From 3f5e5611117d7b25df6a7115eb4c706f47afd9d8 Mon Sep 17 00:00:00 2001 From: Haacked Date: Thu, 17 Oct 2013 09:49:48 -0700 Subject: [PATCH] Add tests to verify current observable behavior Right now, our observable methods are semi-cold. They don't make the request until subscribed, but multiple subscriptions get the same result. This is the way that Octokit.cocoa works. --- .../Octokit.Tests.Integration.csproj | 5 +++ .../ObservableRepositoriesClientTests.cs | 33 +++++++++++++++++++ .../ObservableRepositoriesClientTests.cs | 29 ++++++++++++++++ 3 files changed, 67 insertions(+) create mode 100644 Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs diff --git a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj index ca6158b1..8246bd3e 100644 --- a/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj +++ b/Octokit.Tests.Integration/Octokit.Tests.Integration.csproj @@ -57,6 +57,7 @@ + @@ -64,6 +65,10 @@ + + {674b69b8-0780-4d54-ae2b-c15821fa51cb} + Octokit.Reactive + {149448d4-c2f2-4df9-86bd-03e3272f093b} Octokit.Tests diff --git a/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs new file mode 100644 index 00000000..a81e889c --- /dev/null +++ b/Octokit.Tests.Integration/Reactive/ObservableRepositoriesClientTests.cs @@ -0,0 +1,33 @@ +using System.Reactive.Linq; +using System.Threading.Tasks; +using Octokit.Reactive.Clients; +using Xunit; + +namespace Octokit.Tests.Integration +{ + public class ObservableRepositoriesClientTests + { + public class TheGetMethod + { + [IntegrationTest] + public async Task ReturnsSpecifiedRepository() + { + var github = new GitHubClient("Octokit Test Runner") + { + Credentials = Helper.Credentials + }; + var client = new ObservableRepositoriesClient(github); + var observable = client.Get("haacked", "seegit"); + var repository = await observable; + var repository2 = await observable; + + Assert.Equal("https://github.com/Haacked/SeeGit.git", repository.CloneUrl); + Assert.False(repository.Private); + Assert.False(repository.Fork); + Assert.Equal("https://github.com/Haacked/SeeGit.git", repository2.CloneUrl); + Assert.False(repository2.Private); + Assert.False(repository2.Fork); + } + } + } +} diff --git a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs index 1c1ac5ef..e0689d3f 100644 --- a/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableRepositoriesClientTests.cs @@ -5,12 +5,41 @@ using System.Threading.Tasks; using NSubstitute; using Octokit.Internal; using Octokit.Reactive.Clients; + using Xunit; namespace Octokit.Tests.Reactive { public class ObservableRepositoriesClientTests { + public class TheGetMethod + { + // This isn't really a test specific to this method. This is just as good a place as any to test + // that our API methods returns the right kind of observables. + [Fact] + public async Task IsALukeWarmObservable() + { + var repository = new Repository(); + var response = Task.Factory.StartNew>(() => + new ApiResponse { BodyAsObject = repository }); + var connection = Substitute.For(); + connection.GetAsync(Args.Uri, null, null).Returns(response); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableRepositoriesClient(gitHubClient); + var observable = client.Get("stark", "ned"); + connection.Received(0).GetAsync(Args.Uri); + + var result = await observable; + connection.Received(1).GetAsync(Args.Uri, null, null); + var result2 = await observable; + // TODO: If we change this to a warm observable, we'll need to change this to Received(2) + connection.Received(1).GetAsync(Args.Uri, null, null); + + Assert.Same(repository, result); + Assert.Same(repository, result2); + } + } + public class TheGetAllForCurrentMethod { [Fact]