From bc6a0ce88da4a635174da4dd4d6fcd6c2e551910 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Tue, 14 Jun 2016 18:51:19 +0700 Subject: [PATCH] added new unit tests --- Octokit.Tests/Clients/IssuesClientTests.cs | 286 +++++++++++--- .../Reactive/ObservableIssuesClientTests.cs | 369 +++++++++++++++--- 2 files changed, 545 insertions(+), 110 deletions(-) diff --git a/Octokit.Tests/Clients/IssuesClientTests.cs b/Octokit.Tests/Clients/IssuesClientTests.cs index 131f6ac5..b3b5f539 100644 --- a/Octokit.Tests/Clients/IssuesClientTests.cs +++ b/Octokit.Tests/Clients/IssuesClientTests.cs @@ -13,16 +13,27 @@ namespace Octokit.Tests.Clients public class TheGetMethod { [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.Get("fake", "repo", 42); + await client.Get("fake", "repo", 42); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42")); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + await client.Get(1, 42); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/issues/42")); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -30,6 +41,9 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.Get("", "name", 1)); + await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); } } @@ -47,24 +61,24 @@ namespace Octokit.Tests.Clients } [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.GetAllForCurrent(); + await client.GetAllForCurrent(); connection.Received().GetAll(Arg.Is(u => u.ToString() == "issues"), Arg.Any>(), Args.ApiOptions); } [Fact] - public void SendsAppropriateParameters() + public async Task SendsAppropriateParameters() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.GetAllForCurrent(new IssueRequest { SortDirection = SortDirection.Ascending }); + await client.GetAllForCurrent(new IssueRequest { SortDirection = SortDirection.Ascending }); connection.Received().GetAll(Arg.Is(u => u.ToString() == "issues"), Arg.Is>(d => d.Count == 4 @@ -90,12 +104,12 @@ namespace Octokit.Tests.Clients } [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.GetAllForOwnedAndMemberRepositories(); + await client.GetAllForOwnedAndMemberRepositories(); connection.Received().GetAll(Arg.Is(u => u.ToString() == "user/issues"), Arg.Any>(), @@ -106,7 +120,7 @@ namespace Octokit.Tests.Clients public class TheGetAllForOrganizationMethod { [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task EnsuresNonNullArguments() { var client = new IssuesClient(Substitute.For()); @@ -131,12 +145,12 @@ namespace Octokit.Tests.Clients } [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.GetAllForOrganization("fake"); + await client.GetAllForOrganization("fake"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "orgs/fake/issues"), Arg.Any>(), @@ -167,7 +181,7 @@ namespace Octokit.Tests.Clients public class TheGetAllForRepositoryMethod { [Fact] - public async Task EnsuresArgumentsNotNull() + public async Task EnsuresNonNullArguments() { var client = new IssuesClient(Substitute.For()); @@ -175,39 +189,40 @@ namespace Octokit.Tests.Clients var request = new RepositoryIssueRequest(); await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", options)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request, options)); - - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", options)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request, options)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", options)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, options)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request, options)); - - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", options)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request, options)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null)); - + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request, options)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request, options)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null, options)); await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (RepositoryIssueRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null, options)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, request, null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", options)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", options)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request, options)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request, options)); } [Fact] - public void RequestsCorrectUrl() + public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.GetAllForRepository("fake", "repo"); + await client.GetAllForRepository("fake", "repo"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), Arg.Any>(), @@ -215,12 +230,63 @@ namespace Octokit.Tests.Clients } [Fact] - public void SendsAppropriateParameters() + public async Task RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For(); var client = new IssuesClient(connection); - client.GetAllForRepository("fake", "repo", new RepositoryIssueRequest + await client.GetAllForRepository(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Any>(), + Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), Arg.Any>(), options); + } + + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository(1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Any>(), + options); + } + + [Fact] + public async Task SendsAppropriateParameters() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + await client.GetAllForRepository("fake", "repo", new RepositoryIssueRequest { SortDirection = SortDirection.Ascending }); @@ -233,6 +299,80 @@ namespace Octokit.Tests.Clients && d["filter"] == "assigned"), Args.ApiOptions); } + + [Fact] + public async Task SendsAppropriateParametersWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + await client.GetAllForRepository(1, new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Is>(d => d.Count == 4 + && d["state"] == "open" + && d["direction"] == "asc" + && d["sort"] == "created" + && d["filter"] == "assigned"), + Args.ApiOptions); + } + + [Fact] + public async Task SendsAppropriateParametersWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository("fake", "repo", new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), + Arg.Is>(d => d.Count == 4 + && d["state"] == "open" + && d["direction"] == "asc" + && d["sort"] == "created" + && d["filter"] == "assigned"), + options); + } + + [Fact] + public async Task SendsAppropriateParametersWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + await client.GetAllForRepository(1, new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Is>(d => d.Count == 4 + && d["state"] == "open" + && d["direction"] == "asc" + && d["sort"] == "created" + && d["filter"] == "assigned"), + options); + } } public class TheCreateMethod @@ -251,16 +391,32 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithRepositoryId() + { + var newIssue = new NewIssue("some title"); + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + client.Create(1, newIssue); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/issues"), + newIssue); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new IssuesClient(connection); - await Assert.ThrowsAsync(() => client.Create(null, "name", new NewIssue("title"))); - await Assert.ThrowsAsync(() => client.Create("", "name", new NewIssue("x"))); + await Assert.ThrowsAsync(() => client.Create(null, "name", new NewIssue("x"))); await Assert.ThrowsAsync(() => client.Create("owner", null, new NewIssue("x"))); - await Assert.ThrowsAsync(() => client.Create("owner", "", new NewIssue("x"))); await Assert.ThrowsAsync(() => client.Create("owner", "name", null)); + + await Assert.ThrowsAsync(() => client.Create(1, null)); + + await Assert.ThrowsAsync(() => client.Create("", "name", new NewIssue("x"))); + await Assert.ThrowsAsync(() => client.Create("owner", "", new NewIssue("x"))); } } @@ -280,16 +436,32 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithRepositoryId() + { + var issueUpdate = new IssueUpdate(); + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + client.Update(1, 42, issueUpdate); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/issues/42"), + issueUpdate); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new IssuesClient(connection); await Assert.ThrowsAsync(() => client.Update(null, "name", 1, new IssueUpdate())); - await Assert.ThrowsAsync(() => client.Update("", "name", 1, new IssueUpdate())); await Assert.ThrowsAsync(() => client.Update("owner", null, 1, new IssueUpdate())); - await Assert.ThrowsAsync(() => client.Update("owner", "", 1, new IssueUpdate())); await Assert.ThrowsAsync(() => client.Update("owner", "name", 1, null)); + + await Assert.ThrowsAsync(() => client.Update(1, 1, null)); + + await Assert.ThrowsAsync(() => client.Update("", "name", 1, new IssueUpdate())); + await Assert.ThrowsAsync(() => client.Update("owner", "", 1, new IssueUpdate())); } } @@ -307,14 +479,26 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + client.Lock(1, 42); + + connection.Received().Put(Arg.Is(u => u.ToString() == "repositories/1/issues/42/lock"), Arg.Any(), Arg.Any(), Arg.Is(u => u.ToString() == "application/vnd.github.the-key-preview+json")); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new IssuesClient(connection); await Assert.ThrowsAsync(() => client.Lock(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Lock("", "name", 1)); await Assert.ThrowsAsync(() => client.Lock("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.Lock("", "name", 1)); await Assert.ThrowsAsync(() => client.Lock("owner", "", 1)); } } @@ -333,14 +517,26 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesClient(connection); + + client.Unlock(1, 42); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/issues/42/lock"), Arg.Any(), Arg.Is(u => u.ToString() == "application/vnd.github.the-key-preview+json")); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new IssuesClient(connection); await Assert.ThrowsAsync(() => client.Unlock(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Unlock("", "name", 1)); await Assert.ThrowsAsync(() => client.Unlock("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.Unlock("", "name", 1)); await Assert.ThrowsAsync(() => client.Unlock("owner", "", 1)); } } diff --git a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs index 0360cac1..9471a2d0 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesClientTests.cs @@ -5,7 +5,6 @@ using Octokit.Reactive; using System; using System.Collections.Generic; using System.Reactive.Linq; -using System.Reactive.Threading.Tasks; using System.Threading.Tasks; using Xunit; @@ -25,52 +24,235 @@ public class ObservableIssuesClientTests } [Fact] - public async Task EnsuresNonNullArguments() + public void GetsFromClientIssueIssueWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.Get(1, 42); + + gitHubClient.Issue.Received().Get(1, 42); + } + + [Fact] + public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Get(null, "name", 1).ToTask()); - await Assert.ThrowsAsync(() => client.Get("owner", null, 1).ToTask()); - await Assert.ThrowsAsync(() => client.Get(null, "", 1).ToTask()); - await Assert.ThrowsAsync(() => client.Get("", null, 1).ToTask()); + Assert.Throws(() => client.Get(null, "name", 1)); + Assert.Throws(() => client.Get("owner", null, 1)); + + Assert.Throws(() => client.Get("owner", "", 1)); + Assert.Throws(() => client.Get("", "name", 1)); } } public class TheGetAllForRepositoryMethod { [Fact] - public async Task EnsuresArgumentsNotNull() + public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For()); var options = new ApiOptions(); var request = new RepositoryIssueRequest(); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name").ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", request, options).ToTask()); + Assert.Throws(() => client.GetAllForRepository(null, "name")); + Assert.Throws(() => client.GetAllForRepository("owner", null)); + Assert.Throws(() => client.GetAllForRepository(null, "name", options)); + Assert.Throws(() => client.GetAllForRepository("owner", null, options)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); + Assert.Throws(() => client.GetAllForRepository(null, "name", request)); + Assert.Throws(() => client.GetAllForRepository("owner", null, request)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null)); + Assert.Throws(() => client.GetAllForRepository(null, "name", request, options)); + Assert.Throws(() => client.GetAllForRepository("owner", null, request, options)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", null, options)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", request, null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name").ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", request, options).ToTask()); + Assert.Throws(() => client.GetAllForRepository(1, (ApiOptions)null)); + Assert.Throws(() => client.GetAllForRepository(1, (RepositoryIssueRequest)null)); + Assert.Throws(() => client.GetAllForRepository(1, null, options)); + Assert.Throws(() => client.GetAllForRepository(1, request, null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, request, options).ToTask()); + Assert.Throws(() => client.GetAllForRepository("", "name")); + Assert.Throws(() => client.GetAllForRepository("owner", "")); + Assert.Throws(() => client.GetAllForRepository("", "name", options)); + Assert.Throws(() => client.GetAllForRepository("owner", "", options)); + Assert.Throws(() => client.GetAllForRepository("", "name", request)); + Assert.Throws(() => client.GetAllForRepository("owner", "", request)); + Assert.Throws(() => client.GetAllForRepository("", "name", request, options)); + Assert.Throws(() => client.GetAllForRepository("owner", "", request, options)); + } - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "").ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", request, options).ToTask()); + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (ApiOptions)null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (RepositoryIssueRequest)null).ToTask()); + client.GetAllForRepository("fake", "repo"); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null, options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", request, null).ToTask()); + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), + Arg.Any>(), null); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.GetAllForRepository(1); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Any>(), null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForRepository("fake", "repo", options); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), + Arg.Is>(d => d.Count == 6 + && d["filter"] == "assigned" + && d["state"] == "open" + && d["sort"] == "created" + && d["direction"] == "desc" + && d["page"] == "1" + && d["per_page"] == "1"), null); + } + + [Fact] + public void RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForRepository(1, options); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Is>(d => d.Count == 6 + && d["filter"] == "assigned" + && d["state"] == "open" + && d["sort"] == "created" + && d["direction"] == "desc" + && d["page"] == "1" + && d["per_page"] == "1"), null); + } + + [Fact] + public void SendsAppropriateParameters() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.GetAllForRepository("fake", "repo", new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), + Arg.Is>(d => d.Count == 4 + && d["filter"] == "assigned" + && d["state"] == "open" + && d["sort"] == "created" + && d["direction"] == "asc"), null); + } + + [Fact] + public void SendsAppropriateParametersWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.GetAllForRepository(1, new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Is>(d => d.Count == 4 + && d["filter"] == "assigned" + && d["state"] == "open" + && d["sort"] == "created" + && d["direction"] == "asc"), null); + } + + [Fact] + public void SendsAppropriateParametersWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForRepository("fake", "repo", new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }, options); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues"), + Arg.Is>(d => d.Count == 6 + && d["filter"] == "assigned" + && d["state"] == "open" + && d["sort"] == "created" + && d["direction"] == "asc" + && d["page"] == "1" + && d["per_page"] == "1"), + null); + } + + [Fact] + public void SendsAppropriateParametersWithRepositoryIdWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + StartPage = 1, + PageSize = 1 + }; + + client.GetAllForRepository(1, new RepositoryIssueRequest + { + SortDirection = SortDirection.Ascending + }, options); + + gitHubClient.Connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues"), + Arg.Is>(d => d.Count == 6 + && d["filter"] == "assigned" + && d["state"] == "open" + && d["sort"] == "created" + && d["direction"] == "asc" + && d["page"] == "1" + && d["per_page"] == "1"), + null); } [Fact] @@ -135,18 +317,18 @@ public class ObservableIssuesClientTests public class TheGetAllForOwnedAndMemberRepositoriesMethod { [Fact] - public async Task EnsuresNonNullArguments() + public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For()); - await Assert.ThrowsAsync( - () => client.GetAllForOwnedAndMemberRepositories((ApiOptions)null).ToTask()); - await Assert.ThrowsAsync( - () => client.GetAllForOwnedAndMemberRepositories((IssueRequest)null).ToTask()); - await Assert.ThrowsAsync( - () => client.GetAllForOwnedAndMemberRepositories(null, new ApiOptions()).ToTask()); - await Assert.ThrowsAsync( - () => client.GetAllForOwnedAndMemberRepositories(new IssueRequest(), null).ToTask()); + Assert.Throws( + () => client.GetAllForOwnedAndMemberRepositories((ApiOptions)null)); + Assert.Throws( + () => client.GetAllForOwnedAndMemberRepositories((IssueRequest)null)); + Assert.Throws( + () => client.GetAllForOwnedAndMemberRepositories(null, new ApiOptions())); + Assert.Throws( + () => client.GetAllForOwnedAndMemberRepositories(new IssueRequest(), null)); } [Fact] @@ -212,28 +394,28 @@ public class ObservableIssuesClientTests public class TheGetAllForOrganizationMethod { [Fact] - public async Task EnsuresArgumentsNotNull() + public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For()); var options = new ApiOptions(); var request = new RepositoryIssueRequest(); - await Assert.ThrowsAsync(() => client.GetAllForOrganization(null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization(null, options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization(null, request).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization(null, request, options).ToTask()); + Assert.Throws(() => client.GetAllForOrganization(null)); + Assert.Throws(() => client.GetAllForOrganization(null, options)); + Assert.Throws(() => client.GetAllForOrganization(null, request)); + Assert.Throws(() => client.GetAllForOrganization(null, request, options)); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("").ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("", options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("", request).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("", request, options).ToTask()); + Assert.Throws(() => client.GetAllForOrganization("")); + Assert.Throws(() => client.GetAllForOrganization("", options)); + Assert.Throws(() => client.GetAllForOrganization("", request)); + Assert.Throws(() => client.GetAllForOrganization("", request, options)); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("org", (ApiOptions)null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("org", (IssueRequest)null).ToTask()); + Assert.Throws(() => client.GetAllForOrganization("org", (ApiOptions)null)); + Assert.Throws(() => client.GetAllForOrganization("org", (IssueRequest)null)); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("org", null, options).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForOrganization("org", request, null).ToTask()); + Assert.Throws(() => client.GetAllForOrganization("org", null, options)); + Assert.Throws(() => client.GetAllForOrganization("org", request, null)); } [Fact] @@ -299,14 +481,14 @@ public class ObservableIssuesClientTests public class TheGetAllForCurrentMethod { [Fact] - public async Task EnsuresNonNullArguments() + public void EnsuresNonNullArguments() { var client = new ObservableIssuesClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.GetAllForCurrent((ApiOptions)null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForCurrent((IssueRequest)null).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForCurrent(null, new ApiOptions()).ToTask()); - await Assert.ThrowsAsync(() => client.GetAllForCurrent(new IssueRequest(), null).ToTask()); + Assert.Throws(() => client.GetAllForCurrent((ApiOptions)null)); + Assert.Throws(() => client.GetAllForCurrent((IssueRequest)null)); + Assert.Throws(() => client.GetAllForCurrent(null, new ApiOptions())); + Assert.Throws(() => client.GetAllForCurrent(new IssueRequest(), null)); } [Fact] @@ -383,16 +565,31 @@ public class ObservableIssuesClientTests } [Fact] - public void EnsuresArgumentsNotNull() + public void CreatesFromClientIssueIssueWithRepositoryId() + { + var newIssue = new NewIssue("some title"); + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.Create(1, newIssue); + + gitHubClient.Issue.Received().Create(1, newIssue); + } + + [Fact] + public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableIssuesClient(gitHubClient); - Assert.Throws(() => client.Create(null, "name", new NewIssue("title"))); - Assert.Throws(() => client.Create("", "name", new NewIssue("x"))); + Assert.Throws(() => client.Create(null, "name", new NewIssue("x"))); Assert.Throws(() => client.Create("owner", null, new NewIssue("x"))); - Assert.Throws(() => client.Create("owner", "", new NewIssue("x"))); Assert.Throws(() => client.Create("owner", "name", null)); + + Assert.Throws(() => client.Create(1, null)); + + Assert.Throws(() => client.Create("", "name", new NewIssue("x"))); + Assert.Throws(() => client.Create("owner", "", new NewIssue("x"))); } } @@ -411,16 +608,32 @@ public class ObservableIssuesClientTests } [Fact] - public void EnsuresArgumentsNotNull() + public void UpdatesClientIssueIssueWithRepositoryId() + { + var issueUpdate = new IssueUpdate(); + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.Update(1, 42, issueUpdate); + + gitHubClient.Issue.Received().Update(1, 42, issueUpdate); + } + + [Fact] + public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableIssuesClient(gitHubClient); Assert.Throws(() => client.Update(null, "name", 42, new IssueUpdate())); - Assert.Throws(() => client.Update("", "name", 42, new IssueUpdate())); Assert.Throws(() => client.Update("owner", null, 42, new IssueUpdate())); - Assert.Throws(() => client.Update("owner", "", 42, new IssueUpdate())); Assert.Throws(() => client.Update("owner", "name", 42, null)); + + Assert.Throws(() => client.Update(1, 42, null)); + + Assert.Throws(() => client.Update("", "name", 42, new IssueUpdate())); + Assert.Throws(() => client.Update("owner", "", 42, new IssueUpdate())); + } } @@ -433,18 +646,31 @@ public class ObservableIssuesClientTests var client = new ObservableIssuesClient(gitHubClient); client.Lock("fake", "repo", 42); + gitHubClient.Issue.Received().Lock("fake", "repo", 42); } [Fact] - public void EnsuresArgumentsNotNull() + public void LocksIssueWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.Lock(1, 42); + + gitHubClient.Issue.Received().Lock(1, 42); + } + + [Fact] + public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableIssuesClient(gitHubClient); Assert.Throws(() => client.Lock(null, "name", 42)); - Assert.Throws(() => client.Lock("", "name", 42)); Assert.Throws(() => client.Lock("owner", null, 42)); + + Assert.Throws(() => client.Lock("", "name", 42)); Assert.Throws(() => client.Lock("owner", "", 42)); } } @@ -458,18 +684,31 @@ public class ObservableIssuesClientTests var client = new ObservableIssuesClient(gitHubClient); client.Unlock("fake", "repo", 42); + gitHubClient.Issue.Received().Unlock("fake", "repo", 42); } [Fact] - public void EnsuresArgumentsNotNull() + public void UnlocksIssueWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesClient(gitHubClient); + + client.Unlock(1, 42); + + gitHubClient.Issue.Received().Unlock(1, 42); + } + + [Fact] + public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableIssuesClient(gitHubClient); Assert.Throws(() => client.Unlock(null, "name", 42)); - Assert.Throws(() => client.Unlock("", "name", 42)); Assert.Throws(() => client.Unlock("owner", null, 42)); + + Assert.Throws(() => client.Unlock("", "name", 42)); Assert.Throws(() => client.Unlock("owner", "", 42)); } }