From 622c19a97405d6d6e6e8a8343082f4e9c7fef6c7 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Wed, 25 May 2016 12:40:26 +0700 Subject: [PATCH] added unit tests --- .../Clients/DeploymentStatusClientTests.cs | 31 ++++++++++++++- .../ObservableDeploymentStatusClientTests.cs | 38 +++++++++++++++++-- 2 files changed, 65 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs index e88080c0..849457ab 100644 --- a/Octokit.Tests/Clients/DeploymentStatusClientTests.cs +++ b/Octokit.Tests/Clients/DeploymentStatusClientTests.cs @@ -2,6 +2,7 @@ using System.Threading.Tasks; using NSubstitute; using Octokit; +using Octokit.Tests; using Xunit; public class DeploymentStatusClientTests @@ -15,6 +16,10 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAll(null, "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", null, 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "name", 1, null)); } [Fact] @@ -24,6 +29,9 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.GetAll("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1)); + + await Assert.ThrowsAsync(() => client.GetAll("", "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", "", 1, ApiOptions.None)); } [Theory] @@ -38,6 +46,9 @@ public class DeploymentStatusClientTests await Assert.ThrowsAsync(() => client.GetAll(whitespace, "name", 1)); await Assert.ThrowsAsync(() => client.GetAll("owner", whitespace, 1)); + + await Assert.ThrowsAsync(() => client.GetAll(whitespace, "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAll("owner", whitespace, 1, ApiOptions.None)); } [Fact] @@ -48,7 +59,25 @@ public class DeploymentStatusClientTests var expectedUrl = "repos/owner/name/deployments/1/statuses"; client.GetAll("owner", "name", 1); - connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl)); + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), Args.ApiOptions); + } + + [Fact] + public void RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new DeploymentStatusClient(connection); + var expectedUrl = "repos/owner/name/deployments/1/statuses"; + + var options =new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + client.GetAll("owner", "name", 1, options); + connection.Received().GetAll(Arg.Is(u => u.ToString() == expectedUrl), options); } } diff --git a/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs b/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs index 0360d467..21567fba 100644 --- a/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableDeploymentStatusClientTests.cs @@ -27,6 +27,10 @@ namespace Octokit.Tests.Reactive { Assert.Throws(() => _client.GetAll(null, "repo", 1)); Assert.Throws(() => _client.GetAll("owner", null, 1)); + + Assert.Throws(() => _client.GetAll(null, "repo", 1, ApiOptions.None)); + Assert.Throws(() => _client.GetAll("owner", null, 1, ApiOptions.None)); + Assert.Throws(() => _client.GetAll("owner", "repo", 1, null)); } [Fact] @@ -34,6 +38,9 @@ namespace Octokit.Tests.Reactive { Assert.Throws(() => _client.GetAll("", "repo", 1)); Assert.Throws(() => _client.GetAll("owner", "", 1)); + + Assert.Throws(() => _client.GetAll("", "repo", 1, ApiOptions.None)); + Assert.Throws(() => _client.GetAll("owner", "", 1, ApiOptions.None)); } [Fact] @@ -43,10 +50,15 @@ namespace Octokit.Tests.Reactive async whitespace => await _client.GetAll(whitespace, "repo", 1)); await AssertEx.ThrowsWhenGivenWhitespaceArgument( async whitespace => await _client.GetAll("owner", whitespace, 1)); + + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.GetAll(whitespace, "repo", 1, ApiOptions.None)); + await AssertEx.ThrowsWhenGivenWhitespaceArgument( + async whitespace => await _client.GetAll("owner", whitespace, 1, ApiOptions.None)); } [Fact] - public void GetsFromCorrectUrl() + public void RequestsCorrectUrl() { var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1); @@ -54,8 +66,28 @@ namespace Octokit.Tests.Reactive _githubClient.Connection.Received(1) .Get>(Arg.Is(expectedUri), - Arg.Any>(), - Arg.Any()); + Args.EmptyDictionary, + null); + } + + [Fact] + public void RequestsCorrectUrlWitApiOptions() + { + var expectedUri = ApiUrls.DeploymentStatuses("owner", "repo", 1); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + _client.GetAll("owner", "repo", 1, options); + + _githubClient.Connection.Received(1) + .Get>(Arg.Is(expectedUri), + Arg.Is>(dictionary => dictionary.Count == 2), + null); } }