From a7c427dc4e827e0570890e799d88870bfa5e6c2a Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Tue, 29 Mar 2016 13:58:28 +0700 Subject: [PATCH 1/4] Some ArgumentNotNullOrEmptyString were added in ObservableAssigneesClient. --- Octokit.Reactive/Clients/ObservableAssigneesClient.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Octokit.Reactive/Clients/ObservableAssigneesClient.cs b/Octokit.Reactive/Clients/ObservableAssigneesClient.cs index beabc06de0..de7eb9c9ca 100644 --- a/Octokit.Reactive/Clients/ObservableAssigneesClient.cs +++ b/Octokit.Reactive/Clients/ObservableAssigneesClient.cs @@ -25,6 +25,9 @@ public ObservableAssigneesClient(IGitHubClient client) /// public IObservable GetAllForRepository(string owner, string name) { + Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); + Ensure.ArgumentNotNullOrEmptyString(name, "name"); + return GetAllForRepository(owner, name, ApiOptions.None); } From c8eb2104e9a5b179421156c59c3b78eb74e00234 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Tue, 29 Mar 2016 19:38:44 +0700 Subject: [PATCH 2/4] ObservableAssigneesClientTests were added --- Octokit.Tests/Octokit.Tests.csproj | 1 + .../ObservableAssigneesClientTests.cs | 116 ++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 8fd268a0b2..842cb3bccf 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -198,6 +198,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs b/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs new file mode 100644 index 0000000000..02648a5bd4 --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs @@ -0,0 +1,116 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableAssigneesClientTests + { + private const string owner = "owner"; + private const string name = "name"; + private const string assignee = "assignee"; + + public class TheGetAllMethod + { + private readonly Uri _expectedUri; + + public TheGetAllMethod() + { + var uri = string.Format("repos/{0}/{1}/assignees", owner, name); + _expectedUri = new Uri(uri, UriKind.Relative); + } + + [Fact] + public void RequestsCorrectUrl() + { + var github = Substitute.For(); + var client = new ObservableAssigneesClient(github); + + client.GetAllForRepository(owner, name); + + github.Connection.Received(1).Get>(_expectedUri, + Arg.Is>(dictionary => dictionary.Count == 0), null); + } + + [Fact] + public void RequestsCorrectUrlWithApiOption() + { + var github = Substitute.For(); + var client = new ObservableAssigneesClient(github); + + client.GetAllForRepository(owner, name, new ApiOptions {PageSize = 1, StartPage = 1}); + + github.Connection.Received(1).Get>(_expectedUri, + Arg.Is>(dictionary => dictionary.Count == 2), null); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var github = Substitute.For(); + var client = new ObservableAssigneesClient(github); + + Assert.Throws(() => client.GetAllForRepository(null, name)); + Assert.Throws(() => client.GetAllForRepository(null, string.Empty)); + Assert.Throws(() => client.GetAllForRepository(owner, null)); + Assert.Throws(() => client.GetAllForRepository(string.Empty, null)); + Assert.Throws(() => client.GetAllForRepository(owner, name, null)); + } + } + + private static ObservableAssigneesClient CreateFixtureWithNonReactiveClient() + { + var nonreactiveClient = new AssigneesClient(Substitute.For()); + var github = Substitute.For(); + github.Issue.Assignee.Returns(nonreactiveClient); + return new ObservableAssigneesClient(github); + } + + public class TheCheckAssigneeMethod + { + [Fact] + public void CallsCheckAssigneeOnClient() + { + var github = Substitute.For(); + var client = new ObservableAssigneesClient(github); + + client.CheckAssignee(owner, name, assignee); + + github.Issue.Assignee.Received(1).CheckAssignee(Arg.Is(owner), Arg.Is(name), Arg.Is(assignee)); + } + + [Fact] + public void EnsuresNonNullArguments() + { + var client = CreateFixtureWithNonReactiveClient(); + + Assert.Throws(() => client.CheckAssignee(null, name, assignee)); + Assert.Throws(() => client.CheckAssignee(owner, null, assignee)); + Assert.Throws(() => client.CheckAssignee(owner, name, null)); + } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = CreateFixtureWithNonReactiveClient(); + + Assert.Throws(() => client.CheckAssignee(string.Empty, name, assignee)); + Assert.Throws(() => client.CheckAssignee(owner, string.Empty, assignee)); + Assert.Throws(() => client.CheckAssignee(owner, name, string.Empty)); + } + } + + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableAssigneesClient(null)); + } + } + } +} \ No newline at end of file From 8e2fee0752fedd579a3b5f0985023cdf6b212618 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Tue, 29 Mar 2016 19:44:32 +0700 Subject: [PATCH 3/4] Fix some tests. --- .../Reactive/ObservableAssigneesClientTests.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs b/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs index 02648a5bd4..a0df825bc2 100644 --- a/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs @@ -53,10 +53,8 @@ public async Task EnsuresNonNullArguments() var github = Substitute.For(); var client = new ObservableAssigneesClient(github); - Assert.Throws(() => client.GetAllForRepository(null, name)); - Assert.Throws(() => client.GetAllForRepository(null, string.Empty)); - Assert.Throws(() => client.GetAllForRepository(owner, null)); - Assert.Throws(() => client.GetAllForRepository(string.Empty, null)); + Assert.Throws(() => client.GetAllForRepository(null, name)); + Assert.Throws(() => client.GetAllForRepository(owner, null)); Assert.Throws(() => client.GetAllForRepository(owner, name, null)); } } @@ -87,9 +85,9 @@ public void EnsuresNonNullArguments() { var client = CreateFixtureWithNonReactiveClient(); - Assert.Throws(() => client.CheckAssignee(null, name, assignee)); - Assert.Throws(() => client.CheckAssignee(owner, null, assignee)); - Assert.Throws(() => client.CheckAssignee(owner, name, null)); + Assert.Throws(() => client.CheckAssignee(null, name, assignee)); + Assert.Throws(() => client.CheckAssignee(owner, null, assignee)); + Assert.Throws(() => client.CheckAssignee(owner, name, null)); } [Fact] From 1ae8235a961863fa597cbb61f3977f69da3e1bbd Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Tue, 29 Mar 2016 19:45:47 +0700 Subject: [PATCH 4/4] Some tests were added. --- Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs b/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs index a0df825bc2..92c7548567 100644 --- a/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableAssigneesClientTests.cs @@ -57,6 +57,15 @@ public async Task EnsuresNonNullArguments() Assert.Throws(() => client.GetAllForRepository(owner, null)); Assert.Throws(() => client.GetAllForRepository(owner, name, null)); } + + [Fact] + public void EnsuresNonEmptyArguments() + { + var client = CreateFixtureWithNonReactiveClient(); + + Assert.Throws(() => client.GetAllForRepository(string.Empty, name)); + Assert.Throws(() => client.GetAllForRepository(owner, string.Empty)); + } } private static ObservableAssigneesClient CreateFixtureWithNonReactiveClient()