diff --git a/Octokit.Tests/Clients/MilestonesClientTests.cs b/Octokit.Tests/Clients/MilestonesClientTests.cs index e5807a7c..9c12fffd 100644 --- a/Octokit.Tests/Clients/MilestonesClientTests.cs +++ b/Octokit.Tests/Clients/MilestonesClientTests.cs @@ -44,7 +44,26 @@ namespace Octokit.Tests.Clients await client.GetAllForRepository("fake", "repo"); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones"), - Arg.Any>()); + Arg.Any>(), Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + await client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones"), + Arg.Any>(), options); } [Fact] @@ -59,7 +78,68 @@ namespace Octokit.Tests.Clients Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" && d["state"] == "open" - && d["sort"] == "due_date")); + && d["sort"] == "due_date"), Args.ApiOptions); + } + + [Fact] + public void SendsAppropriateParametersWithApiOptions() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAllForRepository("fake", "repo", new MilestoneRequest { SortDirection = SortDirection.Descending }, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["state"] == "open" + && d["sort"] == "due_date"), options); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new MilestonesClient(Substitute.For()); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, new ApiOptions())); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", new MilestoneRequest())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, new MilestoneRequest())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null, new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), new ApiOptions())); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new ApiOptions())); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", new MilestoneRequest())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new MilestoneRequest())); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), new ApiOptions())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", new MilestoneRequest(), new ApiOptions())); } } diff --git a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs index beade987..a5812acc 100644 --- a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs @@ -40,7 +40,106 @@ namespace Octokit.Tests.Reactive public class TheGetForRepositoryMethod { [Fact] - public async Task ReturnsEveryPageOfMilestones() + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + client.GetAllForRepository("fake", "repo"); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo"); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAllForRepository("fake", "repo", options); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", options); + } + + [Fact] + public void SendsAppropriateParameters() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending }; + client.GetAllForRepository("fake", "repo", milestoneRequest); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, Args.ApiOptions); + } + + [Fact] + public void SendsAppropriateParametersWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending }; + client.GetAllForRepository("fake", "repo", milestoneRequest, options); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, options); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = new ObservableMilestonesClient(Substitute.For()); + + Assert.Throws(() => client.GetAllForRepository(null, null)); + Assert.Throws(() => client.GetAllForRepository(null, "name")); + Assert.Throws(() => client.GetAllForRepository("owner", null)); + + Assert.Throws(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); + + Assert.Throws(() => client.GetAllForRepository(null, "name", new ApiOptions())); + Assert.Throws(() => client.GetAllForRepository("owner", null, new ApiOptions())); + + Assert.Throws(() => client.GetAllForRepository(null, "name", new MilestoneRequest())); + Assert.Throws(() => client.GetAllForRepository("owner", null, new MilestoneRequest())); + Assert.Throws(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); + + Assert.Throws(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", null, new ApiOptions())); + Assert.Throws(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), new ApiOptions())); + Assert.Throws(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), new ApiOptions())); + + Assert.Throws(() => client.GetAllForRepository("", "")); + Assert.Throws(() => client.GetAllForRepository("", "name")); + Assert.Throws(() => client.GetAllForRepository("owner", "")); + + Assert.Throws(() => client.GetAllForRepository("", "name", new ApiOptions())); + Assert.Throws(() => client.GetAllForRepository("owner", "", new ApiOptions())); + + Assert.Throws(() => client.GetAllForRepository("", "name", new MilestoneRequest())); + Assert.Throws(() => client.GetAllForRepository("owner", "", new MilestoneRequest())); + + Assert.Throws(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), new ApiOptions())); + Assert.Throws(() => client.GetAllForRepository("", "name", new MilestoneRequest(), new ApiOptions())); + } + + [Fact] + public void ReturnsEveryPageOfMilestones() { var firstPageUrl = new Uri("repos/fake/repo/milestones", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); @@ -84,7 +183,7 @@ namespace Octokit.Tests.Reactive .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); var client = new ObservableMilestonesClient(gitHubClient); - var results = await client.GetAllForRepository("fake", "repo").ToArray(); + var results = client.GetAllForRepository("fake", "repo").ToArray().Wait(); Assert.Equal(7, results.Length); Assert.Equal(firstPageResponse.Body[0].Number, results[0].Number); @@ -93,7 +192,7 @@ namespace Octokit.Tests.Reactive } [Fact] - public async Task SendsAppropriateParameters() + public async Task SendsAppropriateParametersMulti() { var firstPageUrl = new Uri("repos/fake/repo/milestones", UriKind.Relative); var secondPageUrl = new Uri("https://example.com/page/2"); @@ -198,11 +297,11 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservableMilestonesClient(gitHubClient); - Assert.Throws(() => client.Create(null, "name", new NewMilestone("title"))); - Assert.Throws(() => client.Create("", "name", new NewMilestone("x"))); - Assert.Throws(() => client.Create("owner", null, new NewMilestone("x"))); - Assert.Throws(() => client.Create("owner", "", new NewMilestone("x"))); - Assert.Throws(() => client.Create("owner", "name", null)); + Assert.Throws(() => client.Update(null, "name", 42, new MilestoneUpdate())); + Assert.Throws(() => client.Update("", "name", 42, new MilestoneUpdate())); + Assert.Throws(() => client.Update("owner", null, 42, new MilestoneUpdate())); + Assert.Throws(() => client.Update("owner", "", 42, new MilestoneUpdate())); + Assert.Throws(() => client.Update("owner", "name", 42, null)); } } @@ -237,7 +336,7 @@ namespace Octokit.Tests.Reactive [Fact] public void EnsuresNonNullArguments() { - Assert.Throws(() => new MilestonesClient(null)); + Assert.Throws(() => new ObservableMilestonesClient(null)); } }