added unit tests

This commit is contained in:
aedampir@gmail.com
2016-05-25 22:31:58 +07:00
parent 41ffb53809
commit f3b3a96dfd
2 changed files with 229 additions and 70 deletions
+100 -5
View File
@@ -23,15 +23,42 @@ namespace Octokit.Tests.Clients
public class TheGetAllForCurrentMethod
{
[Fact]
public void RequestsCorrectUrl()
public async Task RequestsCorrectUrl()
{
var endpoint = new Uri("user/subscriptions", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new WatchedClient(connection);
client.GetAllForCurrent();
await client.GetAllForCurrent();
connection.Received().GetAll<Repository>(endpoint, Arg.Any<ApiOptions>());
connection.Received().GetAll<Repository>(endpoint, Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptions()
{
var endpoint = new Uri("user/subscriptions", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new WatchedClient(connection);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
await client.GetAllForCurrent(options);
connection.Received().GetAll<Repository>(endpoint, options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new WatchedClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null));
}
}
@@ -46,7 +73,39 @@ namespace Octokit.Tests.Clients
client.GetAllForUser("banana");
connection.Received().GetAll<Repository>(endpoint, Arg.Any<ApiOptions>());
connection.Received().GetAll<Repository>(endpoint, Args.ApiOptions);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var endpoint = new Uri("users/banana/subscriptions", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new WatchedClient(connection);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
client.GetAllForUser("banana", options);
connection.Received().GetAll<Repository>(endpoint, options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new WatchedClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("user", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser(""));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("", ApiOptions.None));
}
}
@@ -61,7 +120,43 @@ namespace Octokit.Tests.Clients
client.GetAllWatchers("fight", "club");
connection.Received().GetAll<User>(endpoint, Arg.Any<ApiOptions>());
connection.Received().GetAll<User>(endpoint, Args.ApiOptions);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var endpoint = new Uri("repos/fight/club/subscribers", UriKind.Relative);
var connection = Substitute.For<IApiConnection>();
var client = new WatchedClient(connection);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
client.GetAllWatchers("fight", "club", options);
connection.Received().GetAll<User>(endpoint, options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new WatchedClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers(null, "name", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", null, ApiOptions.None));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", "name", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllWatchers("", "name"));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllWatchers("owner", ""));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllWatchers("", "name", ApiOptions.None));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllWatchers("owner", "", ApiOptions.None));
}
}
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Octokit.Reactive.Internal;
using Xunit;
namespace Octokit.Tests.Reactive
@@ -20,43 +17,10 @@ namespace Octokit.Tests.Reactive
}
}
public class TheGetAllWatchersMethod
{
[Fact]
public async Task EnsuresArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers(null, "name").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllWatchers("owner", "name", null).ToTask());
}
[Fact]
public void GetsWatchersFromClient()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Returns(connection);
var client = new ObservableWatchedClient(gitHubClient);
client.GetAllWatchers("jugglingnutcase", "katiejamie");
connection.Received().Get<List<User>>(ApiUrls.Watchers("jugglingnutcase", "katiejamie"), Arg.Any<IDictionary<string, string>>(), null);
}
}
public class TheGetAllForCurrentMethod
{
[Fact]
public async Task EnsuresArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForCurrent(null).ToTask());
}
[Fact]
public void GetsStarsForCurrent()
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
@@ -64,24 +28,41 @@ namespace Octokit.Tests.Reactive
var client = new ObservableWatchedClient(gitHubClient);
client.GetAllForCurrent();
connection.Received().Get<List<Repository>>(ApiUrls.Watched(), Arg.Any<IDictionary<string, string>>(), null);
connection.Received().Get<List<Repository>>(ApiUrls.Watched(), Args.EmptyDictionary, null);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Returns(connection);
var client = new ObservableWatchedClient(gitHubClient);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
client.GetAllForCurrent(options);
connection.Received().Get<List<Repository>>(ApiUrls.Watched(), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllForCurrent(null));
}
}
public class TheGetAllForUserMethod
{
[Fact]
public async Task EnsuresArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser(null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForUser("").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForUser("user", null).ToTask());
}
[Fact]
public void GetsStarsForUser()
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
@@ -89,21 +70,104 @@ namespace Octokit.Tests.Reactive
var client = new ObservableWatchedClient(gitHubClient);
client.GetAllForUser("jugglingnutcase");
connection.Received().Get<List<Repository>>(ApiUrls.WatchedByUser("jugglingnutcase"), Arg.Any<IDictionary<string, string>>(), null);
connection.Received().Get<List<Repository>>(ApiUrls.WatchedByUser("jugglingnutcase"), Args.EmptyDictionary, null);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Returns(connection);
var client = new ObservableWatchedClient(gitHubClient);
var options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
client.GetAllForUser("jugglingnutcase", options);
connection.Received().Get<List<Repository>>(ApiUrls.WatchedByUser("jugglingnutcase"), Arg.Is<IDictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null));
Assert.Throws<ArgumentNullException>(() => client.GetAllForUser(null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllForUser("user", null));
Assert.Throws<ArgumentException>(() => client.GetAllForUser(""));
Assert.Throws<ArgumentException>(() => client.GetAllForUser("", ApiOptions.None));
}
}
public class TheGetAllWatchersMethod
{
[Fact]
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Returns(connection);
var client = new ObservableWatchedClient(gitHubClient);
client.GetAllWatchers("jugglingnutcase", "katiejamie");
connection.Received().Get<List<User>>(ApiUrls.Watchers("jugglingnutcase", "katiejamie"), Args.EmptyDictionary, null);
}
[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IConnection>();
var gitHubClient = Substitute.For<IGitHubClient>();
gitHubClient.Connection.Returns(connection);
var client = new ObservableWatchedClient(gitHubClient);
ApiOptions options = new ApiOptions
{
StartPage = 1,
PageCount = 1,
PageSize = 1
};
client.GetAllWatchers("jugglingnutcase", "katiejamie", options);
connection.Received().Get<List<User>>(ApiUrls.Watchers("jugglingnutcase", "katiejamie"), Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null);
}
[Fact]
public void EnsuresNonNullArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
Assert.Throws<ArgumentNullException>(() => client.GetAllWatchers(null, "name"));
Assert.Throws<ArgumentNullException>(() => client.GetAllWatchers("owner", null));
Assert.Throws<ArgumentNullException>(() => client.GetAllWatchers(null, "name", ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllWatchers("owner", null, ApiOptions.None));
Assert.Throws<ArgumentNullException>(() => client.GetAllWatchers("owner", "name", null));
Assert.Throws<ArgumentException>(() => client.GetAllWatchers("", "name"));
Assert.Throws<ArgumentException>(() => client.GetAllWatchers("owner", ""));
Assert.Throws<ArgumentException>(() => client.GetAllWatchers("", "name", ApiOptions.None));
Assert.Throws<ArgumentException>(() => client.GetAllWatchers("owner", "", ApiOptions.None));
}
}
public class TheCheckWatchedMethod
{
[Fact]
public async Task EnsureArguments()
public void EnsuresNonNullArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckWatched(null, "name").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CheckWatched("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CheckWatched("", "name").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.CheckWatched("owner", "").ToTask());
Assert.Throws<ArgumentNullException>(() => client.CheckWatched(null, "name"));
Assert.Throws<ArgumentNullException>(() => client.CheckWatched("owner", null));
Assert.Throws<ArgumentException>(() => client.CheckWatched("", "name"));
Assert.Throws<ArgumentException>(() => client.CheckWatched("owner", ""));
}
[Fact]
@@ -121,15 +185,15 @@ namespace Octokit.Tests.Reactive
public class TheWatchRepoMethod
{
[Fact]
public async Task EnsureArguments()
public void EnsuresNonNullArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
var subscription = new NewSubscription();
await Assert.ThrowsAsync<ArgumentNullException>(() => client.WatchRepo(null, "name", subscription).ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.WatchRepo("owner", null, subscription).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.WatchRepo("", "name", subscription).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.WatchRepo("owner", "", subscription).ToTask());
Assert.Throws<ArgumentNullException>(() => client.WatchRepo(null, "name", subscription));
Assert.Throws<ArgumentNullException>(() => client.WatchRepo("owner", null, subscription));
Assert.Throws<ArgumentException>(() => client.WatchRepo("", "name", subscription));
Assert.Throws<ArgumentException>(() => client.WatchRepo("owner", "", subscription));
}
[Fact]
@@ -147,14 +211,14 @@ namespace Octokit.Tests.Reactive
public class TheUnWatchRepoMethod
{
[Fact]
public async Task EnsureArguments()
public void EnsuresNonNullArguments()
{
var client = new ObservableWatchedClient(Substitute.For<IGitHubClient>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.UnwatchRepo(null, "name").ToTask());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.UnwatchRepo("owner", null).ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.UnwatchRepo("", "name").ToTask());
await Assert.ThrowsAsync<ArgumentException>(() => client.UnwatchRepo("owner", "").ToTask());
Assert.Throws<ArgumentNullException>(() => client.UnwatchRepo(null, "name"));
Assert.Throws<ArgumentNullException>(() => client.UnwatchRepo("owner", null));
Assert.Throws<ArgumentException>(() => client.UnwatchRepo("", "name"));
Assert.Throws<ArgumentException>(() => client.UnwatchRepo("owner", ""));
}
[Fact]