using System; using System.Collections.Generic; using NSubstitute; using Octokit.Reactive; using Xunit; namespace Octokit.Tests.Reactive { public class ObservableOrganizationHooksClientTests { public class TheCtor { [Fact] public void EnsuresNonNullArguments() { Assert.Throws( () => new ObservableOrganizationHooksClient(null)); } } public class TheGetAllMethod { [Fact] public void RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); client.GetAll("org"); gitHubClient.Received().Organization.Hook.GetAll("org"); } [Fact] public void RequestsCorrectUrlWithApiOptions() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); var options = new ApiOptions { PageCount = 1, PageSize = 1, StartPage = 1 }; client.GetAll("org", options); gitHubClient.Received(1).Organization.Hook.GetAll("org", options); } [Fact] public void EnsuresNonNullArguments() { var client = new ObservableOrganizationHooksClient(Substitute.For()); Assert.Throws(() => client.GetAll(null, ApiOptions.None)); Assert.Throws(() => client.GetAll("org", null)); Assert.Throws(() => client.GetAll("")); Assert.Throws(() => client.GetAll("", null)); } } public class TheGetMethod { [Fact] public void RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); client.Get("org", 12345678); gitHubClient.Received().Organization.Hook.Get("org", 12345678); } [Fact] public void EnsuresNonNullArguments() { var client = new ObservableOrganizationHooksClient(Substitute.For()); Assert.Throws(() => client.Get(null, 123)); Assert.Throws(() => client.Get("", 123)); } } public class TheCreateMethod { [Fact] public void RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); var hook = new NewOrganizationHook("name", new Dictionary { { "config", "" } }); client.Create("org", hook); gitHubClient.Received().Organization.Hook.Create("org", hook); } [Fact] public void EnsuresNonNullArguments() { var client = new ObservableOrganizationHooksClient(Substitute.For()); var config = new Dictionary { { "config", "" } }; Assert.Throws(() => client.Create(null, new NewOrganizationHook("name", config))); Assert.Throws(() => client.Create("org", null)); Assert.Throws(() => client.Create("", new NewOrganizationHook("name", config))); } } public class TheEditMethod { [Fact] public void RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); var hook = new EditOrganizationHook(); client.Edit("org", 12345678, hook); gitHubClient.Received().Organization.Hook.Edit("org", 12345678, hook); } [Fact] public void EnsuresNonNullArguments() { var client = new ObservableOrganizationHooksClient(Substitute.For()); Assert.Throws(() => client.Edit(null, 12345678, new EditOrganizationHook())); Assert.Throws(() => client.Edit("org", 12345678, null)); Assert.Throws(() => client.Edit("", 12345678, new EditOrganizationHook())); } } public class ThePingMethod { [Fact] public void RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); client.Ping("org", 12345678); gitHubClient.Received().Organization.Hook.Ping("org", 12345678); } [Fact] public void EnsuresNonNullArguments() { var client = new ObservableOrganizationHooksClient(Substitute.For()); Assert.Throws(() => client.Ping(null, 12345678)); Assert.Throws(() => client.Ping("", 12345678)); } } public class TheDeleteMethod { [Fact] public void RequestsCorrectUrl() { var gitHubClient = Substitute.For(); var client = new ObservableOrganizationHooksClient(gitHubClient); client.Delete("org", 12345678); gitHubClient.Received().Organization.Hook.Delete("org", 12345678); } [Fact] public void EnsuresNonNullArguments() { var client = new ObservableOrganizationHooksClient(Substitute.For()); Assert.Throws(() => client.Delete(null, 12345678)); Assert.Throws(() => client.Delete("", 12345678)); } } } }