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.
This commit is contained in:
Haacked
2013-10-17 09:49:48 -07:00
parent abde37c576
commit 3f5e561111
3 changed files with 67 additions and 0 deletions
@@ -57,6 +57,7 @@
<ItemGroup>
<Compile Include="IntegrationTestAttribute.cs" />
<Compile Include="MiscellaneousClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
<Compile Include="ReleasesClientTests.cs" />
<Compile Include="RepositoriesClientTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -64,6 +65,10 @@
<Compile Include="UsersClientTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Octokit.Reactive\Octokit.Reactive.csproj">
<Project>{674b69b8-0780-4d54-ae2b-c15821fa51cb}</Project>
<Name>Octokit.Reactive</Name>
</ProjectReference>
<ProjectReference Include="..\Octokit.Tests\Octokit.Tests.csproj">
<Project>{149448d4-c2f2-4df9-86bd-03e3272f093b}</Project>
<Name>Octokit.Tests</Name>
@@ -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);
}
}
}
}
@@ -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<IResponse<Repository>>(() =>
new ApiResponse<Repository> { BodyAsObject = repository });
var connection = Substitute.For<IConnection>();
connection.GetAsync<Repository>(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<Repository>(Args.Uri);
var result = await observable;
connection.Received(1).GetAsync<Repository>(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<Repository>(Args.Uri, null, null);
Assert.Same(repository, result);
Assert.Same(repository, result2);
}
}
public class TheGetAllForCurrentMethod
{
[Fact]