mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-03 19:11:30 +00:00
Add AutoCompleteEndpoint for emojis
This commit is contained in:
@@ -11,6 +11,8 @@
|
||||
<Word>Poco</Word>
|
||||
<Word>Ssh</Word>
|
||||
<Word>Svn</Word>
|
||||
<Word>Emoji</Word>
|
||||
<Word>Emojis</Word>
|
||||
</Recognized>
|
||||
</Words>
|
||||
<Acronyms>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Octopi.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace Octopi.Tests.Integration
|
||||
{
|
||||
public class AutoCompleteEndpointTests
|
||||
{
|
||||
public class TheGetEmojisMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task GetsAllTheEmojis()
|
||||
{
|
||||
var github = new GitHubClient
|
||||
{
|
||||
Credentials = new Credentials("xapitestaccountx", "octocat11")
|
||||
};
|
||||
|
||||
var emojis = await github.AutoComplete.GetEmojis();
|
||||
|
||||
emojis.Count.Should().BeGreaterThan(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,7 @@
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="AutoCompleteEndpointTests.cs" />
|
||||
<Compile Include="RepositoriesEndpointTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="UsersEndpointTests.cs" />
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using NSubstitute;
|
||||
using Octopi.Endpoints;
|
||||
using Octopi.Http;
|
||||
using Xunit;
|
||||
|
||||
namespace Octopi.Tests.Integration
|
||||
{
|
||||
public class AutoCompleteEndpointTests
|
||||
{
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
public void EnsuresArgumentsNotNull()
|
||||
{
|
||||
Assert.Throws<ArgumentNullException>(() => new AutoCompleteEndpoint(null));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheGetEmojisMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsTheEmojiEndpoint()
|
||||
{
|
||||
var links = new Dictionary<string, Uri>();
|
||||
var scopes = new List<string>();
|
||||
IResponse<Dictionary<string, string>> response = new ApiResponse<Dictionary<string, string>>
|
||||
{
|
||||
ApiInfo = new ApiInfo(links, scopes, scopes, "", 1, 1),
|
||||
BodyAsObject = new Dictionary<string, string>
|
||||
{
|
||||
{ "foo", "http://example.com/foo.gif" },
|
||||
{ "bar", "http://example.com/bar.gif" }
|
||||
}
|
||||
};
|
||||
var connection = Substitute.For<IConnection>();
|
||||
connection.GetAsync<Dictionary<string, string>>(Args.Uri).Returns(Task.FromResult(response));
|
||||
var autoComplete = new AutoCompleteEndpoint(connection);
|
||||
|
||||
var emojis = await autoComplete.GetEmojis();
|
||||
|
||||
emojis.Count.Should().Be(2);
|
||||
connection.Received()
|
||||
.GetAsync<Dictionary<string, string>>(Arg.Is<Uri>(u => u.ToString() == "/emojis"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,6 +55,7 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="Authentication\CredentialsTests.cs" />
|
||||
<Compile Include="Endpoints\AuthorizationsEndpointTests.cs" />
|
||||
<Compile Include="Endpoints\AutoCompleteEndpointTests.cs" />
|
||||
<Compile Include="Endpoints\OrganizationsEndpointTests.cs" />
|
||||
<Compile Include="Helpers\Arg.cs" />
|
||||
<Compile Include="Helpers\AssertEx.cs" />
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Octopi.Http;
|
||||
|
||||
namespace Octopi.Endpoints
|
||||
{
|
||||
/// <summary>
|
||||
/// Calls API methods meant to support auto complete.
|
||||
/// </summary>
|
||||
public class AutoCompleteEndpoint : IAutoCompleteEndpoint
|
||||
{
|
||||
readonly IConnection connection;
|
||||
|
||||
public AutoCompleteEndpoint(IConnection connection)
|
||||
{
|
||||
Ensure.ArgumentNotNull(connection, "connection");
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public async Task<IReadOnlyDictionary<string, Uri>> GetEmojis()
|
||||
{
|
||||
var endpoint = new Uri("/emojis", UriKind.Relative);
|
||||
var response = await connection.GetAsync<Dictionary<string, string>>(endpoint);
|
||||
return new ReadOnlyDictionary<string, Uri>(
|
||||
response.BodyAsObject.ToDictionary(kvp => kvp.Key, kvp => new Uri(kvp.Value)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -111,5 +111,14 @@ namespace Octopi
|
||||
}
|
||||
}
|
||||
|
||||
IAutoCompleteEndpoint autoComplete;
|
||||
|
||||
public IAutoCompleteEndpoint AutoComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return autoComplete ?? (autoComplete = new AutoCompleteEndpoint(Connection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Octopi
|
||||
{
|
||||
public interface IAutoCompleteEndpoint
|
||||
{
|
||||
[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate",
|
||||
Justification = "Makes a network request")]
|
||||
Task<IReadOnlyDictionary<string, Uri>> GetEmojis();
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,7 @@
|
||||
<Compile Include="Endpoints\ApiEndpoint.cs" />
|
||||
<Compile Include="Endpoints\AuthorizationsEndpoint.cs" />
|
||||
<Compile Include="Endpoints\ApiPagination.cs" />
|
||||
<Compile Include="Endpoints\AutoCompleteEndpoint.cs" />
|
||||
<Compile Include="Endpoints\GistsEndpoint.cs" />
|
||||
<Compile Include="Endpoints\IssuesEndpoint.cs" />
|
||||
<Compile Include="Endpoints\OrganizationsEndpoint.cs" />
|
||||
@@ -61,6 +62,7 @@
|
||||
<Compile Include="Http\InMemoryCredentialStore.cs" />
|
||||
<Compile Include="IApiPagination.cs" />
|
||||
<Compile Include="IAuthorizationsEndpoint.cs" />
|
||||
<Compile Include="IAutoCompleteEndpoint.cs" />
|
||||
<Compile Include="IGitHubClient.cs" />
|
||||
<Compile Include="ISshKeysEndpoint.cs" />
|
||||
<Compile Include="IOrganizationsEndpoint.cs" />
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
<Compile Include="Endpoints\ApiEndpoint.cs" />
|
||||
<Compile Include="Endpoints\ApiPagination.cs" />
|
||||
<Compile Include="Endpoints\AuthorizationsEndpoint.cs" />
|
||||
<Compile Include="Endpoints\AutoCompleteEndpoint.cs" />
|
||||
<Compile Include="Endpoints\GistsEndpoint.cs" />
|
||||
<Compile Include="Endpoints\IssuesEndpoint.cs" />
|
||||
<Compile Include="Endpoints\OrganizationsEndpoint.cs" />
|
||||
@@ -127,6 +128,7 @@
|
||||
<Compile Include="Http\ReadOnlyPagedCollection.cs" />
|
||||
<Compile Include="IApiPagination.cs" />
|
||||
<Compile Include="IAuthorizationsEndpoint.cs" />
|
||||
<Compile Include="IAutoCompleteEndpoint.cs" />
|
||||
<Compile Include="IGitHubClient.cs" />
|
||||
<Compile Include="IOrganizationsEndpoint.cs" />
|
||||
<Compile Include="IReadOnlyPagedCollection.cs" />
|
||||
|
||||
Reference in New Issue
Block a user