Skip to content

Commit

Permalink
Add some new tests for overloaded methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-efremov committed Mar 21, 2016
1 parent 63b5852 commit 1a5658d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 14 deletions.
5 changes: 1 addition & 4 deletions Octokit.Reactive/Clients/ObservableAssigneesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ public ObservableAssigneesClient(IGitHubClient client)
/// <returns></returns>
public IObservable<User> GetAllForRepository(string owner, string name)
{
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
Ensure.ArgumentNotNullOrEmptyString(name, "name");

return _connection.GetAndFlattenAllPages<User>(ApiUrls.Assignees(owner, name));
return GetAllForRepository(owner, name, ApiOptions.None);
}

/// <summary>
Expand Down
26 changes: 24 additions & 2 deletions Octokit.Tests/Clients/AssigneesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Internal;
using Octokit.Tests.Helpers;
using Xunit;

namespace Octokit.Tests.Clients
{
public class AssigneesClientTests
{
public class TheGetForRepositoryMethod
public class TheGetAllMethod
{
[Fact]
public void RequestsCorrectUrl()
Expand All @@ -28,6 +27,28 @@ public void RequestsCorrectUrl()
Args.ApiOptions);
}

[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new AssigneesClient(connection);

var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

client.GetAllForRepository("fake", "repo", options);

connection.Received().GetAll<User>(
Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/assignees"),
null,
AcceptHeaders.StableVersion,
options);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
Expand All @@ -37,6 +58,7 @@ public async Task EnsuresNonNullArguments()
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository(null, ""));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForRepository("", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForRepository("owner", "name", null));
}
}

Expand Down
22 changes: 19 additions & 3 deletions Octokit.Tests/Clients/AuthorizationsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,28 @@ public void RequestsCorrectUrlWithApiOptions()
{
var client = Substitute.For<IApiConnection>();
var authEndpoint = new AuthorizationsClient(client);

authEndpoint.GetAll(ApiOptions.None);

var options = new ApiOptions
{
StartPage = 1,
PageSize = 1,
PageCount = 1
};

authEndpoint.GetAll(options);

client.Received().GetAll<Authorization>(
Arg.Is<Uri>(u => u.ToString() == "authorizations"),
Args.ApiOptions);
options);
}

[Fact]
public async Task EnsuresArgumentsNotNull()
{
var client = Substitute.For<IApiConnection>();
var authEndpoint = new AuthorizationsClient(client);

await Assert.ThrowsAsync<ArgumentNullException>(() => authEndpoint.GetAll(null));
}
}

Expand Down
22 changes: 22 additions & 0 deletions Octokit.Tests/Clients/ReleasesClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,35 @@ public void RequestsCorrectUrl()
Args.ApiOptions);
}

[Fact]
public void RequestsCorrectUrlWithApiOptions()
{
var client = Substitute.For<IApiConnection>();
var releasesClient = new ReleasesClient(client);

var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};

releasesClient.GetAll("fake", "repo", options);

client.Received().GetAll<Release>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/releases"),
null,
"application/vnd.github.v3",
options);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var releasesClient = new ReleasesClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.GetAll(null, "name"));
await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.GetAll("owner", null));
await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.GetAll("owner", "name", null));
}
}

Expand Down
24 changes: 20 additions & 4 deletions Octokit.Tests/Clients/UserEmailsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class UserEmailsClientTests
public class TheGetAllMethod
{
[Fact]
public void GetsCorrectUrl()
public void RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new UserEmailsClient(connection);
Expand All @@ -24,15 +24,31 @@ public void GetsCorrectUrl()
}

[Fact]
public void GetsCorrectUrlWithApiOptions()
public void RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new UserEmailsClient(connection);

client.GetAll(ApiOptions.None);
var options = new ApiOptions
{
PageCount = 1,
PageSize = 1,
StartPage = 1
};

client.GetAll(options);

connection.Received(1)
.GetAll<EmailAddress>(Arg.Is<Uri>(u => u.ToString() == "user/emails"), Args.ApiOptions);
.GetAll<EmailAddress>(Arg.Is<Uri>(u => u.ToString() == "user/emails"),
options);
}

[Fact]
public async Task EnsuresNonNullArguments()
{
var releasesClient = new UserEmailsClient(Substitute.For<IApiConnection>());

await Assert.ThrowsAsync<ArgumentNullException>(() => releasesClient.GetAll(null));
}
}

Expand Down
13 changes: 12 additions & 1 deletion Octokit.Tests/Reactive/ObservableAuthorizationsClientTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using NSubstitute;
using Octokit.Reactive;
using Xunit;
Expand Down Expand Up @@ -27,12 +29,21 @@ public void RequestsCorrectUrlWithApiOption()
{
var client = Substitute.For<IGitHubClient>();
var authEndpoint = new ObservableAuthorizationsClient(client);

authEndpoint.GetAll(ApiOptions.None);

client.Connection.Received(1).Get<List<Authorization>>(Arg.Is<Uri>(u => u.ToString() == "authorizations"),
Arg.Is<Dictionary<string, string>>(dictionary => dictionary.Count == 0), null);
}

[Fact]
public async Task EnsuresArgumentsNotNull()
{
var client = Substitute.For<IGitHubClient>();
var authEndpoint = new ObservableAuthorizationsClient(client);

await Assert.ThrowsAsync<ArgumentNullException>(() => authEndpoint.GetAll(null).ToTask());
}
}

public class TheCtor
Expand Down

0 comments on commit 1a5658d

Please sign in to comment.