added new unit tests

This commit is contained in:
aedampir@gmail.com
2016-06-10 18:02:00 +07:00
parent 9383756137
commit 7a0fca3fd0
2 changed files with 72 additions and 21 deletions
+34 -7
View File
@@ -22,26 +22,38 @@ namespace Octokit.Tests.Clients
public class TheGetMethod
{
[Fact]
public void RequestsCorrectUrl()
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new BlobsClient(connection);
client.Get("fake", "repo", "123456ABCD");
await client.Get("fake", "repo", "123456ABCD");
connection.Received().Get<Blob>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/blobs/123456ABCD"));
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new BlobsClient(connection);
await client.Get(1, "123456ABCD");
connection.Received().Get<Blob>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/blobs/123456ABCD"));
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new BlobsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "123456ABCD"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "123456ABCD"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "123456ABCD"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "123456ABCD"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "123456ABCD"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "123456ABCD"));
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", ""));
}
}
@@ -51,15 +63,29 @@ namespace Octokit.Tests.Clients
[Fact]
public void PostsToCorrectUrl()
{
var newBlob = new NewBlob();
var connection = Substitute.For<IApiConnection>();
var client = new BlobsClient(connection);
var newBlob = new NewBlob();
client.Create("fake", "repo", newBlob);
connection.Received().Post<BlobReference>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/git/blobs"), newBlob);
}
[Fact]
public void PostsToCorrectUrlWithRepositoryId()
{
var connection = Substitute.For<IApiConnection>();
var client = new BlobsClient(connection);
var newBlob = new NewBlob();
client.Create(1, newBlob);
connection.Received().Post<BlobReference>(Arg.Is<Uri>(u => u.ToString() == "repositories/1/git/blobs"), newBlob);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
@@ -67,10 +93,11 @@ namespace Octokit.Tests.Clients
var client = new BlobsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewBlob()));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewBlob()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewBlob()));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewBlob()));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewBlob()));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewBlob()));
}
}
@@ -1,5 +1,4 @@
using System;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
@@ -12,7 +11,7 @@ namespace Octokit.Tests.Reactive
public class TheGetMethod
{
[Fact]
public void GetsFromClientIssueComment()
public void RequestsCorrectUrl()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableBlobClient(gitHubClient);
@@ -22,17 +21,29 @@ namespace Octokit.Tests.Reactive
gitHubClient.Git.Blob.Received().Get("fake", "repo", "123456ABCD");
}
[Fact]
public async Task RequestsCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableBlobClient(gitHubClient);
client.Get(1, "123456ABCD");
gitHubClient.Git.Blob.Received().Get(1, "123456ABCD");
}
[Fact]
public async Task EnsuresArguments()
{
var client = new ObservableBlobClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get(null, "name", "123456ABCD").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("", "name", "123456ABCD").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", null, "123456ABCD").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "", "123456ABCD").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Get("owner", "name", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Get("owner", "name", "").ToTask());
Assert.Throws<ArgumentNullException>(() => client.Get(null, "name", "123456ABCD"));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", null, "123456ABCD"));
Assert.Throws<ArgumentNullException>(() => client.Get("owner", "name", null));
Assert.Throws<ArgumentException>(() => client.Get("", "name", "123456ABCD"));
Assert.Throws<ArgumentException>(() => client.Get("owner", "", "123456ABCD"));
Assert.Throws<ArgumentException>(() => client.Get("owner", "name", ""));
}
}
@@ -41,26 +52,39 @@ namespace Octokit.Tests.Reactive
[Fact]
public void PostsToCorrectUrl()
{
var newBlob = new NewBlob();
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableBlobClient(gitHubClient);
var newBlob = new NewBlob();
client.Create("fake", "repo", newBlob);
gitHubClient.Git.Blob.Received().Create("fake", "repo", newBlob);
}
[Fact]
public void PostsToCorrectUrlWithRepositoryId()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableBlobClient(gitHubClient);
var newBlob = new NewBlob();
client.Create(1, newBlob);
gitHubClient.Git.Blob.Received().Create(1, newBlob);
}
[Fact]
public async Task EnsuresArgumentsNotNull()
{
var gitHubClient = Substitute.For<IGitHubClient>();
var client = new ObservableBlobClient(gitHubClient);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create(null, "name", new NewBlob()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("", "name", new NewBlob()).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", null, new NewBlob()).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("owner", "", new NewBlob()).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("owner", "name", null).ToTask());
Assert.Throws<ArgumentNullException>(() => client.Create(null, "name", new NewBlob()));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", null, new NewBlob()));
Assert.Throws<ArgumentNullException>(() => client.Create("owner", "name", null));
Assert.Throws<ArgumentException>(() => client.Create("", "name", new NewBlob()));
Assert.Throws<ArgumentException>(() => client.Create("owner", "", new NewBlob()));
}
}