mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
add unit tests for reactions
This commit is contained in:
@@ -88,17 +88,6 @@ namespace Octokit.Reactive
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <returns></returns>
|
||||
IObservable<Unit> Delete(string owner, string name, int number);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a reaction for specified Commit Comment
|
||||
/// </summary>
|
||||
/// <remarks>https://developer.github.com/v3/reactions/#create-reaction-for-a-commit-comment</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <param name="reaction">The reaction to create </param>
|
||||
/// <returns></returns>
|
||||
IObservable<Reaction> CreateReaction(string owner, string name, int number, NewReaction reaction);
|
||||
IObservable<Unit> Delete(string owner, string name, int number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,8 +41,7 @@ namespace Octokit.Reactive
|
||||
/// <remarks>http://developer.github.com/v3/repos/comments/#list-reactions-for-a-commit-comment</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <param name="reaction">The reaction for </param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Reaction> GetAll(string owner, string name, int number)
|
||||
{
|
||||
|
||||
@@ -154,22 +154,5 @@ namespace Octokit.Reactive
|
||||
|
||||
return _client.Delete(owner, name, number).ToObservable();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a reaction for specified Commit Comment
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/repos/comments/#create-reaction-for-a-commit-comment</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <param name="reaction">The reaction for </param>
|
||||
/// <returns></returns>
|
||||
public IObservable<Reaction> CreateReaction(string owner, string name, int number, NewReaction reaction)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
|
||||
return _client.CreateReaction(owner, name, number, reaction).ToObservable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -377,68 +377,68 @@ public class RepositoryCommentsClientTests
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateReactionMethod : IDisposable
|
||||
{
|
||||
private readonly IGitHubClient _github;
|
||||
private readonly RepositoryContext _context;
|
||||
//public class TheCreateReactionMethod : IDisposable
|
||||
//{
|
||||
// private readonly IGitHubClient _github;
|
||||
// private readonly RepositoryContext _context;
|
||||
|
||||
public TheCreateReactionMethod()
|
||||
{
|
||||
_github = Helper.GetAuthenticatedClient();
|
||||
// public TheCreateReactionMethod()
|
||||
// {
|
||||
// _github = Helper.GetAuthenticatedClient();
|
||||
|
||||
_context = _github.CreateRepositoryContext("public-repo").Result;
|
||||
}
|
||||
// _context = _github.CreateRepositoryContext("public-repo").Result;
|
||||
// }
|
||||
|
||||
private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
|
||||
{
|
||||
var blob = new NewBlob
|
||||
{
|
||||
Content = "Hello World!",
|
||||
Encoding = EncodingType.Utf8
|
||||
};
|
||||
var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);
|
||||
// private async Task<Commit> SetupCommitForRepository(IGitHubClient client)
|
||||
// {
|
||||
// var blob = new NewBlob
|
||||
// {
|
||||
// Content = "Hello World!",
|
||||
// Encoding = EncodingType.Utf8
|
||||
// };
|
||||
// var blobResult = await client.Git.Blob.Create(_context.RepositoryOwner, _context.RepositoryName, blob);
|
||||
|
||||
var newTree = new NewTree();
|
||||
newTree.Tree.Add(new NewTreeItem
|
||||
{
|
||||
Type = TreeType.Blob,
|
||||
Mode = FileMode.File,
|
||||
Path = "README.md",
|
||||
Sha = blobResult.Sha
|
||||
});
|
||||
// var newTree = new NewTree();
|
||||
// newTree.Tree.Add(new NewTreeItem
|
||||
// {
|
||||
// Type = TreeType.Blob,
|
||||
// Mode = FileMode.File,
|
||||
// Path = "README.md",
|
||||
// Sha = blobResult.Sha
|
||||
// });
|
||||
|
||||
var treeResult = await client.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
|
||||
// var treeResult = await client.Git.Tree.Create(_context.RepositoryOwner, _context.RepositoryName, newTree);
|
||||
|
||||
var newCommit = new NewCommit("test-commit", treeResult.Sha);
|
||||
// var newCommit = new NewCommit("test-commit", treeResult.Sha);
|
||||
|
||||
return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
|
||||
}
|
||||
// return await client.Git.Commit.Create(_context.RepositoryOwner, _context.RepositoryName, newCommit);
|
||||
// }
|
||||
|
||||
[IntegrationTest]
|
||||
public async Task CanCreateReaction()
|
||||
{
|
||||
var commit = await SetupCommitForRepository(_github);
|
||||
// [IntegrationTest]
|
||||
// public async Task CanCreateReaction()
|
||||
// {
|
||||
// var commit = await SetupCommitForRepository(_github);
|
||||
|
||||
var comment = new NewCommitComment("test");
|
||||
// var comment = new NewCommitComment("test");
|
||||
|
||||
var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
|
||||
commit.Sha, comment);
|
||||
// var result = await _github.Repository.Comment.Create(_context.RepositoryOwner, _context.RepositoryName,
|
||||
// commit.Sha, comment);
|
||||
|
||||
Assert.NotNull(result);
|
||||
// Assert.NotNull(result);
|
||||
|
||||
var newReaction = new NewReaction(ReactionType.Confused);
|
||||
var reaction = await _github.Repository.Comment.CreateReaction(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);
|
||||
// var newReaction = new NewReaction(ReactionType.Confused);
|
||||
// var reaction = await _github.Repository.Comment.CreateReaction(_context.RepositoryOwner, _context.RepositoryName, result.Id, newReaction);
|
||||
|
||||
Assert.IsType<Reaction>(reaction);
|
||||
// Assert.IsType<Reaction>(reaction);
|
||||
|
||||
Assert.Equal(ReactionType.Confused, reaction.Content);
|
||||
// Assert.Equal(ReactionType.Confused, reaction.Content);
|
||||
|
||||
Assert.Equal(result.User.Id, reaction.UserId);
|
||||
}
|
||||
// Assert.Equal(result.User.Id, reaction.UserId);
|
||||
// }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_context.Dispose();
|
||||
}
|
||||
}
|
||||
// public void Dispose()
|
||||
// {
|
||||
// _context.Dispose();
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
using NSubstitute;
|
||||
using Octokit;
|
||||
using Octokit.Tests;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
public class ReactionsClientTests
|
||||
{
|
||||
public class CommitComments
|
||||
{
|
||||
public class TheGetAllMethod
|
||||
{
|
||||
[Fact]
|
||||
public async Task RequestsCorrectUrl()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
client.CommitComments.GetAll("fake", "repo", 42);
|
||||
|
||||
connection.Received().GetAll<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), "application/vnd.github.squirrel-girl-preview");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComments.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComments.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CommitComments.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CommitComments.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
NewReaction newReaction = new NewReaction(ReactionType.Heart);
|
||||
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new ReactionsClient(connection);
|
||||
|
||||
client.CommitComments.CreateReaction("fake", "repo", 1, newReaction);
|
||||
|
||||
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,34 +240,6 @@ public class RepositoryCommentsClientTests
|
||||
}
|
||||
}
|
||||
|
||||
public class TheReactionMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
NewReaction newReaction = new NewReaction(ReactionType.Heart);
|
||||
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryCommentsClient(connection);
|
||||
|
||||
client.CreateReaction("fake", "repo", 1, newReaction);
|
||||
|
||||
connection.Received().Post<Reaction>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/comments/1/reactions"), Arg.Any<object>(), "application/vnd.github.squirrel-girl-preview");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task EnsuresArgumentsNotNull()
|
||||
{
|
||||
var connection = Substitute.For<IApiConnection>();
|
||||
var client = new RepositoryCommentsClient(connection);
|
||||
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentNullException>(() => client.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
await Assert.ThrowsAsync<ArgumentException>(() => client.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCtor
|
||||
{
|
||||
[Fact]
|
||||
|
||||
@@ -180,6 +180,10 @@
|
||||
<None Include="packages.Octokit.Tests-NetCore45.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Octokit\Octokit-Mono.csproj">
|
||||
<Project>{49EF16A2-5ED1-480F-80A1-D1D05D6C1BE4}</Project>
|
||||
<Name>Octokit-Mono</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Octokit\Octokit-NetCore45.csproj">
|
||||
<Project>{c8bc13b6-3fa3-4716-827d-e7706f976fe1}</Project>
|
||||
<Name>Octokit-NetCore45</Name>
|
||||
|
||||
@@ -93,6 +93,7 @@
|
||||
<Compile Include="Clients\Enterprise\EnterpriseSearchIndexingClientTests.cs" />
|
||||
<Compile Include="Clients\MergingClientTests.cs" />
|
||||
<Compile Include="Clients\OauthClientTests.cs" />
|
||||
<Compile Include="Clients\ReactionsClientTests.cs" />
|
||||
<Compile Include="Clients\RepositoryCommentsClientTests.cs" />
|
||||
<Compile Include="Clients\DeploymentsClientTests.cs" />
|
||||
<Compile Include="Clients\DeploymentStatusClientTests.cs" />
|
||||
@@ -208,6 +209,7 @@
|
||||
<Compile Include="Reactive\ObservableBlobClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableCommitsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableIssuesLabelsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableReactionsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableRepoCollaboratorsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableDeploymentsClientTests.cs" />
|
||||
<Compile Include="Reactive\ObservableDeploymentStatusClientTests.cs" />
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using NSubstitute;
|
||||
using Octokit.Reactive;
|
||||
using System;
|
||||
using Xunit;
|
||||
|
||||
namespace Octokit.Tests.Reactive
|
||||
{
|
||||
public class ObservableReactionsClientTests
|
||||
{
|
||||
public class CommitComments
|
||||
{
|
||||
public class TheGetMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(githubClient);
|
||||
|
||||
client.CommitComments.GetAll("fake", "repo", 42);
|
||||
githubClient.Received().Reaction.CommitComments.GetAll("fake", "repo", 42);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresArgumentsNotNull()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(githubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComments.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComments.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComments.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComments.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
|
||||
public class TheCreateMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(githubClient);
|
||||
var newReaction = new NewReaction(ReactionType.Confused);
|
||||
|
||||
client.CommitComments.CreateReaction("fake", "repo", 1, newReaction);
|
||||
githubClient.Received().Reaction.CommitComments.CreateReaction("fake", "repo", 1, newReaction);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresArgumentsNotNull()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableReactionsClient(githubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComments.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComments.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => client.CommitComments.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CommitComments.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,30 +133,5 @@ namespace Octokit.Tests.Reactive
|
||||
Assert.Throws<ArgumentException>(() => client.GetAllForCommit("", "name", "sha1", Args.ApiOptions));
|
||||
}
|
||||
}
|
||||
public class TheReactionMethod
|
||||
{
|
||||
[Fact]
|
||||
public void RequestsCorrectUrl()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryCommentsClient(githubClient);
|
||||
var newReaction = new NewReaction(ReactionType.Confused);
|
||||
|
||||
client.CreateReaction("fake", "repo", 1, newReaction);
|
||||
githubClient.Received().Repository.Comment.CreateReaction("fake", "repo", 1, newReaction);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void EnsuresArgumentsNotNull()
|
||||
{
|
||||
var githubClient = Substitute.For<IGitHubClient>();
|
||||
var client = new ObservableRepositoryCommentsClient(githubClient);
|
||||
|
||||
Assert.Throws<ArgumentNullException>(() => client.CreateReaction(null, "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CreateReaction("", "name", 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentNullException>(() => client.CreateReaction("owner", null, 1, new NewReaction(ReactionType.Heart)));
|
||||
Assert.Throws<ArgumentException>(() => client.CreateReaction("owner", "", 1, new NewReaction(ReactionType.Heart)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,7 @@ namespace Octokit
|
||||
/// <remarks>http://developer.github.com/v3/repos/comments/#list-reactions-for-a-commit-comment</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <param name="reaction">The reaction for </param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <returns></returns>
|
||||
public Task<IReadOnlyList<Reaction>> GetAll(string owner, string name, int number)
|
||||
{
|
||||
|
||||
@@ -94,17 +94,6 @@ namespace Octokit
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <returns></returns>
|
||||
Task Delete(string owner, string name, int number);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a reaction for specified Commit Comment
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/repos/comments/#create-reaction-for-a-commit-comment</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <param name="reaction">The reaction for </param>
|
||||
/// <returns></returns>
|
||||
Task<Reaction> CreateReaction(string owner, string name, int number, NewReaction reaction);
|
||||
Task Delete(string owner, string name, int number);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,23 +156,5 @@ namespace Octokit
|
||||
|
||||
return ApiConnection.Delete(ApiUrls.CommitComment(owner, name, number));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a reaction for specified Commit Comment
|
||||
/// </summary>
|
||||
/// <remarks>http://developer.github.com/v3/repos/comments/#create-reaction-for-a-commit-comment</remarks>
|
||||
/// <param name="owner">The owner of the repository</param>
|
||||
/// <param name="name">The name of the repository</param>
|
||||
/// <param name="number">The comment id</param>
|
||||
/// <param name="reaction">The reaction for </param>
|
||||
/// <returns></returns>
|
||||
public Task<Reaction> CreateReaction(string owner, string name, int number, NewReaction reaction)
|
||||
{
|
||||
Ensure.ArgumentNotNullOrEmptyString(owner, "owner");
|
||||
Ensure.ArgumentNotNullOrEmptyString(name, "name");
|
||||
Ensure.ArgumentNotNull(reaction, "reaction");
|
||||
|
||||
return ApiConnection.Post<Reaction>(ApiUrls.CommitCommentReaction(owner, name, number), reaction, AcceptHeaders.ReactionsPreview);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user