Files
Ryan Gribble 3c818934b8 Release v0.24 - A Sight For Sore Eyes (#1539)
* Add release notes and bump version to 0.24

* run "build FormatCode" to fix up whitespace/formatting issues

* Fix failing Ssh key tests due to "validation exception".  This key must be in use on github (under another user, most likely from these tests failing).  Changed to a new SSH key and tweaked tests to reduce chance of a key being created and not destroyed

* Assignee and Assignees cant both be specified on NewIssue.  We missed this one in the PR.  Marked Assignee as [Obsolete] and fixed tests to use Assignees

* Fix a couple of Reactions tests that were calling the wrong client methods

* Fix timeline tests - looks like the response class has changed shape a bit, it now has an Issue object in the payload and Id field isnt present (leaving Id field there in case other timeline events do use it)

* Fix some following tests that require the test user to follow more than 1 other user

* Unskip these Event tests now because apparently they work!

* add breaking changes notes

* Update ApiErrorMessageSafe to return null for empty and whitespace strings (#1540)

* return null if ApiError.Message is empty or whitespace

* Uncomment test, which now passes

* update release notes to include PR1540

* Add "Bot" AccountType, was causing a deserialization exception when running the integration test "SearchForExcludedLanguage" (#1541)

* Update to include PR1541

* add bullets to make release notes easier to read

* markup additional code mentions in notes

* Fix grammar

fields => field
2017-01-17 18:56:55 +10:00

139 lines
4.8 KiB
C#

using System;
using System.Threading.Tasks;
using NSubstitute;
using Xunit;
namespace Octokit.Tests.Clients
{
public class GistCommentsClientTests
{
public class TheCtor
{
[Fact]
public void EnsuresNonNullArguments()
{
Assert.Throws<ArgumentNullException>(() => new GistCommentsClient(null));
}
}
public class TheGetMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
await client.Get("24", 1337);
connection.Received().Get<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
}
}
public class TheGetAllForGistMethod
{
[Fact]
public async Task RequestsCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
await client.GetAllForGist("24");
connection.Received().GetAll<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), Args.ApiOptions);
}
[Fact]
public async Task RequestsCorrectUrlWithApiOptions()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
var options = new ApiOptions
{
PageSize = 1,
PageCount = 1,
StartPage = 1
};
await client.GetAllForGist("24", options);
connection.Received().GetAll<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), options);
}
[Fact]
public async Task EnsuresNonNullArguments()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForGist(null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForGist(""));
await Assert.ThrowsAsync<ArgumentNullException>(() => client.GetAllForGist("24", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.GetAllForGist("", ApiOptions.None));
}
}
public class TheCreateMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new GistCommentsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Create("24", null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Create("24", ""));
}
[Fact]
public async Task PostsToCorrectUrl()
{
var comment = "This is a comment.";
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
await client.Create("24", comment);
connection.Received().Post<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments"), Arg.Is<BodyWrapper>(x => x.Body == comment));
}
}
public class TheUpdateMethod
{
[Fact]
public async Task EnsuresNonNullArguments()
{
var client = new GistCommentsClient(Substitute.For<IApiConnection>());
await Assert.ThrowsAsync<ArgumentNullException>(() => client.Update("24", 1337, null));
await Assert.ThrowsAsync<ArgumentException>(() => client.Update("24", 1337, ""));
}
[Fact]
public async Task PostsToCorrectUrl()
{
var comment = "This is a comment.";
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
await client.Update("24", 1337, comment);
connection.Received().Patch<GistComment>(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"), Arg.Is<BodyWrapper>(x => x.Body == comment));
}
}
public class TheDeleteMethod
{
[Fact]
public async Task PostsToCorrectUrl()
{
var connection = Substitute.For<IApiConnection>();
var client = new GistCommentsClient(connection);
await client.Delete("24", 1337);
connection.Received().Delete(Arg.Is<Uri>(u => u.ToString() == "gists/24/comments/1337"));
}
}
}
}