diff --git a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs index 140bb5a7..6c33ae3d 100644 --- a/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs +++ b/Octokit.Reactive/Clients/ObservablePullRequestReviewCommentsClient.cs @@ -93,9 +93,6 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); - Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); - Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); return _client.Create(owner, name, number, comment).ToObservable(); } @@ -114,7 +111,6 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); return _client.CreateReply(owner, name, number, comment).ToObservable(); } @@ -133,7 +129,6 @@ namespace Octokit.Reactive Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); return _client.Edit(owner, name, number, comment).ToObservable(); } diff --git a/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs index 9651d29a..e1c28f97 100644 --- a/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests.Integration/PullRequestReviewCommentsClientTests.cs @@ -98,13 +98,7 @@ public class PullRequestReviewCommentsClientTests : IDisposable [IntegrationTest(Skip = "Requires Blob, Tree, Fork and Pull Request Api implementation")] public async Task CanCreateAndRetrieveReviewComment() { - var pullRequestReviewComment = new PullRequestReviewCommentCreate - { - Body = "A review comment message", - CommitId = _pullRequestCommitId, - Path = _path, - Position = 1, - }; + var pullRequestReviewComment = new PullRequestReviewCommentCreate("A review comment message", _pullRequestCommitId, _path, 1); var createdComment = await _client.Create(_ownerName, _repoName, _pullRequestNumber, pullRequestReviewComment); diff --git a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs index 1788a95b..fbdb9464 100644 --- a/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Clients/PullRequestReviewCommentsClientTests.cs @@ -8,6 +8,79 @@ using Xunit; public class PullRequestReviewCommentsClientTests { + public class TheModelConstructors + { + [Fact] + public void PullRequestReviewCommentCreateEnsuresArgumentsValue() + { + string body = "body"; + string commitId = "sha"; + string path = "path"; + int position = 1; + + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); + + Assert.Equal(body, comment.Body); + Assert.Equal(commitId, comment.CommitId); + Assert.Equal(path, comment.Path); + Assert.Equal(position, comment.Position); + } + + [Fact] + public void PullRequestReviewCommentCreateEnsuresArgumentsNotNull() + { + string body = "body"; + string commitId = "sha"; + string path = "path"; + int position = 1; + + Assert.Throws(() => new PullRequestReviewCommentCreate(null, commitId, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate("", commitId, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, null, path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, "", path, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, null, position)); + Assert.Throws(() => new PullRequestReviewCommentCreate(body, commitId, "", position)); + } + + [Fact] + public void PullRequestReviewCommentEditEnsuresArgumentsValue() + { + string body = "body"; + + var comment = new PullRequestReviewCommentEdit(body); + + Assert.Equal(body, comment.Body); + } + + [Fact] + public void PullRequestReviewCommentEditEnsuresArgumentsNotNull() + { + Assert.Throws(() => new PullRequestReviewCommentEdit(null)); + Assert.Throws(() => new PullRequestReviewCommentEdit("")); + } + + [Fact] + public void PullRequestReviewCommentReplyCreateEnsuresArgumentsValue() + { + string body = "body"; + int inReplyTo = 1; + + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); + + Assert.Equal(body, comment.Body); + Assert.Equal(inReplyTo, comment.InReplyTo); + } + + [Fact] + public void PullRequestReviewCommentReplyCreateEnsuresArgumentsNotNull() + { + int inReplyTo = 1; + + Assert.Throws(() => new PullRequestReviewCommentReplyCreate(null, inReplyTo)); + Assert.Throws(() => new PullRequestReviewCommentReplyCreate("", inReplyTo)); + } + } + public class TheGetForPullRequestMethod { [Fact] @@ -131,13 +204,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentCreate - { - Body = "Comment content", - CommitId = "qe3dsdsf6", - Path = "file.css", - Position = 7, - }; + var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); client.Create("fakeOwner", "fakeRepoName", 13, comment); @@ -156,37 +223,13 @@ public class PullRequestReviewCommentsClientTests string path = "file.css"; int position = 7; - var comment = new PullRequestReviewCommentCreate - { - Body = body, - CommitId = commitId, - Path = path, - Position = position, - }; + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); await AssertEx.Throws(async () => await client.Create(null, "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Create("", "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Create("fakeOwner", null, 1, comment)); await AssertEx.Throws(async () => await client.Create("fakeOwner", "", 1, comment)); await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = body; - - comment.CommitId = null; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.CommitId = ""; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.CommitId = commitId; - - comment.Path = null; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Path = ""; - await AssertEx.Throws(async () => await client.Create("fakeOwner", "fakeRepoName", 1, comment)); - comment.Path = path; } } @@ -198,11 +241,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentReplyCreate - { - Body = "Comment content", - InReplyTo = 5 - }; + var comment = new PullRequestReviewCommentReplyCreate("Comment content", 5); client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); @@ -219,23 +258,13 @@ public class PullRequestReviewCommentsClientTests string body = "Comment content"; int inReplyTo = 7; - var comment = new PullRequestReviewCommentReplyCreate - { - Body = body, - InReplyTo = inReplyTo, - }; + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); await AssertEx.Throws(async () => await client.CreateReply(null, "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("", "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", null, 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.CreateReply("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = body; } } @@ -247,10 +276,7 @@ public class PullRequestReviewCommentsClientTests var connection = Substitute.For(); var client = new PullRequestReviewCommentsClient(connection); - var comment = new PullRequestReviewCommentEdit - { - Body = "New comment content", - }; + var comment = new PullRequestReviewCommentEdit("New comment content"); client.Edit("fakeOwner", "fakeRepoName", 13, comment); @@ -265,22 +291,13 @@ public class PullRequestReviewCommentsClientTests var body = "New comment content"; - var comment = new PullRequestReviewCommentEdit - { - Body = body, - }; + var comment = new PullRequestReviewCommentEdit(body); await AssertEx.Throws(async () => await client.Edit(null, "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Edit("", "fakeRepoName", 1, comment)); await AssertEx.Throws(async () => await client.Edit("fakeOwner", null, 1, comment)); await AssertEx.Throws(async () => await client.Edit("fakeOwner", "", 1, comment)); await AssertEx.Throws(async () => await client.Edit("fakeOwner", null, 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Edit("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Edit("fakeOwner", "fakeRepoName", 1, comment)); - comment.Body = body; } } diff --git a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs index 6d1d3e98..dd47067e 100644 --- a/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs +++ b/Octokit.Tests/Reactive/ObservablePullRequestReviewCommentsClientTests.cs @@ -276,13 +276,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); - var comment = new PullRequestReviewCommentCreate - { - Body = "Comment content", - CommitId = "qe3dsdsf6", - Path = "file.css", - Position = 7, - }; + var comment = new PullRequestReviewCommentCreate("Comment content", "qe3dsdsf6", "file.css", 7); client.Create("fakeOwner", "fakeRepoName", 13, comment); @@ -300,37 +294,13 @@ namespace Octokit.Tests.Reactive string path = "file.css"; int position = 7; - var comment = new PullRequestReviewCommentCreate - { - Body = body, - CommitId = commitId, - Path = path, - Position = position, - }; + var comment = new PullRequestReviewCommentCreate(body, commitId, path, position); await AssertEx.Throws(async () => await client.Create(null, "name", 1, comment)); await AssertEx.Throws(async () => await client.Create("", "name", 1, comment)); await AssertEx.Throws(async () => await client.Create("owner", null, 1, comment)); await AssertEx.Throws(async () => await client.Create("owner", "", 1, comment)); await AssertEx.Throws(async () => await client.Create("owner", "name", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Body = body; - - comment.CommitId = null; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.CommitId = ""; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.CommitId = commitId; - - comment.Path = null; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Path = ""; - await AssertEx.Throws(async () => await client.Create("owner", "name", 1, comment)); - comment.Path = path; } } @@ -342,11 +312,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); - var comment = new PullRequestReviewCommentReplyCreate - { - Body = "Comment content", - InReplyTo = 9, - }; + var comment = new PullRequestReviewCommentReplyCreate("Comment content", 9); client.CreateReply("fakeOwner", "fakeRepoName", 13, comment); @@ -362,23 +328,13 @@ namespace Octokit.Tests.Reactive string body = "Comment content"; int inReplyTo = 7; - var comment = new PullRequestReviewCommentReplyCreate - { - Body = body, - InReplyTo = inReplyTo, - }; + var comment = new PullRequestReviewCommentReplyCreate(body, inReplyTo); await AssertEx.Throws(async () => await client.CreateReply(null, "name", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("", "name", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("owner", null, 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("owner", "", 1, comment)); await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.CreateReply("owner", "name", 1, comment)); - comment.Body = body; } } @@ -390,10 +346,7 @@ namespace Octokit.Tests.Reactive var gitHubClient = Substitute.For(); var client = new ObservablePullRequestReviewCommentsClient(gitHubClient); - var comment = new PullRequestReviewCommentEdit - { - Body = "New comment content", - }; + var comment = new PullRequestReviewCommentEdit("New comment content"); client.Edit("fakeOwner", "fakeRepoName", 13, comment); @@ -408,22 +361,13 @@ namespace Octokit.Tests.Reactive var body = "New comment content"; - var comment = new PullRequestReviewCommentEdit - { - Body = body, - }; + var comment = new PullRequestReviewCommentEdit(body); await AssertEx.Throws(async () => await client.Edit(null, "name", 1, comment)); await AssertEx.Throws(async () => await client.Edit("", "name", 1, comment)); await AssertEx.Throws(async () => await client.Edit("owner", null, 1, comment)); await AssertEx.Throws(async () => await client.Edit("owner", "", 1, comment)); await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, null)); - - comment.Body = null; - await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, comment)); - comment.Body = ""; - await AssertEx.Throws(async () => await client.Edit("owner", "name", 1, comment)); - comment.Body = body; } } diff --git a/Octokit/Clients/PullRequestReviewCommentsClient.cs b/Octokit/Clients/PullRequestReviewCommentsClient.cs index 0df5eb3a..280e5948 100644 --- a/Octokit/Clients/PullRequestReviewCommentsClient.cs +++ b/Octokit/Clients/PullRequestReviewCommentsClient.cs @@ -86,9 +86,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); - Ensure.ArgumentNotNullOrEmptyString(comment.CommitId, "commitId"); - Ensure.ArgumentNotNullOrEmptyString(comment.Path, "path"); var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); @@ -114,7 +111,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); var response = await ApiConnection.Connection.PostAsync(ApiUrls.PullRequestReviewComments(owner, name, number), comment, null, null).ConfigureAwait(false); @@ -140,7 +136,6 @@ namespace Octokit Ensure.ArgumentNotNullOrEmptyString(owner, "owner"); Ensure.ArgumentNotNullOrEmptyString(name, "name"); Ensure.ArgumentNotNull(comment, "comment"); - Ensure.ArgumentNotNullOrEmptyString(comment.Body, "body"); return ApiConnection.Patch(ApiUrls.PullRequestReviewComment(owner, name, number), comment); } diff --git a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs index 08e9e581..b3f96441 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentCreate.cs @@ -4,25 +4,48 @@ namespace Octokit { public class PullRequestReviewCommentCreate : RequestParameters { + private readonly string _body; + private readonly string _commitId; + private readonly string _path; + private readonly int _position; + /// /// The text of the comment. /// - public string Body { get; set; } + public string Body { get { return _body; } } /// /// The SHA of the commit to comment on. /// - [Parameter(Key = "commit_id")] - public string CommitId { get; set; } + public string CommitId { get { return _commitId; } } /// /// The relative path of the file to comment on. /// - public string Path { get; set; } + public string Path { get { return _path; } } /// /// The line index in the diff to comment on. /// - public int Position { get; set; } + public int Position { get { return _position; } } + + /// + /// Creates a comment + /// + /// The text of the comment + /// The SHA of the commit to comment on + /// The relative path of the file to comment on + /// The line index in the diff to comment on + public PullRequestReviewCommentCreate(string body, string commitId, string path, int position) + { + Ensure.ArgumentNotNullOrEmptyString(body, "body"); + Ensure.ArgumentNotNullOrEmptyString(commitId, "commitId"); + Ensure.ArgumentNotNullOrEmptyString(path, "path"); + + _body = body; + _commitId = commitId; + _path = path; + _position = position; + } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs index 1ad6f0ba..d257ebf1 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentEdit.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentEdit.cs @@ -3,9 +3,22 @@ namespace Octokit { public class PullRequestReviewCommentEdit : RequestParameters { + private readonly string _body; + /// /// The text of the comment. /// - public string Body { get; set; } + public string Body { get { return _body; }} + + /// + /// Creates an edit to a comment + /// + /// The text of the comment + public PullRequestReviewCommentEdit(string body) + { + Ensure.ArgumentNotNullOrEmptyString(body, "body"); + + _body = body; + } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs index a8e23599..90822c01 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentReplyCreate.cs @@ -4,15 +4,30 @@ namespace Octokit { public class PullRequestReviewCommentReplyCreate : RequestParameters { + private readonly string _body; + private readonly int _inReplyTo; + /// /// The text of the comment. /// - public string Body { get; set; } + public string Body { get { return _body; } } /// /// The comment Id to reply to. /// - [Parameter(Key = "in_reply_to")] - public int InReplyTo { get; set; } + public int InReplyTo { get { return _inReplyTo; } } + + /// + /// Creates a comment that is replying to another comment. + /// + /// The text of the comment + /// The comment Id to reply to + public PullRequestReviewCommentReplyCreate(string body, int inReplyTo) + { + Ensure.ArgumentNotNullOrEmptyString(body, "body"); + + _body = body; + _inReplyTo = inReplyTo; + } } } diff --git a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs index 125f8059..ada12064 100644 --- a/Octokit/Models/Request/PullRequestReviewCommentRequest.cs +++ b/Octokit/Models/Request/PullRequestReviewCommentRequest.cs @@ -7,7 +7,6 @@ namespace Octokit public PullRequestReviewCommentRequest() { // Default arguments - Sort = PullRequestReviewCommentSort.Created; Direction = SortDirection.Ascending; Since = null;