using System; using System.Security.Policy; using System.Threading.Tasks; using NSubstitute; using Octokit.Tests.Helpers; using Xunit; namespace Octokit.Tests.Clients { public class CommitStatusClientTests { public class TheGetMethod { [Fact] public void RequestsCorrectUrl() { var connection = Substitute.For(); var client = new CommitStatusClient(connection); client.GetAll("fake", "repo", "sha"); connection.Received() .GetAll(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/statuses")); } [Fact] public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For()); await AssertEx.Throws(async () => await client.GetAll("", "name", "sha")); await AssertEx.Throws(async () => await client.GetAll("owner", "", "sha")); await AssertEx.Throws(async () => await client.GetAll("owner", "name", "")); await AssertEx.Throws(async () => await client.GetAll(null, "name", "sha")); await AssertEx.Throws(async () => await client.GetAll("owner", null, "sha")); await AssertEx.Throws(async () => await client.GetAll("owner", "name", null)); } } public class TheGetCombinedMethod { [Fact] public void RequestsCorrectUrl() { var connection = Substitute.For(); var client = new CommitStatusClient(connection); client.GetCombined("fake", "repo", "sha"); connection.Received() .Get(Arg.Is(u => u.ToString() == "repos/fake/repo/commits/sha/status"), null); } [Fact] public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For()); await AssertEx.Throws(async () => await client.GetCombined("", "name", "sha")); await AssertEx.Throws(async () => await client.GetCombined("owner", "", "sha")); await AssertEx.Throws(async () => await client.GetCombined("owner", "name", "")); await AssertEx.Throws(async () => await client.GetCombined(null, "name", "sha")); await AssertEx.Throws(async () => await client.GetCombined("owner", null, "sha")); await AssertEx.Throws(async () => await client.GetCombined("owner", "name", null)); } } public class TheCreateMethodForUser { [Fact] public void PostsToTheCorrectUrl() { var connection = Substitute.For(); var client = new CommitStatusClient(connection); client.Create("owner", "repo", "sha", new NewCommitStatus { State = CommitState.Success }); connection.Received().Post(Arg.Is(u => u.ToString() == "repos/owner/repo/statuses/sha"), Arg.Is(s => s.State == CommitState.Success)); } [Fact] public async Task EnsuresNonNullArguments() { var client = new CommitStatusClient(Substitute.For()); await AssertEx.Throws(async () => await client.Create("", "name", "sha", new NewCommitStatus())); await AssertEx.Throws(async () => await client.Create("owner", "", "sha", new NewCommitStatus())); await AssertEx.Throws(async () => await client.Create("owner", "name", "", new NewCommitStatus())); await AssertEx.Throws(async () => await client.Create(null, "name", "sha", new NewCommitStatus())); await AssertEx.Throws(async () => await client.Create("owner", null, "sha", new NewCommitStatus())); await AssertEx.Throws(async () => await client.Create("owner", "name", null, new NewCommitStatus())); await AssertEx.Throws(async () => await client.Create("owner", "name", "sha", null)); } } public class TheConstructor { [Fact] public void EnsuresNonNullArguments() { Assert.Throws(() => new CommitStatusClient(null)); } } } }