public async Task UpdatesInlineCommentThreadsFromEditorContent()
            {
                var baseContents   = @"Line 1
Line 2
Line 3
Line 4";
                var contents       = @"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        = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment");

                using (var diffService = new FakeDiffService())
                {
                    var textView    = CreateTextView(contents);
                    var pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        comment);

                    diffService.AddFile(FilePath, baseContents, "MERGE_BASE");

                    var target = CreateTarget(sessionService: CreateRealSessionService(diffService, pullRequest));
                    var file   = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                    Assert.That(1, Is.EqualTo(file.InlineCommentThreads.Count));
                    Assert.That(2, Is.EqualTo(file.InlineCommentThreads[0].LineNumber));

                    textView.TextSnapshot.GetText().Returns(editorContents);
                    SignalTextChanged(textView.TextBuffer);

                    var linesChanged = await file.LinesChanged.Take(1);

                    Assert.That(1, Is.EqualTo(file.InlineCommentThreads.Count));
                    Assert.That(4, Is.EqualTo(file.InlineCommentThreads[0].LineNumber));
                    Assert.That(
                        new[]
                    {
                        Tuple.Create(2, DiffSide.Right),
                        Tuple.Create(4, DiffSide.Right),
                    },
                        Is.EqualTo(linesChanged.ToArray()));
                }
            }
            public async Task AddsNewReviewCommentToThread()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var contents     = @"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 textView    = CreateTextView(contents);
                    var pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        OwnerCloneUrl,
                        comment1);

                    diffService.AddFile(FilePath, baseContents, "MERGE_BASE");

                    var target = CreateTarget(
                        sessionService: CreateRealSessionService(diff: diffService),
                        modelServiceFactory: CreateModelServiceFactory(pullRequest));
                    var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                    Assert.That(1, Is.EqualTo(file.InlineCommentThreads[0].Comments.Count));

                    pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        OwnerCloneUrl,
                        comment1,
                        comment2);
                    await target.CurrentSession.Update(pullRequest);

                    var linesChanged = await file.LinesChanged.Take(1);

                    Assert.That(2, Is.EqualTo(file.InlineCommentThreads[0].Comments.Count));
                    Assert.That("Comment1", Is.EqualTo(file.InlineCommentThreads[0].Comments[0].Body));
                    Assert.That("Comment2", Is.EqualTo(file.InlineCommentThreads[0].Comments[1].Body));
                }
            }
            public async Task UpdatesInlineCommentThreadsFromEditorContent()
            {
                var baseContents   = @"Line 1
Line 2
Line 3
Line 4";
                var contents       = @"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 textView    = CreateTextView(contents);
                    var pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        OwnerCloneUrl,
                        comment);

                    diffService.AddFile(FilePath, baseContents, "MERGE_BASE");

                    var target = new PullRequestSessionManager(
                        CreatePullRequestService(),
                        CreateRealSessionService(diff: diffService),
                        CreateRepositoryHosts(pullRequest),
                        new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                    var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                    Assert.Equal(1, file.InlineCommentThreads.Count);
                    Assert.Equal(2, file.InlineCommentThreads[0].LineNumber);

                    textView.TextSnapshot.GetText().Returns(editorContents);
                    SignalTextChanged(textView.TextBuffer);

                    var linesChanged = await file.LinesChanged.Take(1);

                    Assert.Equal(1, file.InlineCommentThreads.Count);
                    Assert.Equal(4, file.InlineCommentThreads[0].LineNumber);
                    Assert.Equal(new[] { 2, 4 }, linesChanged.ToArray());
                }
            }
Exemple #4
0
            public async Task UpdatesReviewCommentWithNewBody()
            {
                var baseContents   = @"Line 1
Line 2
Line 3
Line 4";
                var contents       = @"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", "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 textView    = CreateTextView(contents);
                    var pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        OwnerCloneUrl,
                        comment);

                    diffService.AddFile(FilePath, baseContents, "MERGE_BASE");

                    var target = new PullRequestSessionManager(
                        CreatePullRequestService(),
                        CreateRealSessionService(diff: diffService),
                        CreateConnectionManager(),
                        CreateModelServiceFactory(pullRequest),
                        new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                    var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                    Assert.Equal("Original Comment", file.InlineCommentThreads[0].Comments[0].Body);

                    pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        OwnerCloneUrl,
                        updatedComment);
                    await target.CurrentSession.Update(pullRequest);

                    await file.LinesChanged.Take(1);

                    Assert.Equal("Updated Comment", file.InlineCommentThreads[0].Comments[0].Body);
                }
            }
Exemple #5
0
            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));
                }
            }
Exemple #6
0
            public async Task UpdatesReviewCommentWithNewBody()
            {
                var baseContents   = @"Line 1
Line 2
Line 3
Line 4";
                var contents       = @"Line 1
Line 2
Line 3 with comment
Line 4";
                var comment        = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment", "Original Comment");
                var updatedComment = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment", "Updated Comment");

                using (var diffService = new FakeDiffService())
                {
                    var textView    = CreateTextView(contents);
                    var pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        comment);
                    var sessionService = CreateRealSessionService(diffService, pullRequest);

                    diffService.AddFile(FilePath, baseContents, "MERGE_BASE");

                    var target = CreateTarget(sessionService: sessionService);
                    var file   = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                    Assert.That(file.InlineCommentThreads[0].Comments[0].Comment.Body, Is.EqualTo("Original Comment"));

                    pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        updatedComment);
                    sessionService.ReadPullRequestDetail(
                        Arg.Any <HostAddress>(),
                        Arg.Any <string>(),
                        Arg.Any <string>(),
                        Arg.Any <int>()).Returns(pullRequest);
                    await target.CurrentSession.Refresh();

                    await file.LinesChanged.Take(1);

                    Assert.That("Updated Comment", Is.EqualTo(file.InlineCommentThreads[0].Comments[0].Comment.Body));
                }
            }
            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 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);
                }
            }
Exemple #11
0
            public async Task InlineCommentThreadsAreLoadedFromCurrentSession()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var contents     = @"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 textView    = CreateTextView(contents);
                    var pullRequest = CreatePullRequestModel(
                        CurrentBranchPullRequestNumber,
                        OwnerCloneUrl,
                        comment);

                    diffService.AddFile(FilePath, baseContents, "MERGE_BASE");

                    var target = new PullRequestSessionManager(
                        CreatePullRequestService(),
                        CreateRealSessionService(diff: diffService),
                        CreateConnectionManager(),
                        CreateModelServiceFactory(pullRequest),
                        new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                    var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                    Assert.Equal(1, file.InlineCommentThreads.Count);
                    Assert.Equal(2, file.InlineCommentThreads[0].LineNumber);
                }
            }