added new unit tests

This commit is contained in:
aedampir@gmail.com
2016-06-10 19:27:44 +07:00
parent c8ff0b6151
commit f3e90ba68f
3 changed files with 140 additions and 2 deletions

View File

@@ -10,16 +10,27 @@ public class TagsClientTests
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new TagsClient(connection);
client.Get("owner", "repo", "reference");
await client.Get("owner", "repo", "reference");
connection.Received().Get<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repos/owner/repo/git/tags/reference"));
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new TagsClient(connection);
await client.Get(1, "reference");
connection.Received().Get<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/tags/reference"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -28,9 +39,14 @@ public class TagsClientTests
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "reference"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "reference"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "reference"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "reference"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", ""));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get(1, ""));
}
}
@@ -48,6 +64,18 @@ public class TagsClientTests
Arg.Is<NewTag>(nt => nt.Type == TaggedType.Tree));
}
[Fact]
public void PostsToTheCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new TagsClient(connection);
client.Create(1, new NewTag { Type = TaggedType.Tree });
connection.Received().Post<GitTag>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/tags"),
Arg.Is<NewTag>(nt => nt.Type == TaggedType.Tree));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
@@ -56,6 +84,9 @@ public class TagsClientTests
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewTag()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewTag()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(1, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewTag()));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewTag()));
}

View File

@@ -236,6 +236,7 @@
<Compile Include="Reactive\ObservableRepositoryHooksClientTests.cs" />
<Compile Include="Reactive\ObservableStarredClientTests.cs" />
<Compile Include="Reactive\ObservableStatisticsClientTests.cs" />
<Compile Include="Reactive\ObservableTagsClientTests.cs" />
<Compile Include="Reactive\ObservableTeamsClientTests.cs" />
<Compile Include="Reactive\ObservableTreesClientTests.cs" />
<Compile Include="Reactive\ObservableFollowersTest.cs" />

View File

@@ -0,0 +1,106 @@
using System;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
namespace Octokit.Tests.Reactive
{
public class TagsClientTests
{
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
client.Get("owner", "repo", "reference");
gitHubClient.Received().Git.Tag.Get("owner", "repo", "reference");
}
[Fact]
public void RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
client.Get(1, "reference");
gitHubClient.Received().Git.Tag.Get(1, "reference");
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableTagsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", "reference"));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, "reference"));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.Get(1, null));
Assert.Throws<ArgumentException>(() => client.Get("", "name", "reference"));
Assert.Throws<ArgumentException>(() => client.Get("owner", "", "reference"));
Assert.Throws<ArgumentException>(() => client.Get("owner", "name", ""));
Assert.Throws<ArgumentException>(() => client.Get(1, ""));
}
}
public class TheCreateMethod
{
[Fact]
public void PostsToTheCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
var newTag = new NewTag { Type = TaggedType.Tree };
client.Create("owner", "repo", newTag);
gitHubClient.Received().Git.Tag.Create("owner", "repo", newTag);
}
[Fact]
public void PostsToTheCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableTagsClient(gitHubClient);
var newTag = new NewTag { Type = TaggedType.Tree };
client.Create(1, newTag);
gitHubClient.Received().Git.Tag.Create(1, newTag);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableTagsClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewTag()));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewTag()));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
Assert.Throws<ArgumentNullException>(() => client.Create(1, null));
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewTag()));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewTag()));
}
}
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new ObservableTagsClient(null));
}
}
}
}