public async Task UpdatesReviewCommentWithEditorContents() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var diskContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var editorContents = @"New Line 1 New Line 2 Line 1 Line 2 Line 3 with comment Line 4"; var comment = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(comment); var service = CreateService(diffService); diffService.AddFile(FilePath, baseContents); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), "owner", true); var editor = new FakeEditorContentSource(diskContents); var file = await target.GetFile(FilePath, editor); var thread = file.InlineCommentThreads.First(); Assert.Equal(2, thread.LineNumber); editor.SetContent(editorContents); await target.UpdateEditorContent(FilePath); Assert.Equal(4, thread.LineNumber); } }
public async Task CommitShaIsNullWhenChangedToModified() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = Encoding.UTF8.GetBytes(@"Line 1 Line 2 Line 3 with comment Line 4"); var editorContents = Encoding.UTF8.GetBytes(@"Line 1 Line 2 Line 3 with comment Line 4 with comment"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(); var service = CreateService(diffService); diffService.AddFile(FilePath, baseContents); service.IsUnmodifiedAndPushed(Arg.Any <ILocalRepositoryModel>(), FilePath, headContents).Returns(true); service.IsUnmodifiedAndPushed(Arg.Any <ILocalRepositoryModel>(), FilePath, editorContents).Returns(false); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), "owner", true); var editor = new FakeEditorContentSource(headContents); var file = await target.GetFile(FilePath, editor); Assert.Equal("BRANCH_TIP", file.CommitSha); editor.SetContent(editorContents); await target.UpdateEditorContent(FilePath); Assert.Null(file.CommitSha); } }