diff --git a/Octokit.Tests/Clients/IssuesEventsClientTests.cs b/Octokit.Tests/Clients/IssuesEventsClientTests.cs index 98f20170..03cbbd0b 100644 --- a/Octokit.Tests/Clients/IssuesEventsClientTests.cs +++ b/Octokit.Tests/Clients/IssuesEventsClientTests.cs @@ -27,7 +27,25 @@ namespace Octokit.Tests.Clients await client.GetAllForIssue("fake", "repo", 42); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events"), Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAllForIssue("fake", "repo", 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events"), options); } [Fact] @@ -35,8 +53,12 @@ namespace Octokit.Tests.Clients { var client = new IssuesEventsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "name", 1, null)); } } @@ -50,7 +72,25 @@ namespace Octokit.Tests.Clients await client.GetAllForRepository("fake", "repo"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events")); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAllForRepository("fake", "repo", options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), options); } [Fact] @@ -58,8 +98,12 @@ namespace Octokit.Tests.Clients { var client = new IssuesEventsClient(Substitute.For()); - await Assert.ThrowsAsync(() => client.Get(null, "name", 1)); - await Assert.ThrowsAsync(() => client.Get("owner", null, 1)); + await Assert.ThrowsAsync(() => client.GetAllForRepository(null, "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", null)); + + 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", null)); } } diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index c15db0ba..deb7e33c 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -223,6 +223,7 @@ + diff --git a/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs new file mode 100644 index 00000000..31b082be --- /dev/null +++ b/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs @@ -0,0 +1,185 @@ +using System; +using System.Collections.Generic; +using System.Reactive.Linq; +using System.Threading.Tasks; +using NSubstitute; +using Octokit.Internal; +using Octokit.Reactive; +using Xunit; + +namespace Octokit.Tests.Reactive +{ + public class ObservableIssuesEventsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresNonNullArguments() + { + Assert.Throws( + () => new ObservableIssuesEventsClient(null)); + } + } + + public class TheGetForIssueMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var result = new List { new EventInfo() }; + + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableIssuesEventsClient(gitHubClient); + + IApiResponse> response = new ApiResponse>( + new Response + { + ApiInfo = new ApiInfo(new Dictionary(), new List(), new List(), "etag", new RateLimit()), + }, result); + gitHubClient.Connection.Get>(Args.Uri, Args.EmptyDictionary, null) + .Returns(Task.FromResult(response)); + + var eventInfos = await client.GetAllForIssue("fake", "repo", 42).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events"), Args.EmptyDictionary, null); + Assert.Equal(1, eventInfos.Count); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var result = new List { new EventInfo() }; + + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableIssuesEventsClient(gitHubClient); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + IApiResponse> response = new ApiResponse>( + new Response + { + ApiInfo = new ApiInfo(new Dictionary(), new List(), new List(), "etag", new RateLimit()), + }, result); + gitHubClient.Connection.Get>(Args.Uri, Arg.Is>(d => d.Count == 2), null) + .Returns(Task.FromResult(response)); + + var eventInfos = await client.GetAllForIssue("fake", "repo", 42, options).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events"), Arg.Is>(d => d.Count == 2), null); + Assert.Equal(1, eventInfos.Count); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableIssuesEventsClient(Substitute.For()); + + Assert.Throws(() => client.GetAllForIssue(null, "name", 1)); + Assert.Throws(() => client.GetAllForIssue("owner", null, 1)); + + Assert.Throws(() => client.GetAllForIssue(null, "name", 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllForIssue("owner", null, 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllForIssue("owner", "name", 1, null)); + } + } + + public class TheGetForRepositoryMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var result = new List { new IssueEvent() }; + + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableIssuesEventsClient(gitHubClient); + + IApiResponse> response = new ApiResponse>( + new Response + { + ApiInfo = new ApiInfo(new Dictionary(), new List(), new List(), "etag1", new RateLimit()), + }, result); + gitHubClient.Connection.Get>(Args.Uri, Args.EmptyDictionary, null) + .Returns(Task.FromResult(response)); + + var issueEvents = await client.GetAllForRepository("fake", "repo").ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.EmptyDictionary, null); + Assert.Equal(1, issueEvents.Count); + } + + [Fact] + public async Task RequestsCorrectUrlWithApiOptions() + { + var result = new List { new IssueEvent() }; + + var connection = Substitute.For(); + var gitHubClient = new GitHubClient(connection); + var client = new ObservableIssuesEventsClient(gitHubClient); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + IApiResponse> response = new ApiResponse>( + new Response + { + ApiInfo = new ApiInfo(new Dictionary(), new List(), new List(), "etag1", new RateLimit()), + }, result); + gitHubClient.Connection.Get>(Args.Uri, Arg.Is>(d => d.Count == 2), null) + .Returns(Task.FromResult(response)); + + var issueEvents = await client.GetAllForRepository("fake", "repo", options).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Arg.Is>(d => d.Count == 2), null); + Assert.Equal(1, issueEvents.Count); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableIssuesEventsClient(Substitute.For()); + + Assert.Throws(() => client.GetAllForRepository(null, "name")); + Assert.Throws(() => client.GetAllForRepository("owner", null)); + + Assert.Throws(() => client.GetAllForRepository(null, "name", ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", null, ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "name", null)); + } + } + + public class TheGetMethod + { + [Fact] + public void RequestsCorrectUrl() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesEventsClient(gitHubClient); + + client.Get("fake", "repo", 42); + + gitHubClient.Received().Issue.Events.Get("fake", "repo", 42); + } + + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new ObservableIssuesEventsClient(Substitute.For()); + + Assert.Throws(() => client.Get(null, "name", 1)); + Assert.Throws(() => client.Get("owner", null, 1)); + } + } + } +}