From bcbcfac301d329e527014aae6f62675f612ba1e2 Mon Sep 17 00:00:00 2001 From: Haacked Date: Mon, 28 Jan 2013 13:09:41 -0800 Subject: [PATCH] Add AutoCompleteEndpoint for emojis --- CustomDictionary.xml | 2 + .../AutoCompleteEndpointTests.cs | 26 ++++++++++ .../Octopi.Tests.Integration.csproj | 1 + .../Endpoints/AutoCompleteEndpointTests.cs | 51 +++++++++++++++++++ Octopi.Tests/Octopi.Tests.csproj | 1 + Octopi/Endpoints/AutoCompleteEndpoint.cs | 31 +++++++++++ Octopi/GitHubClient.cs | 9 ++++ Octopi/IAutoCompleteEndpoint.cs | 14 +++++ Octopi/Octopi.csproj | 2 + Octopi/OctopiRT.csproj | 2 + 10 files changed, 139 insertions(+) create mode 100644 Octopi.Tests.Integration/AutoCompleteEndpointTests.cs create mode 100644 Octopi.Tests/Endpoints/AutoCompleteEndpointTests.cs create mode 100644 Octopi/Endpoints/AutoCompleteEndpoint.cs create mode 100644 Octopi/IAutoCompleteEndpoint.cs diff --git a/CustomDictionary.xml b/CustomDictionary.xml index ea8a0aac..4e9b0fbf 100644 --- a/CustomDictionary.xml +++ b/CustomDictionary.xml @@ -11,6 +11,8 @@ Poco Ssh Svn + Emoji + Emojis diff --git a/Octopi.Tests.Integration/AutoCompleteEndpointTests.cs b/Octopi.Tests.Integration/AutoCompleteEndpointTests.cs new file mode 100644 index 00000000..99669f65 --- /dev/null +++ b/Octopi.Tests.Integration/AutoCompleteEndpointTests.cs @@ -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); + } + } + } +} diff --git a/Octopi.Tests.Integration/Octopi.Tests.Integration.csproj b/Octopi.Tests.Integration/Octopi.Tests.Integration.csproj index b3fdedd6..824abe3d 100644 --- a/Octopi.Tests.Integration/Octopi.Tests.Integration.csproj +++ b/Octopi.Tests.Integration/Octopi.Tests.Integration.csproj @@ -49,6 +49,7 @@ + diff --git a/Octopi.Tests/Endpoints/AutoCompleteEndpointTests.cs b/Octopi.Tests/Endpoints/AutoCompleteEndpointTests.cs new file mode 100644 index 00000000..64a84c1f --- /dev/null +++ b/Octopi.Tests/Endpoints/AutoCompleteEndpointTests.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(() => new AutoCompleteEndpoint(null)); + } + } + + public class TheGetEmojisMethod + { + [Fact] + public async Task RequestsTheEmojiEndpoint() + { + var links = new Dictionary(); + var scopes = new List(); + IResponse> response = new ApiResponse> + { + ApiInfo = new ApiInfo(links, scopes, scopes, "", 1, 1), + BodyAsObject = new Dictionary + { + { "foo", "http://example.com/foo.gif" }, + { "bar", "http://example.com/bar.gif" } + } + }; + var connection = Substitute.For(); + connection.GetAsync>(Args.Uri).Returns(Task.FromResult(response)); + var autoComplete = new AutoCompleteEndpoint(connection); + + var emojis = await autoComplete.GetEmojis(); + + emojis.Count.Should().Be(2); + connection.Received() + .GetAsync>(Arg.Is(u => u.ToString() == "/emojis")); + } + } + } +} diff --git a/Octopi.Tests/Octopi.Tests.csproj b/Octopi.Tests/Octopi.Tests.csproj index e96e03f8..283959a9 100644 --- a/Octopi.Tests/Octopi.Tests.csproj +++ b/Octopi.Tests/Octopi.Tests.csproj @@ -55,6 +55,7 @@ + diff --git a/Octopi/Endpoints/AutoCompleteEndpoint.cs b/Octopi/Endpoints/AutoCompleteEndpoint.cs new file mode 100644 index 00000000..406451ae --- /dev/null +++ b/Octopi/Endpoints/AutoCompleteEndpoint.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 +{ + /// + /// Calls API methods meant to support auto complete. + /// + public class AutoCompleteEndpoint : IAutoCompleteEndpoint + { + readonly IConnection connection; + + public AutoCompleteEndpoint(IConnection connection) + { + Ensure.ArgumentNotNull(connection, "connection"); + this.connection = connection; + } + + public async Task> GetEmojis() + { + var endpoint = new Uri("/emojis", UriKind.Relative); + var response = await connection.GetAsync>(endpoint); + return new ReadOnlyDictionary( + response.BodyAsObject.ToDictionary(kvp => kvp.Key, kvp => new Uri(kvp.Value))); + } + } +} diff --git a/Octopi/GitHubClient.cs b/Octopi/GitHubClient.cs index 5ed5ab82..6f2908b5 100644 --- a/Octopi/GitHubClient.cs +++ b/Octopi/GitHubClient.cs @@ -111,5 +111,14 @@ namespace Octopi } } + IAutoCompleteEndpoint autoComplete; + + public IAutoCompleteEndpoint AutoComplete + { + get + { + return autoComplete ?? (autoComplete = new AutoCompleteEndpoint(Connection)); + } + } } } diff --git a/Octopi/IAutoCompleteEndpoint.cs b/Octopi/IAutoCompleteEndpoint.cs new file mode 100644 index 00000000..6af40982 --- /dev/null +++ b/Octopi/IAutoCompleteEndpoint.cs @@ -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> GetEmojis(); + } +} diff --git a/Octopi/Octopi.csproj b/Octopi/Octopi.csproj index 4ba9ed1e..f57f34cc 100644 --- a/Octopi/Octopi.csproj +++ b/Octopi/Octopi.csproj @@ -41,6 +41,7 @@ + @@ -61,6 +62,7 @@ + diff --git a/Octopi/OctopiRT.csproj b/Octopi/OctopiRT.csproj index a2da9ffb..4e30e837 100644 --- a/Octopi/OctopiRT.csproj +++ b/Octopi/OctopiRT.csproj @@ -109,6 +109,7 @@ + @@ -127,6 +128,7 @@ +