public async Task DoesntThrowIfGetFileCalledDuringUpdate() { 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); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), string.Empty, true); await target.GetFile("test.cs"); // Simulate calling GetFile with a file that's not yet been initialized // while doing the Update. service.WhenForAnyArgs(x => x.Diff(null, null, null, null, null)) .Do(_ => target.GetFile("other.cs").Forget()); await target.Update(pullRequest); } }
public async Task DoesntThrowIfGetFileCalledDuringUpdate() { var thread = CreateThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(thread); var service = CreateRealSessionService(diffService); var target = new PullRequestSession( service, CreateActor(), pullRequest, CreateLocalRepository(), string.Empty, true); await target.GetFile("test.cs"); // Simulate calling GetFile with a file that's not yet been initialized // while doing the Update. service.WhenForAnyArgs(x => x.Diff(null, null, null, null)) .Do(_ => target.GetFile("other.cs").Forget()); UpdateReadPullRequest(service, pullRequest); await target.Refresh(); } }
public async Task DifferentCommitShasReturnDifferentFiles() { var target = new PullRequestSession( CreateRealSessionService(), CreateActor(), CreatePullRequest(), Substitute.For <LocalRepositoryModel>(), "owner", true); var file1 = await target.GetFile(FilePath, "123"); var file2 = await target.GetFile(FilePath, "456"); Assert.That(file1, Is.Not.SameAs(file2)); }
public async Task SameNonHeadCommitShasReturnSameFiles() { var target = new PullRequestSession( CreateRealSessionService(), Substitute.For <IAccount>(), CreatePullRequest(), Substitute.For <ILocalRepositoryModel>(), "owner", true); var file1 = await target.GetFile(FilePath, "123"); var file2 = await target.GetFile(FilePath, "123"); Assert.That(file1, Is.SameAs(file2)); }
public async Task CommitShaIsSetIfUnmodified() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"Line 1 Line 2 Line 3 with comment Line 4"; using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(); var service = CreateService(diffService); diffService.AddFile(FilePath, baseContents); service.IsUnmodifiedAndPushed(Arg.Any <ILocalRepositoryModel>(), FilePath, Arg.Any <byte[]>()).Returns(true); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), true); var editor = new FakeEditorContentSource(headContents); var file = await target.GetFile(FilePath, editor); Assert.Equal("BRANCH_TIP", file.CommitSha); } }
public async Task CommitShaIsReadFromPullRequestModelIfBranchNotCheckedOut() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"Line 1 Line 2 Line 3 with comment Line 4"; using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(); var service = CreateService(diffService); diffService.AddFile(FilePath, baseContents); service.IsUnmodifiedAndPushed(Arg.Any <ILocalRepositoryModel>(), FilePath, Arg.Any <byte[]>()).Returns(false); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), "owner", isCheckedOut: false); var editor = new FakeEditorContentSource(headContents); var file = await target.GetFile(FilePath, editor); Assert.Equal("HEAD_SHA", file.CommitSha); } }
async Task <PullRequestSession> CreateTarget(FakeDiffService diffService) { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var pullRequest = CreatePullRequest(); 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(headContents); var file = await target.GetFile(FilePath, editor); return(target); }
public async Task AddsNewReviewCommentToThread() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var editorContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var comment1 = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Comment1"); var comment2 = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Comment2"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(comment1); 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(editorContents); var file = await target.GetFile(FilePath, editor); var thread = file.InlineCommentThreads.Single(); Assert.Equal("Comment1", thread.Comments.Single().Body); Assert.Equal(2, thread.LineNumber); pullRequest = CreatePullRequest(comment1, comment2); await target.Update(pullRequest); thread = file.InlineCommentThreads.Single(); Assert.Equal(2, thread.Comments.Count); Assert.Equal(new[] { "Comment1", "Comment2" }, thread.Comments.Select(x => x.Body).ToArray()); Assert.Equal(2, thread.LineNumber); } }
public async Task UpdatesReviewCommentWithNewBody() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var editorContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var originalComment = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Original Comment"); var updatedComment = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Updated Comment"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(originalComment); 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(editorContents); var file = await target.GetFile(FilePath, editor); var thread = file.InlineCommentThreads.Single(); Assert.Equal("Original Comment", thread.Comments.Single().Body); Assert.Equal(2, thread.LineNumber); pullRequest = CreatePullRequest(updatedComment); await target.Update(pullRequest); thread = file.InlineCommentThreads.Single(); Assert.Equal("Updated Comment", thread.Comments.Single().Body); Assert.Equal(2, thread.LineNumber); } }
public async Task BaseShaIsSet() { var target = new PullRequestSession( CreateSessionService(), Substitute.For <IAccount>(), CreatePullRequest(), Substitute.For <ILocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath); Assert.Same("BASE_SHA", file.BaseSha); }
public async Task BaseShaIsSet() { var target = new PullRequestSession( CreateRealSessionService(), CreateActor(), CreatePullRequest(), Substitute.For <LocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath); Assert.That("BASE_SHA", Is.SameAs(file.BaseSha)); }
public async Task CommitShaIsSet() { var target = new PullRequestSession( CreateSessionService(), Substitute.For <IAccount>(), CreatePullRequest(), Substitute.For <ILocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath); Assert.That("HEAD_SHA", Is.SameAs(file.CommitSha)); }
public async Task AddsNewReviewCommentToThreadNonHeadFile() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var comment1 = CreateThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Comment1"); var comment2 = CreateThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Comment2"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(comment1); var service = CreateRealSessionService(diffService); diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); diffService.AddFile(FilePath, headContents, "123"); var target = new PullRequestSession( service, CreateActor(), pullRequest, CreateLocalRepository(), "owner", true); var file = await target.GetFile(FilePath, "123"); Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(1)); Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); pullRequest = CreatePullRequest(comment1, comment2); UpdateReadPullRequest(service, pullRequest); await target.Refresh(); Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(2)); Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); } }
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 PinnedCommitShaIsSet() { var target = new PullRequestSession( CreateRealSessionService(), CreateActor(), CreatePullRequest(), Substitute.For <LocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath, "123"); Assert.That("123", Is.SameAs(file.CommitSha)); Assert.That(file.IsTrackingHead, Is.False); }
public async Task AddsNewReviewCommentToThreadOnHeadFile() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var comment1 = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Comment1"); var comment2 = CreateComment(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment", "Comment2"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(comment1); var service = CreateRealSessionService(diffService); diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); diffService.AddFile(FilePath, headContents, "HEAD_SHA"); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath, "HEAD"); Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(1)); Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); pullRequest = CreatePullRequest(comment1, comment2); await target.Update(pullRequest); Assert.That(file.InlineCommentThreads[0].Comments, Has.Count.EqualTo(2)); Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2)); } }
public async Task UpdatesReviewCommentWithContentsFromGitWhenBranchNotCheckedOut() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var gitContents = Encoding.UTF8.GetBytes(@"Line 1 Line 2 Line 3 with comment Line 4"); var editorContents = @"Editor content"; 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); // Because the PR branch isn't checked out, the file contents should be read // from git and not the editor or disk. service.ExtractFileFromGit(Arg.Any <ILocalRepositoryModel>(), PullRequestNumber, "HEAD_SHA", FilePath) .Returns(Task.FromResult(gitContents)); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), "owner", isCheckedOut: false); var editor = new FakeEditorContentSource(editorContents); var file = await target.GetFile(FilePath, editor); var thread = file.InlineCommentThreads.First(); Assert.Equal(2, 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); } }
public async Task MatchesReviewCommentOnOriginalLineGettingContentFromDisk() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"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); service.ReadFileAsync(FilePath).Returns(Encoding.UTF8.GetBytes(headContents)); var target = new PullRequestSession( service, Substitute.For <IAccount>(), pullRequest, Substitute.For <ILocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath); var thread = file.InlineCommentThreads.First(); Assert.Equal(2, thread.LineNumber); } }
public async Task InlineCommentThreadsIsSet() { var baseContents = @"Line 1 Line 2 Line 3 Line 4"; var headContents = @"Line 1 Line 2 Line 3 with comment Line 4"; var thread = CreateThread(@"@@ -1,4 +1,4 @@ Line 1 Line 2 -Line 3 +Line 3 with comment"); using (var diffService = new FakeDiffService()) { var pullRequest = CreatePullRequest(thread); var service = CreateRealSessionService(diffService); diffService.AddFile(FilePath, baseContents, "MERGE_BASE"); diffService.AddFile(FilePath, headContents, "HEAD_SHA"); var target = new PullRequestSession( service, CreateActor(), pullRequest, Substitute.For <LocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath); var inlineThread = file.InlineCommentThreads.First(); Assert.That(2, Is.EqualTo(inlineThread.LineNumber)); } }
public async Task DiffShaIsSet() { var diff = new List <DiffChunk>(); var sessionService = CreateRealSessionService(); sessionService.Diff( Arg.Any <LocalRepositoryModel>(), "MERGE_BASE", "HEAD_SHA", FilePath).Returns(diff); var target = new PullRequestSession( sessionService, CreateActor(), CreatePullRequest(), Substitute.For <LocalRepositoryModel>(), "owner", true); var file = await target.GetFile(FilePath); Assert.That(diff, Is.SameAs(file.Diff)); }