Create Observable Tests

This commit is contained in:
pltaylor
2013-11-11 09:03:30 -05:00
parent 59441ed030
commit b2a2897bc8
5 changed files with 102 additions and 3 deletions
@@ -0,0 +1,32 @@
using System;
namespace Octokit.Reactive
{
public interface IObservableTreesClient
{
/// <summary>
/// Gets a Tree Response for a given SHA.
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/trees/#get-a-tree
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="reference">The SHA that references the tree</param>
/// <returns>The <see cref="TreeResponse"/> for the specified Tree.</returns>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Get")]
IObservable<TreeResponse> Get(string owner, string name, string reference);
/// <summary>
/// Creates a new Tree in the specified repo
/// </summary>
/// <remarks>
/// http://developer.github.com/v3/git/trees/#create-a-tree
/// </remarks>
/// <param name="owner">The owner of the repository</param>
/// <param name="name">The name of the repository</param>
/// <param name="newTree">The value of the new tree</param>
/// <returns>The <see cref="TreeResponse"/> that was just created.</returns>
IObservable<TreeResponse> Create(string owner, string name, NewTree newTree);
}
}
@@ -3,9 +3,6 @@ using System.Reactive.Threading.Tasks;
namespace Octokit.Reactive
{
public interface IObservableTreesClient
{
}
public class ObservableTreesClient : IObservableTreesClient
{
+1
View File
@@ -74,6 +74,7 @@
<Link>Properties\SolutionInfo.cs</Link>
</Compile>
<Compile Include="Clients\IObservableEventsClient.cs" />
<Compile Include="Clients\IObservableTreesClient.cs" />
<Compile Include="Clients\ObservableEventsClient.cs" />
<Compile Include="Clients\ObservableGitDatabaseClient.cs" />
<Compile Include="Clients\IObservableGitDatabaseClient.cs" />
+1
View File
@@ -118,6 +118,7 @@
<Compile Include="Reactive\ObservableIssuesClientTests.cs" />
<Compile Include="Reactive\ObservableMilestonesClientTests.cs" />
<Compile Include="Reactive\ObservableRepositoriesClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
<Compile Include="SimpleJsonSerializerTests.cs" />
<Compile Include="Clients\UsersClientTests.cs" />
</ItemGroup>
@@ -0,0 +1,68 @@
using System;
using System.Reactive.Linq;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Octokit.Tests.Helpers;
using Xunit;
namespace Octokit.Tests
{
public class ObservableTreesClientTests
{
public class TheGetMethod
{
[Fact]
public void GetsFromClientIssueIssue()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTreesClient(gitHubClient);
client.Get("fake", "repo", "123456ABCD");
gitHubClient.Tree.Received().Get("fake", "repo", "123456ABCD");
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new ObservableTreesClient(Substitute.For<IGitHubClient>());
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get(null, "name", "123456ABCD"));
await AssertEx.Throws<ArgumentException>(async () => await client.Get("", "name", "123456ABCD"));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", null, "123456ABCD"));
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "", "123456ABCD"));
await AssertEx.Throws<ArgumentNullException>(async () => await client.Get("owner", "name", null));
await AssertEx.Throws<ArgumentException>(async () => await client.Get("owner", "name", ""));
}
}
public class TheCreateMethod
{
[Fact]
public void CreatesFromClientIssueIssue()
{
var newTree = new NewTree();
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTreesClient(gitHubClient);
client.Create("fake", "repo", newTree);
gitHubClient.Tree.Received().Create("fake", "repo", newTree);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTreesClient(gitHubClient);
AssertEx.Throws<ArgumentNullException>(async () => await client.Create(null, "name", new NewTree()));
AssertEx.Throws<ArgumentException>(async () => await client.Create("", "name", new NewTree()));
AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", null, new NewTree()));
AssertEx.Throws<ArgumentException>(async () => await client.Create("owner", "", new NewTree()));
AssertEx.Throws<ArgumentNullException>(async () => await client.Create("owner", "name", null));
}
}
}
}