From a33204b384618e92dedabc76c90e12a630852084 Mon Sep 17 00:00:00 2001 From: Alexander Efremov Date: Mon, 13 Jun 2016 17:34:29 +0700 Subject: [PATCH] added new unit tests --- .../Clients/IssuesEventsClientTests.cs | 88 +++++++++++- .../ObservableIssuesEventsClientTests.cs | 136 +++++++++++++++++- 2 files changed, 220 insertions(+), 4 deletions(-) diff --git a/Octokit.Tests/Clients/IssuesEventsClientTests.cs b/Octokit.Tests/Clients/IssuesEventsClientTests.cs index 03cbbd0b..3e3f46f7 100644 --- a/Octokit.Tests/Clients/IssuesEventsClientTests.cs +++ b/Octokit.Tests/Clients/IssuesEventsClientTests.cs @@ -30,6 +30,17 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events"), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + await client.GetAllForIssue(1, 42); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/42/events"), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -48,6 +59,24 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/42/events"), options); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAllForIssue(1, 42, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/42/events"), options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -55,10 +84,16 @@ namespace Octokit.Tests.Clients 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)); + + await Assert.ThrowsAsync(() => client.GetAllForIssue(1, 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("", "name", 1, ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None)); } } @@ -75,6 +110,17 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), Args.ApiOptions); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + await client.GetAllForRepository(1); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/events"), Args.ApiOptions); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -93,6 +139,24 @@ namespace Octokit.Tests.Clients connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events"), options); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAllForRepository(1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repositories/1/issues/events"), options); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -100,10 +164,16 @@ namespace Octokit.Tests.Clients 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)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository(1, null)); + + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "")); + await Assert.ThrowsAsync(() => client.GetAllForRepository("", "name", ApiOptions.None)); + await Assert.ThrowsAsync(() => client.GetAllForRepository("owner", "", ApiOptions.None)); } } @@ -120,6 +190,17 @@ namespace Octokit.Tests.Clients connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/issues/events/42")); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var connection = Substitute.For(); + var client = new IssuesEventsClient(connection); + + client.Get(1, 42); + + connection.Received().Get(Arg.Is(u => u.ToString() == "repositories/1/issues/events/42")); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -127,6 +208,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("", "name", 1)); + await Assert.ThrowsAsync(() => client.Get("owner", "", 1)); } } } diff --git a/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs b/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs index 31b082be..c665c1c7 100644 --- a/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableIssuesEventsClientTests.cs @@ -46,6 +46,29 @@ namespace Octokit.Tests.Reactive Assert.Equal(1, eventInfos.Count); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + 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(1, 42).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues/42/events"), Args.EmptyDictionary, null); + Assert.Equal(1, eventInfos.Count); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -76,6 +99,36 @@ namespace Octokit.Tests.Reactive Assert.Equal(1, eventInfos.Count); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + 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(1, 42, options).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues/42/events"), Arg.Is>(d => d.Count == 2), null); + Assert.Equal(1, eventInfos.Count); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -83,10 +136,16 @@ namespace Octokit.Tests.Reactive 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)); + + Assert.Throws(() => client.GetAllForIssue(1, 1, null)); + + Assert.Throws(() => client.GetAllForIssue("", "name", 1)); + Assert.Throws(() => client.GetAllForIssue("owner", "", 1)); + Assert.Throws(() => client.GetAllForIssue("", "name", 1, ApiOptions.None)); + Assert.Throws(() => client.GetAllForIssue("owner", "", 1, ApiOptions.None)); } } @@ -115,6 +174,29 @@ namespace Octokit.Tests.Reactive Assert.Equal(1, issueEvents.Count); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryId() + { + 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(1).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues/events"), Args.EmptyDictionary, null); + Assert.Equal(1, issueEvents.Count); + } + [Fact] public async Task RequestsCorrectUrlWithApiOptions() { @@ -145,6 +227,36 @@ namespace Octokit.Tests.Reactive Assert.Equal(1, issueEvents.Count); } + [Fact] + public async Task RequestsCorrectUrlWithRepositoryIdWithApiOptions() + { + 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(1, options).ToList(); + + connection.Received().Get>(Arg.Is(u => u.ToString() == "repositories/1/issues/events"), Arg.Is>(d => d.Count == 2), null); + Assert.Equal(1, issueEvents.Count); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -152,10 +264,16 @@ namespace Octokit.Tests.Reactive 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)); + + Assert.Throws(() => client.GetAllForRepository(1, null)); + + Assert.Throws(() => client.GetAllForRepository("", "name")); + Assert.Throws(() => client.GetAllForRepository("owner", "")); + Assert.Throws(() => client.GetAllForRepository("", "name", ApiOptions.None)); + Assert.Throws(() => client.GetAllForRepository("owner", "", ApiOptions.None)); } } @@ -172,6 +290,17 @@ namespace Octokit.Tests.Reactive gitHubClient.Received().Issue.Events.Get("fake", "repo", 42); } + [Fact] + public void RequestsCorrectUrlWithRepositoryId() + { + var gitHubClient = Substitute.For(); + var client = new ObservableIssuesEventsClient(gitHubClient); + + client.Get(1, 42); + + gitHubClient.Received().Issue.Events.Get(1, 42); + } + [Fact] public async Task EnsuresNonNullArguments() { @@ -179,6 +308,9 @@ namespace Octokit.Tests.Reactive Assert.Throws(() => client.Get(null, "name", 1)); Assert.Throws(() => client.Get("owner", null, 1)); + + Assert.Throws(() => client.Get("", "name", 1)); + Assert.Throws(() => client.Get("owner", "", 1)); } } }