using System; using System.Collections.Generic; using System.Threading.Tasks; using NSubstitute; using Octokit.Reactive; using Xunit; namespace Octokit.Tests.Clients { public class ObservableObservableCheckSuitesClientTests { public class TheCtor { [Fact] public void EnsuresNonNullArguments() { Assert.Throws(() => new ObservableCheckSuitesClient(null)); } } public class TheGetMethod { [Fact] public async Task RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); client.Get("fake", "repo", 1); gitHubClient.Check.Suite.Received().Get("fake", "repo", 1); } [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); client.Get(1, 1); gitHubClient.Check.Suite.Received().Get(1, 1); } [Fact] public async Task EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); Assert.Throws(() => client.Get(null, "repo", 1)); Assert.Throws(() => client.Get("fake", null, 1)); Assert.Throws(() => client.Get(null, "repo", 1)); } [Fact] public async Task EnsuresNonEmptyArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); Assert.Throws(() => client.Get("", "repo", 1)); Assert.Throws(() => client.Get("fake", "", 1)); } } public class TheGetAllForReferenceMethod { [Fact] public async Task RequestsCorrectUrl() { var connection = Substitute.For(); var gitHubClient = new GitHubClient(connection); var client = new ObservableCheckSuitesClient(gitHubClient); client.GetAllForReference("fake", "repo", "ref"); connection.Received().Get>( Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-suites"), Args.EmptyDictionary); } [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { var connection = Substitute.For(); var gitHubClient = new GitHubClient(connection); var client = new ObservableCheckSuitesClient(gitHubClient); client.GetAllForReference(1, "ref"); connection.Received().Get>( Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-suites"), Args.EmptyDictionary); } [Fact] public async Task RequestsCorrectUrlWithRequest() { var connection = Substitute.For(); var gitHubClient = new GitHubClient(connection); var client = new ObservableCheckSuitesClient(gitHubClient); var request = new CheckSuiteRequest { AppId = 123, CheckName = "build" }; client.GetAllForReference("fake", "repo", "ref", request); connection.Received().Get>( Arg.Is(u => u.ToString() == "repos/fake/repo/commits/ref/check-suites"), Arg.Is>(x => x["app_id"] == "123" && x["check_name"] == "build")); } [Fact] public async Task RequestsCorrectUrlWithRequestWithRepositoryId() { var connection = Substitute.For(); var gitHubClient = new GitHubClient(connection); var client = new ObservableCheckSuitesClient(gitHubClient); var request = new CheckSuiteRequest { AppId = 123, CheckName = "build" }; client.GetAllForReference(1, "ref", request); connection.Received().Get>( Arg.Is(u => u.ToString() == "repositories/1/commits/ref/check-suites"), Arg.Is>(x => x["app_id"] == "123" && x["check_name"] == "build")); } [Fact] public async Task EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var request = new CheckSuiteRequest(); Assert.Throws(() => client.GetAllForReference(null, "repo", "ref")); Assert.Throws(() => client.GetAllForReference("fake", null, "ref")); Assert.Throws(() => client.GetAllForReference("fake", "repo", null)); Assert.Throws(() => client.GetAllForReference(null, "repo", "ref", request)); Assert.Throws(() => client.GetAllForReference("fake", null, "ref", request)); Assert.Throws(() => client.GetAllForReference("fake", "repo", null, request)); Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", null)); Assert.Throws(() => client.GetAllForReference(null, "repo", "ref", request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference("fake", null, "ref", request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference("fake", "repo", null, request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", null, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference("fake", "repo", "ref", request, null)); Assert.Throws(() => client.GetAllForReference(1, null)); Assert.Throws(() => client.GetAllForReference(1, null, request)); Assert.Throws(() => client.GetAllForReference(1, "ref", null)); Assert.Throws(() => client.GetAllForReference(1, null, request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference(1, "ref", null, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference(1, "ref", request, null)); } [Fact] public async Task EnsuresNonEmptyArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var request = new CheckSuiteRequest(); Assert.Throws(() => client.GetAllForReference("", "repo", "ref")); Assert.Throws(() => client.GetAllForReference("fake", "", "ref")); Assert.Throws(() => client.GetAllForReference("fake", "repo", "")); Assert.Throws(() => client.GetAllForReference("", "repo", "ref", request)); Assert.Throws(() => client.GetAllForReference("fake", "", "ref", request)); Assert.Throws(() => client.GetAllForReference("fake", "repo", "", request)); Assert.Throws(() => client.GetAllForReference("", "repo", "ref", request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference("fake", "", "ref", request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference("fake", "repo", "", request, ApiOptions.None)); Assert.Throws(() => client.GetAllForReference(1, "")); Assert.Throws(() => client.GetAllForReference(1, "", request)); Assert.Throws(() => client.GetAllForReference(1, "", request, ApiOptions.None)); } } public class TheUpdatePreferencesMethod { [Fact] public async Task RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) }); client.UpdatePreferences("fake", "repo", preferences); gitHubClient.Check.Suite.Received().UpdatePreferences("fake", "repo", preferences); } [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) }); client.UpdatePreferences(1, preferences); gitHubClient.Check.Suite.Received().UpdatePreferences(1, preferences); } [Fact] public async Task EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) }); Assert.Throws(() => client.UpdatePreferences(null, "repo", preferences)); Assert.Throws(() => client.UpdatePreferences("fake", null, preferences)); Assert.Throws(() => client.UpdatePreferences("fake", "repo", null)); } [Fact] public async Task EnsuresNonEmptyArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var preferences = new CheckSuitePreferences(new[] { new CheckSuitePreferenceAutoTrigger(123, true) }); Assert.Throws(() => client.UpdatePreferences("", "repo", preferences)); Assert.Throws(() => client.UpdatePreferences("fake", "", preferences)); } } public class TheCreateMethod { [Fact] public async Task RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var newCheckSuite = new NewCheckSuite("123abc"); client.Create("fake", "repo", newCheckSuite); gitHubClient.Check.Suite.Received().Create("fake", "repo", newCheckSuite); } [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var newCheckSuite = new NewCheckSuite("123abc"); client.Create(1, newCheckSuite); gitHubClient.Check.Suite.Received().Create(1, newCheckSuite); } [Fact] public async Task EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var newCheckSuite = new NewCheckSuite("123abc"); Assert.Throws(() => client.Create(null, "repo", newCheckSuite)); Assert.Throws(() => client.Create("fake", null, newCheckSuite)); Assert.Throws(() => client.Create("fake", "repo", null)); Assert.Throws(() => client.Create(1, null)); } [Fact] public async Task EnsuresNonEmptyArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); var newCheckSuite = new NewCheckSuite("123abc"); Assert.Throws(() => client.Create("", "repo", newCheckSuite)); Assert.Throws(() => client.Create("fake", "", newCheckSuite)); } } public class TheRerequestMethod { [Fact] public async Task RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); client.Rerequest("fake", "repo", 1); gitHubClient.Check.Suite.Received().Rerequest("fake", "repo", 1); } [Fact] public async Task RequestsCorrectUrlWithRepositoryId() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); client.Rerequest(1, 1); gitHubClient.Check.Suite.Received().Rerequest(1, 1); } [Fact] public async Task EnsuresNonNullArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); Assert.Throws(() => client.Rerequest(null, "repo", 1)); Assert.Throws(() => client.Rerequest("fake", null, 1)); } [Fact] public async Task EnsuresNonEmptyArguments() { var gitHubClient = Substitute.For(); var client = new ObservableCheckSuitesClient(gitHubClient); Assert.Throws(() => client.Rerequest("", "repo", 1)); Assert.Throws(() => client.Rerequest("fake", "", 1)); } } } }