diff --git a/Octokit.Tests/Clients/MilestonesClientTests.cs b/Octokit.Tests/Clients/MilestonesClientTests.cs index 660ec67e..ba102101 100644 --- a/Octokit.Tests/Clients/MilestonesClientTests.cs +++ b/Octokit.Tests/Clients/MilestonesClientTests.cs @@ -21,6 +21,17 @@ namespace Octokit.Tests.Clients connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/milestones/42")); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + client.Get(1, 42); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/milestones/42")); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -28,8 +39,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(null, "", 1)); - await Assert.ThrowsAsync(() => client.Get("", null, 1)); + + await Assert.ThrowsAsync(() => client.Get("", "name", 1)); + await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); } } @@ -47,6 +59,18 @@ namespace Octokit.Tests.Clients Arg.Any>(), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + await client.GetAllForRepository(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/milestones"), + Arg.Any>(), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -66,6 +90,25 @@ namespace Octokit.Tests.Clients Arg.Any>(), options); } + [Fact] + public async Task RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + await client.GetAllForRepository(1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/milestones"), + Arg.Any>(), options); + } + [Fact] public void SendsAppropriateParameters() { @@ -81,6 +124,21 @@ namespace Octokit.Tests.Clients && d["sort"] == "due_date"), Args.ApiOptions); } + [Fact] + public void SendsAppropriateParametersWithRepositoryId() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + client.GetAllForRepository(1, new MilestoneRequest { SortDirection = SortDirection.Descending }); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/milestones"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["state"] == "open" + && d["sort"] == "due_date"), Args.ApiOptions); + } + [Fact] public void SendsAppropriateParametersWithApiOptions() { @@ -103,6 +161,28 @@ namespace Octokit.Tests.Clients && d["sort"] == "due_date"), options); } + [Fact] + public void SendsAppropriateParametersWithApiOptionsWithRepositoryId() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAllForRepository(1, new MilestoneRequest { SortDirection = SortDirection.Descending }, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/milestones"), + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["state"] == "open" + && d["sort"] == "due_date"), options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -111,30 +191,35 @@ namespace Octokit.Tests.Clients await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, new MilestoneRequest())); 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, ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (ApiOptions)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, (MilestoneRequest)null)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, new MilestoneRequest(), null)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None)); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new MilestoneRequest())); await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", new MilestoneRequest())); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new MilestoneRequest())); - await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), ApiOptions.None)); await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", new MilestoneRequest(), ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), ApiOptions.None)); } } @@ -154,16 +239,32 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithRepositoryId() + { + var newMilestone = new NewMilestone("some title"); + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + client.Create(1, newMilestone); + + connection.Received().Post(Arg.Is(u => u.ToString() == "repositories/1/milestones"), + newMilestone); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new MilestonesClient(connection); - await Assert.ThrowsAsync(() => client.Create(null, "name", new NewMilestone("title"))); - await Assert.ThrowsAsync(() => client.Create("", "name", new NewMilestone("x"))); + await Assert.ThrowsAsync(() => client.Create(null, "name", new NewMilestone("x"))); await Assert.ThrowsAsync(() => client.Create("owner", null, new NewMilestone("x"))); - await Assert.ThrowsAsync(() => client.Create("owner", "", new NewMilestone("x"))); await Assert.ThrowsAsync(() => client.Create("owner", "name", null)); + + await Assert.ThrowsAsync(() => client.Create(1, null)); + + await Assert.ThrowsAsync(() => client.Create("", "name", new NewMilestone("x"))); + await Assert.ThrowsAsync(() => client.Create("owner", "", new NewMilestone("x"))); } } @@ -183,16 +284,32 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithRepositoryId() + { + var milestoneUpdate = new MilestoneUpdate(); + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + client.Update(1, 42, milestoneUpdate); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "repositories/1/milestones/42"), + milestoneUpdate); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new MilestonesClient(connection); await Assert.ThrowsAsync(() => client.Create(null, "name", new NewMilestone("title"))); - await Assert.ThrowsAsync(() => client.Create("", "name", new NewMilestone("x"))); await Assert.ThrowsAsync(() => client.Create("owner", null, new NewMilestone("x"))); - await Assert.ThrowsAsync(() => client.Create("owner", "", new NewMilestone("x"))); await Assert.ThrowsAsync(() => client.Create("owner", "name", null)); + + await Assert.ThrowsAsync(() => client.Create(1, null)); + + await Assert.ThrowsAsync(() => client.Create("", "name", new NewMilestone("x"))); + await Assert.ThrowsAsync(() => client.Create("owner", "", new NewMilestone("x"))); } } @@ -210,14 +327,26 @@ namespace Octokit.Tests.Clients } [Fact] - public async Task EnsuresArgumentsNotNull() + public void PostsToCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new MilestonesClient(connection); + + client.Delete(1, 42); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "repositories/1/milestones/42")); + } + + [Fact] + public async Task EnsuresNonNullArguments() { var connection = Substitute.For(); var client = new MilestonesClient(connection); await Assert.ThrowsAsync(() => client.Delete(null, "name", 42)); - await Assert.ThrowsAsync(() => client.Delete("", "name", 42)); await Assert.ThrowsAsync(() => client.Delete("owner", null, 42)); + + await Assert.ThrowsAsync(() => client.Delete("", "name", 42)); await Assert.ThrowsAsync(() => client.Delete("owner", "", 42)); } } diff --git a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs index 00dc018c..4281418d 100644 --- a/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableMilestonesClientTests.cs @@ -25,6 +25,17 @@ namespace Octokit.Tests.Reactive gitHubClient.Issue.Milestone.Received().Get("fake", "repo", 42); } + [Fact] + public void GetsFromClientIssueMilestoneWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + client.Get(1, 42); + + gitHubClient.Issue.Milestone.Received().Get(1, 42); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -32,6 +43,7 @@ namespace Octokit.Tests.Reactive 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()); } @@ -50,6 +62,17 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo"); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + client.GetAllForRepository(1); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository(1); + } + [Fact] public void RequestsCorrectUrlWithApiOptions() { @@ -68,6 +91,24 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", options); } + [Fact] + public void RequestsCorrectUrlWithApiOptionsWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + var options = new ApiOptions + { + PageCount = 1, + PageSize = 1, + StartPage = 1 + }; + + client.GetAllForRepository(1, options); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, options); + } + [Fact] public void SendsAppropriateParameters() { @@ -80,6 +121,18 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, Args.ApiOptions); } + [Fact] + public void SendsAppropriateParametersWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + var milestoneRequest = new MilestoneRequest { SortDirection = SortDirection.Descending }; + client.GetAllForRepository(1, milestoneRequest); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, milestoneRequest, Args.ApiOptions); + } + [Fact] public void SendsAppropriateParametersWithApiOptions() { @@ -99,38 +152,62 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Issue.Milestone.GetAllForRepository("fake", "repo", milestoneRequest, options); } + [Fact] + public void SendsAppropriateParametersWithApiOptionsWithRepositoryId() + { + 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(1, milestoneRequest, options); + + gitHubClient.Received().Issue.Milestone.GetAllForRepository(1, milestoneRequest, options); + } + [Fact] public void EnsuresNonNullArguments() { var client = new ObservableMilestonesClient(Substitute.For()); - Assert.Throws(() => client.GetAllForRepository("owner", 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", null, ApiOptions.None)); Assert.Throws(() => client.GetAllForRepository(null, "name", ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", (ApiOptions)null)); - Assert.Throws(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); - Assert.Throws(() => client.GetAllForRepository("owner", null, new MilestoneRequest())); Assert.Throws(() => client.GetAllForRepository(null, "name", new MilestoneRequest())); - - Assert.Throws(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); - Assert.Throws(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None)); - Assert.Throws(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", null, new MilestoneRequest())); + Assert.Throws(() => client.GetAllForRepository("owner", "name", (MilestoneRequest)null)); + Assert.Throws(() => client.GetAllForRepository(null, "name", new MilestoneRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", null, new MilestoneRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", new MilestoneRequest(), null)); + + Assert.Throws(() => client.GetAllForRepository(1, (ApiOptions)null)); + Assert.Throws(() => client.GetAllForRepository(1, (MilestoneRequest)null)); + Assert.Throws(() => client.GetAllForRepository(1, null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository(1, new MilestoneRequest(), null)); - Assert.Throws(() => client.GetAllForRepository("owner", "")); Assert.Throws(() => client.GetAllForRepository("", "name")); + Assert.Throws(() => client.GetAllForRepository("owner", "")); - Assert.Throws(() => client.GetAllForRepository("owner", "", ApiOptions.None)); Assert.Throws(() => client.GetAllForRepository("", "name", ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "", ApiOptions.None)); - Assert.Throws(() => client.GetAllForRepository("owner", "", new MilestoneRequest())); Assert.Throws(() => client.GetAllForRepository("", "name", new MilestoneRequest())); + Assert.Throws(() => client.GetAllForRepository("owner", "", new MilestoneRequest())); - Assert.Throws(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), ApiOptions.None)); Assert.Throws(() => client.GetAllForRepository("", "name", new MilestoneRequest(), ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "", new MilestoneRequest(), ApiOptions.None)); } [Fact] @@ -168,7 +245,7 @@ namespace Octokit.Tests.Reactive { new Milestone(7) } - ); + ); var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(firstPageUrl, Args.EmptyDictionary, null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); @@ -224,10 +301,10 @@ namespace Octokit.Tests.Reactive ); var gitHubClient = Substitute.For(); gitHubClient.Connection.Get>(Arg.Is(firstPageUrl), - Arg.Is>(d => d.Count == 3 - && d["direction"] == "desc" - && d["state"] == "open" - && d["sort"] == "due_date"), null) + Arg.Is>(d => d.Count == 3 + && d["direction"] == "desc" + && d["state"] == "open" + && d["sort"] == "due_date"), null) .Returns(Task.Factory.StartNew>>(() => firstPageResponse)); gitHubClient.Connection.Get>(secondPageUrl, Arg.Is>(d => d.Count == 3 && d["direction"] == "desc" @@ -239,7 +316,7 @@ namespace Octokit.Tests.Reactive && d["state"] == "open" && d["sort"] == "due_date"), null) .Returns(Task.Factory.StartNew>>(() => lastPageResponse)); - + var client = new ObservableMilestonesClient(gitHubClient); var results = await client.GetAllForRepository("fake", "repo", new MilestoneRequest { SortDirection = SortDirection.Descending }).ToArray(); @@ -266,16 +343,31 @@ namespace Octokit.Tests.Reactive } [Fact] - public void EnsuresArgumentsNotNull() + public void CreatesFromClientIssueMilestoneWithRepositoryId() + { + var newMilestone = new NewMilestone("some title"); + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + client.Create(1, newMilestone); + + gitHubClient.Issue.Milestone.Received().Create(1, newMilestone); + } + + [Fact] + public void EnsuresNonNullArguments() { 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(null, "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.Create(1, null)); + + Assert.Throws(() => client.Create("", "name", new NewMilestone("x"))); + Assert.Throws(() => client.Create("owner", "", new NewMilestone("x"))); } } @@ -294,16 +386,31 @@ namespace Octokit.Tests.Reactive } [Fact] - public void EnsuresArgumentsNotNull() + public void UpdatesClientIssueMilestoneWithRepositoryId() + { + var milestoneUpdate = new MilestoneUpdate(); + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + client.Update(1, 42, milestoneUpdate); + + gitHubClient.Issue.Milestone.Received().Update(1, 42, milestoneUpdate); + } + + [Fact] + public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableMilestonesClient(gitHubClient); 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)); + + Assert.Throws(() => client.Update(1, 42, null)); + + Assert.Throws(() => client.Update("", "name", 42, new MilestoneUpdate())); + Assert.Throws(() => client.Update("owner", "", 42, new MilestoneUpdate())); } } @@ -321,14 +428,26 @@ namespace Octokit.Tests.Reactive } [Fact] - public void EnsuresArgumentsNotNull() + public void DeletesFromClientIssueMilestoneWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableMilestonesClient(gitHubClient); + + client.Delete(1, 42); + + gitHubClient.Issue.Milestone.Received().Delete(1, 42); + } + + [Fact] + public void EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableMilestonesClient(gitHubClient); Assert.Throws(() => client.Delete(null, "name", 42)); - Assert.Throws(() => client.Delete("", "name", 42)); Assert.Throws(() => client.Delete("owner", null, 42)); + + Assert.Throws(() => client.Delete("", "name", 42)); Assert.Throws(() => client.Delete("owner", "", 42)); } }