From 4c533858d3f0632c5ed376f9072a0ad2f89c28e9 Mon Sep 17 00:00:00 2001 From: Kristian Hellang Date: Sun, 1 Dec 2013 22:12:19 +0100 Subject: [PATCH] Added failing tests --- .../Clients/GistCommentsClientTests.cs | 113 ++++++++++++++++++ Octokit.Tests/Octokit.Tests.csproj | 1 + 2 files changed, 114 insertions(+) create mode 100644 Octokit.Tests/Clients/GistCommentsClientTests.cs diff --git a/Octokit.Tests/Clients/GistCommentsClientTests.cs b/Octokit.Tests/Clients/GistCommentsClientTests.cs new file mode 100644 index 00000000..0407e428 --- /dev/null +++ b/Octokit.Tests/Clients/GistCommentsClientTests.cs @@ -0,0 +1,113 @@ +using System; +using System.Threading.Tasks; + +using NSubstitute; + +using Octokit.Tests.Helpers; + +using Xunit; + +namespace Octokit.Tests.Clients +{ + public class GistCommentsClientTests + { + public class TheCtor + { + [Fact] + public void EnsuresArgument() + { + Assert.Throws(() => new GistCommentsClient(null)); + } + } + + public class TheGetMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Get(24, 1337); + + connection.Received().Get(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), null); + } + } + + public class TheGetForGistMethod + { + [Fact] + public async Task RequestsCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.GetForGist(24); + + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/24/comments"), null); + } + } + + public class TheCreateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Create(24, null)); + await AssertEx.Throws(async () => await client.Create(24, "")); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Create(24, comment); + + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/24/comments"), comment); + } + } + + public class TheUpdateMethod + { + [Fact] + public async Task EnsuresNonNullArguments() + { + var client = new GistCommentsClient(Substitute.For()); + + await AssertEx.Throws(async () => await client.Update(24, 1337, null)); + await AssertEx.Throws(async () => await client.Update(24, 1337, "")); + } + + [Fact] + public async Task PostsToCorrectUrl() + { + var comment = "This is a comment."; + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Update(24, 1337, comment); + + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/24/comments/1337"), comment); + } + } + + public class TheDeleteMethod + { + [Fact] + public async Task PostsToCorrectUrl() + { + var connection = Substitute.For(); + var client = new GistCommentsClient(connection); + + await client.Delete(24, 1337); + + connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/24/comments/1337")); + } + } + } +} \ No newline at end of file diff --git a/Octokit.Tests/Octokit.Tests.csproj b/Octokit.Tests/Octokit.Tests.csproj index 6a7e72bc..ab7436b8 100644 --- a/Octokit.Tests/Octokit.Tests.csproj +++ b/Octokit.Tests/Octokit.Tests.csproj @@ -62,6 +62,7 @@ +