From d1376c8f02b8ac61d165ea4f73adc4c3a7128f6d Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 30 Mar 2016 12:04:50 +0700 Subject: [PATCH] All remarks were fixed --- .../Clients/ObservableDeploymentsClient.cs | 3 ++ .../Clients/DeploymentsClientTests.cs | 28 +++++----- .../ObservableDeploymentsClientTests.cs | 51 ++++++++++--------- Octokit/Clients/DeploymentsClient.cs | 5 +- 4 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Octokit.Reactive/Clients/ObservableDeploymentsClient.cs b/Octokit.Reactive/Clients/ObservableDeploymentsClient.cs index 3d382af5..9a32ace1 100644 --- a/Octokit.Reactive/Clients/ObservableDeploymentsClient.cs +++ b/Octokit.Reactive/Clients/ObservableDeploymentsClient.cs @@ -31,6 +31,9 @@ namespace Octokit.Reactive.Clients /// All the s for the specified repository. public IObservable GetAll(string owner, string name) { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return GetAll(owner, name, ApiOptions.None); } diff --git a/Octokit.Tests/Clients/DeploymentsClientTests.cs b/Octokit.Tests/Clients/DeploymentsClientTests.cs index ef69431c..804835cc 100644 --- a/Octokit.Tests/Clients/DeploymentsClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentsClientTests.cs @@ -50,11 +50,11 @@ public class DeploymentsClientTests { var connection = Substitute.For(); var client = new DeploymentsClient(connection); - var expectedUrl = ApiUrls.Deployments(owner, name); + var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name); client.GetAll(owner, name); connection.Received(1) - .GetAll(Arg.Is(u => u == expectedUrl), Args.ApiOptions); + .GetAll(Arg.Is(u => u.ToString() == expectedUrl), Args.ApiOptions); } [Fact] @@ -62,7 +62,7 @@ public class DeploymentsClientTests { var connection = Substitute.For(); var client = new DeploymentsClient(connection); - var expectedUrl = ApiUrls.Deployments(owner, name); + var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name); var options = new ApiOptions { @@ -73,21 +73,21 @@ public class DeploymentsClientTests client.GetAll(owner, name, options); connection.Received(1) - .GetAll(Arg.Is(u => u == expectedUrl), options); + .GetAll(Arg.Is(u => u.ToString() == expectedUrl), options); } } public class TheCreateMethod { - private readonly NewDeployment _newDeployment = new NewDeployment("aRef"); + private readonly NewDeployment newDeployment = new NewDeployment("aRef"); [Fact] public async Task EnsuresNonNullArguments() { var client = new DeploymentsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Create(null, "name", _newDeployment)); - await Assert.ThrowsAsync(() => client.Create("owner", null, _newDeployment)); + await Assert.ThrowsAsync(() => client.Create(null, "name", newDeployment)); + await Assert.ThrowsAsync(() => client.Create("owner", null, newDeployment)); await Assert.ThrowsAsync(() => client.Create("owner", "name", null)); } @@ -96,8 +96,8 @@ public class DeploymentsClientTests { var client = new DeploymentsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Create("", "name", _newDeployment)); - await Assert.ThrowsAsync(() => client.Create("owner", "", _newDeployment)); + await Assert.ThrowsAsync(() => client.Create("", "name", newDeployment)); + await Assert.ThrowsAsync(() => client.Create("owner", "", newDeployment)); } [Theory] @@ -110,8 +110,8 @@ public class DeploymentsClientTests { var client = new DeploymentsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Create(whitespace, "name", _newDeployment)); - await Assert.ThrowsAsync(() => client.Create("owner", whitespace, _newDeployment)); + await Assert.ThrowsAsync(() => client.Create(whitespace, "name", newDeployment)); + await Assert.ThrowsAsync(() => client.Create("owner", whitespace, newDeployment)); } [Fact] @@ -121,7 +121,7 @@ public class DeploymentsClientTests var client = new DeploymentsClient(connection); var expectedUrl = "repos/owner/name/deployments"; - client.Create("owner", "name", _newDeployment); + client.Create("owner", "name", newDeployment); connection.Received(1).Post(Arg.Is(u => u.ToString() == expectedUrl), Arg.Any()); @@ -133,10 +133,10 @@ public class DeploymentsClientTests var connection = Substitute.For(); var client = new DeploymentsClient(connection); - client.Create("owner", "name", _newDeployment); + client.Create("owner", "name", newDeployment); connection.Received(1).Post(Arg.Any(), - _newDeployment); + newDeployment); } } diff --git a/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs b/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs index e3d815b9..477d1d78 100644 --- a/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableDeploymentsClientTests.cs @@ -51,21 +51,21 @@ namespace Octokit.Tests.Reactive [Fact] public void RequestsCorrectUrl() { - var expectedUri = ApiUrls.Deployments(owner, name); + var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name); _client.GetAll(owner, name); - _githubClient.Connection - .Received(1) - .Get>(Arg.Is(expectedUri), - Arg.Is>(dictionary => dictionary.Count == 0), Arg.Any()); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 0), + Arg.Any()); } [Fact] public void RequestsCorrectUrlWithApiOptions() { - var expectedUri = ApiUrls.Deployments(owner, name); - - // all properties are setted => only 2 options (StartPage, PageSize) in Dictionary + var expectedUrl = string.Format("repos/{0}/{1}/deployments", owner, name); + + // all properties are setted => only 2 options (StartPage, PageSize) in dictionary var options = new ApiOptions { StartPage = 1, @@ -74,34 +74,34 @@ namespace Octokit.Tests.Reactive }; _client.GetAll(owner, name, options); - _githubClient.Connection - .Received(1) - .Get>(Arg.Is(expectedUri), - Arg.Is>(dictionary => dictionary.Count == 2), null); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 2), + null); - // StartPage is setted => only 1 option (StartPage) in Dictionary + // StartPage is setted => only 1 option (StartPage) in dictionary options = new ApiOptions { StartPage = 1 }; _client.GetAll(owner, name, options); - _githubClient.Connection - .Received(1) - .Get>(Arg.Is(expectedUri), - Arg.Is>(dictionary => dictionary.Count == 1), null); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 1), + null); - // PageCount is setted => none of options in Dictionary + // PageCount is setted => none of options in dictionary options = new ApiOptions { PageCount = 1 }; _client.GetAll(owner, name, options); - _githubClient.Connection - .Received(1) - .Get>(Arg.Is(expectedUri), - Arg.Is>(dictionary => dictionary.Count == 0), null); + _githubClient.Connection.Received(1) + .Get>(Arg.Is(u => u.ToString() == expectedUrl), + Arg.Is>(dictionary => dictionary.Count == 0), + null); } } @@ -164,9 +164,10 @@ namespace Octokit.Tests.Reactive var newDeployment = new NewDeployment("ref"); _client.Create("owner", "repo", newDeployment); + _githubClient.Repository.Deployment.Received(1).Create(Arg.Is("owner"), - Arg.Is("repo"), - Arg.Is(newDeployment)); + Arg.Is("repo"), + Arg.Is(newDeployment)); } } @@ -179,4 +180,4 @@ namespace Octokit.Tests.Reactive } } } -} \ No newline at end of file +} diff --git a/Octokit/Clients/DeploymentsClient.cs b/Octokit/Clients/DeploymentsClient.cs index 4f63e510..db42b424 100644 --- a/Octokit/Clients/DeploymentsClient.cs +++ b/Octokit/Clients/DeploymentsClient.cs @@ -34,6 +34,9 @@ namespace Octokit /// All the s for the specified repository. public Task> GetAll(string owner, string name) { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return GetAll(owner, name, ApiOptions.None); } @@ -50,7 +53,7 @@ namespace Octokit /// All the s for the specified repository. public Task> GetAll(string owner, string name, ApiOptions options) { - Ensure.ArgumentNotNullOrEmptyString(owner, "login"); + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(options, "options");