diff --git a/Octokit.Tests.Integration/Clients/GistsClientTests.cs b/Octokit.Tests.Integration/Clients/GistsClientTests.cs index 1265ad10..344431ff 100644 --- a/Octokit.Tests.Integration/Clients/GistsClientTests.cs +++ b/Octokit.Tests.Integration/Clients/GistsClientTests.cs @@ -5,6 +5,8 @@ using Octokit.Tests.Integration; using Xunit; using System.Collections.Generic; using System.Collections.ObjectModel; +using System; +using System.Linq; public class GistsClientTests { @@ -132,5 +134,4 @@ public class GistsClientTests await _fixture.Delete(createdGist.Id); } -} } \ No newline at end of file diff --git a/Octokit.Tests/Clients/GistsClientTests.cs b/Octokit.Tests/Clients/GistsClientTests.cs index 48a1bd6c..3a3d8769 100644 --- a/Octokit.Tests/Clients/GistsClientTests.cs +++ b/Octokit.Tests/Clients/GistsClientTests.cs @@ -1,11 +1,14 @@ -using System; -using NSubstitute; +using NSubstitute; using Octokit; -using Xunit; -using System.Collections.ObjectModel; -using System.Collections.Generic; -using System.Threading.Tasks; +using Octokit.Internal; using Octokit.Tests.Helpers; +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Net; +using System.Threading.Tasks; +using Xunit; +using Xunit.Extensions; public class GistsClientTests { @@ -33,7 +36,7 @@ public class GistsClientTests client.GetAll(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists"), null); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists")); } [Fact] @@ -56,8 +59,7 @@ public class GistsClientTests client.GetAllPublic(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public"), - Arg.Is>(x => x.ContainsKey("since"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/public")); } [Fact] @@ -81,8 +83,7 @@ public class GistsClientTests client.GetAllStarred(); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred"), - Arg.Is>(x => x.ContainsKey("since"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "gists/starred")); } [Fact] @@ -106,8 +107,7 @@ public class GistsClientTests client.GetAllForUser("octokit"); - connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists"), - Arg.Is>(x => x.ContainsKey("since"))); + connection.Received().GetAll(Arg.Is(u => u.ToString() == "users/octokit/gists")); } [Fact] @@ -178,7 +178,7 @@ public class GistsClientTests client.Star("1"); - connection.Received().Get(Arg.Is(u => u.ToString() == "gists/1/star"), null); + connection.Received().Put(Arg.Is(u => u.ToString() == "gists/1/star")); } [Fact] @@ -189,18 +189,42 @@ public class GistsClientTests client.Unstar("1"); - connection.Received().Get(Arg.Is(u => u.ToString() == "gists/1/star"), null); + connection.Received().Delete(Arg.Is(u => u.ToString() == "gists/1/star")); + } + + [Theory] + [InlineData(HttpStatusCode.NoContent, true)] + [InlineData(HttpStatusCode.NotFound, false)] + public async Task RequestsCorrectValueForStatusCode(HttpStatusCode status, bool expected) + { + var response = Task.Factory.StartNew>(() => + new ApiResponse { StatusCode = status }); + var connection = Substitute.For(); + connection.GetAsync(Arg.Is(u => u.ToString() == "gists/1/star"), + null, null).Returns(response); + var apiConnection = Substitute.For(); + apiConnection.Connection.Returns(connection); + var client = new GistsClient(apiConnection); + + var result = await client.IsStarred("1"); + + Assert.Equal(expected, result); } [Fact] - public void RequestsCorrectCheckIfStarredUrl() + public async Task ThrowsExceptionForInvalidStatusCode() { - var connection = Substitute.For(); - var client = new GistsClient(connection); + var response = Task.Factory.StartNew>(() => + new ApiResponse { StatusCode = HttpStatusCode.Conflict }); + var connection = Substitute.For(); + connection.GetAsync(Arg.Is(u => u.ToString() == "gists/1/star"), + null, null).Returns(response); + var apiConnection = Substitute.For(); + apiConnection.Connection.Returns(connection); - client.IsStarred("1"); + var client = new GistsClient(apiConnection); - connection.Received().Get(Arg.Is(u => u.ToString() == "gists/1/star"), null); + AssertEx.Throws(async () => await client.IsStarred("1")); } } @@ -214,8 +238,8 @@ public class GistsClientTests client.Fork("1"); - connection.Received().Post(Arg.Is(u => u.ToString() == "gists/1/fork"), - Arg.Is(o => o == null)); + connection.Received().Post(Arg.Is(u => u.ToString() == "gists/1/forks"), + Arg.Any()); } } @@ -239,7 +263,7 @@ public class GistsClientTests client.Edit("1", updateGist); - connection.Received().Post(Arg.Is(u => u.ToString() == "gists/1"), Arg.Any()); + connection.Received().Patch(Arg.Is(u => u.ToString() == "gists/1"), Arg.Any()); } } diff --git a/Octokit/Clients/GistsClient.cs b/Octokit/Clients/GistsClient.cs index ae816607..e40bfb3c 100644 --- a/Octokit/Clients/GistsClient.cs +++ b/Octokit/Clients/GistsClient.cs @@ -99,7 +99,6 @@ namespace Octokit /// /// http://developer.github.com/v3/gists/#list-gists /// - /// Only gists updated at or after this time are returned public Task> GetAll() { return ApiConnection.GetAll(ApiUrls.Gist()); @@ -201,7 +200,7 @@ namespace Octokit /// Edits a gist /// /// - /// http://developer.github.com/v3/gists/#edit-a-gist + /// http://developer.github.com/v3/gists/#delete-a-gist /// /// The id of the gist /// The update to the gist diff --git a/Octokit/Octokit-MonoAndroid.csproj b/Octokit/Octokit-MonoAndroid.csproj index 9c36915d..30fc8b52 100644 --- a/Octokit/Octokit-MonoAndroid.csproj +++ b/Octokit/Octokit-MonoAndroid.csproj @@ -309,6 +309,8 @@ + + \ No newline at end of file diff --git a/Octokit/Octokit-Monotouch.csproj b/Octokit/Octokit-Monotouch.csproj index 1fb714a2..e75a3941 100644 --- a/Octokit/Octokit-Monotouch.csproj +++ b/Octokit/Octokit-Monotouch.csproj @@ -248,7 +248,6 @@ -<<<<<<< HEAD @@ -304,7 +303,8 @@ - + +