From b24c80e1940b34c8adf3529fe8a1d74b11e24546 Mon Sep 17 00:00:00 2001 From: "aedampir@gmail.com" Date: Fri, 20 May 2016 19:22:52 +0700 Subject: [PATCH] added new unit tests --- Octokit.Tests/Clients/ReleasesClientTests.cs | 82 +++++++++++++------ .../Reactive/ObservableReleasesClientTests.cs | 31 ++++++- 2 files changed, 84 insertions(+), 29 deletions(-) diff --git a/Octokit.Tests/Clients/ReleasesClientTests.cs b/Octokit.Tests/Clients/ReleasesClientTests.cs index 9e79d47e..837e6c8c 100644 --- a/Octokit.Tests/Clients/ReleasesClientTests.cs +++ b/Octokit.Tests/Clients/ReleasesClientTests.cs @@ -21,12 +21,12 @@ namespace Octokit.Tests.Clients public class TheGetAllMethod { [Fact] - public void RequestsCorrectUrl() + public async void RequestsCorrectUrl() { var client = Substitute.For(); var releasesClient = new ReleasesClient(client); - releasesClient.GetAll("fake", "repo"); + await releasesClient.GetAll("fake", "repo"); client.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/releases"), null, @@ -35,7 +35,7 @@ namespace Octokit.Tests.Clients } [Fact] - public void RequestsCorrectUrlWithApiOptions() + public async void RequestsCorrectUrlWithApiOptions() { var client = Substitute.For(); var releasesClient = new ReleasesClient(client); @@ -47,7 +47,7 @@ namespace Octokit.Tests.Clients StartPage = 1 }; - releasesClient.GetAll("fake", "repo", options); + await releasesClient.GetAll("fake", "repo", options); client.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/releases"), null, @@ -73,12 +73,12 @@ namespace Octokit.Tests.Clients public class TheGetReleaseMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); - client.Get("fake", "repo", 1); + await client.Get("fake", "repo", 1); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/1")); } @@ -98,12 +98,12 @@ namespace Octokit.Tests.Clients public class TheGetLatestReleaseMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); - client.GetLatest("fake", "repo"); + await client.GetLatest("fake", "repo"); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/latest")); } @@ -122,13 +122,13 @@ namespace Octokit.Tests.Clients public class TheCreateReleaseMethod { [Fact] - public void RequestsCorrectUrl() + public async void RequestsCorrectUrl() { var client = Substitute.For(); var releasesClient = new ReleasesClient(client); var data = new NewRelease("fake-tag"); - releasesClient.Create("fake", "repo", data); + await releasesClient.Create("fake", "repo", data); client.Received().Post(Arg.Is(u => u.ToString() == "repos/fake/repo/releases"), data, @@ -151,13 +151,13 @@ namespace Octokit.Tests.Clients public class TheEditReleaseMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var releasesClient = new ReleasesClient(connection); var data = new ReleaseUpdate { TagName = "fake-tag" }; - releasesClient.Edit("fake", "repo", 1, data); + await releasesClient.Edit("fake", "repo", 1, data); connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/1"), data); } @@ -179,12 +179,12 @@ namespace Octokit.Tests.Clients public class TheDeleteReleaseMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); - client.Delete("fake", "repo", 1); + await client.Delete("fake", "repo", 1); connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/1")); } @@ -204,26 +204,54 @@ namespace Octokit.Tests.Clients public class TheGetAssetsMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); - client.GetAllAssets("fake", "repo", 1); + await client.GetAllAssets("fake", "repo", 1); connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/1/assets"), null, - "application/vnd.github.v3"); + "application/vnd.github.v3", + Args.ApiOptions); + } + + [Fact] + public async void RequestsTheCorrectUrlWithApiOptions() + { + var connection = Substitute.For(); + var client = new ReleasesClient(connection); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + await client.GetAllAssets("fake", "repo", 1, options); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/1/assets"), + null, + "application/vnd.github.v3", options); } [Fact] public async Task EnsuresNonNullArguments() { var client = new ReleasesClient(Substitute.For()); - + + await Assert.ThrowsAsync(() => client.GetAllAssets(null, null, 1)); await Assert.ThrowsAsync(() => client.GetAllAssets(null, "name", 1)); - await Assert.ThrowsAsync(() => client.GetAllAssets("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAllAssets("owner", null, 1)); + + await Assert.ThrowsAsync(() => client.GetAllAssets(null, null, 1, null)); + await Assert.ThrowsAsync(() => client.GetAllAssets(null, null, 1, Args.ApiOptions)); + await Assert.ThrowsAsync(() => client.GetAllAssets(null, "name", 1, null)); + await Assert.ThrowsAsync(() => client.GetAllAssets("owner", null, 1, null)); + + await Assert.ThrowsAsync(() => client.GetAllAssets("", "name", 1)); await Assert.ThrowsAsync(() => client.GetAllAssets("owner", "", 1)); } } @@ -231,7 +259,7 @@ namespace Octokit.Tests.Clients public class TheUploadReleaseAssetMethod { [Fact] - public void UploadsToCorrectUrl() + public async void UploadsToCorrectUrl() { var client = Substitute.For(); var releasesClient = new ReleasesClient(client); @@ -239,7 +267,7 @@ namespace Octokit.Tests.Clients var rawData = Substitute.For(); var upload = new ReleaseAssetUpload("example.zip", "application/zip", rawData, null); - releasesClient.UploadAsset(release, upload); + await releasesClient.UploadAsset(release, upload); client.Received().Post( Arg.Is(u => u.ToString() == "https://uploads.test.dev/does/not/matter/releases/1/assets?name=example.zip"), @@ -280,12 +308,12 @@ namespace Octokit.Tests.Clients public class TheGetAssetMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); - client.GetAsset("fake", "repo", 1); + await client.GetAsset("fake", "repo", 1); connection.Received().Get(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/assets/1")); } @@ -305,13 +333,13 @@ namespace Octokit.Tests.Clients public class TheEditAssetMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); var data = new ReleaseAssetUpdate("asset"); - client.EditAsset("fake", "repo", 1, data); + await client.EditAsset("fake", "repo", 1, data); connection.Received().Patch(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/assets/1"), data); @@ -333,12 +361,12 @@ namespace Octokit.Tests.Clients public class TheDeleteAssetMethod { [Fact] - public void RequestsTheCorrectUrl() + public async void RequestsTheCorrectUrl() { var connection = Substitute.For(); var client = new ReleasesClient(connection); - client.DeleteAsset("fake", "repo", 1); + await client.DeleteAsset("fake", "repo", 1); connection.Received().Delete(Arg.Is(u => u.ToString() == "repos/fake/repo/releases/assets/1")); } diff --git a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs index ca163f6d..0e7317cd 100644 --- a/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs +++ b/Octokit.Tests/Reactive/ObservableReleasesClientTests.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Reactive.Linq; using NSubstitute; using Octokit.Reactive; using Xunit; @@ -181,7 +182,26 @@ namespace Octokit.Tests.Reactive client.GetAllAssets("fake", "repo", 1); gitHubClient.Connection.Received(1).Get>( - new Uri("repos/fake/repo/releases/1/assets", UriKind.Relative), null, null); + new Uri("repos/fake/repo/releases/1/assets", UriKind.Relative), Args.EmptyDictionary, null); + } + + [Fact] + public void RequestsTheCorrectUrlWithApiOptions() + { + var gitHubClient = Substitute.For(); + var client = new ObservableReleasesClient(gitHubClient); + + var options = new ApiOptions + { + StartPage = 1, + PageCount = 1, + PageSize = 1 + }; + + client.GetAllAssets("fake", "repo", 1, options); + + gitHubClient.Connection.Received(1).Get>( + new Uri("repos/fake/repo/releases/1/assets", UriKind.Relative), Arg.Is>(dictionary => dictionary.Count == 2), null); } [Fact] @@ -189,9 +209,16 @@ namespace Octokit.Tests.Reactive { var client = new ObservableReleasesClient(Substitute.For()); + Assert.Throws(() => client.GetAllAssets(null, null, 1)); Assert.Throws(() => client.GetAllAssets(null, "name", 1)); - Assert.Throws(() => client.GetAllAssets("", "name", 1)); Assert.Throws(() => client.GetAllAssets("owner", null, 1)); + + Assert.Throws(() => client.GetAllAssets(null, null, 1, null)); + Assert.Throws(() => client.GetAllAssets(null, null, 1, Args.ApiOptions)); + Assert.Throws(() => client.GetAllAssets(null, "name", 1, null)); + Assert.Throws(() => client.GetAllAssets("owner", null, 1, null)); + + Assert.Throws(() => client.GetAllAssets("", "name", 1)); Assert.Throws(() => client.GetAllAssets("owner", "", 1)); } }