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 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);
                }
            }
Ejemplo n.º 4
0
            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 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);
                }
            }
Ejemplo n.º 6
0
        static IPullRequestSessionService CreateService(FakeDiffService diffService)
        {
            var result = Substitute.For <IPullRequestSessionService>();

            result.Diff(
                Arg.Any <ILocalRepositoryModel>(),
                Arg.Any <string>(),
                Arg.Any <string>(),
                Arg.Any <string>(),
                Arg.Any <byte[]>())
            .Returns(i => diffService.Diff(
                         null,
                         i.ArgAt <string>(1),
                         i.ArgAt <string>(2),
                         i.ArgAt <string>(3),
                         i.ArgAt <byte[]>(4)));
            result.GetTipSha(Arg.Any <ILocalRepositoryModel>()).Returns("BRANCH_TIP");

            var diffChunk = "@@ -1,4 +1,4 @@";

            result.PostReviewComment(null, null, null, 0, null, 0).ReturnsForAnyArgs(i =>
                                                                                     CreateComment(diffChunk, i.ArgAt <string>(4)));
            result.PostReviewComment(null, null, null, 0, null, null, null, 0).ReturnsForAnyArgs(i =>
                                                                                                 CreateComment(diffChunk, i.ArgAt <string>(4)));
            return(result);
        }
Ejemplo n.º 7
0
            public async Task MatchesReviewCommentOnDifferentLine()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"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(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff);

                    var thread = result.Single();
                    Assert.Equal(4, thread.LineNumber);
                }
            }
Ejemplo n.º 8
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 thread       = 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,
                        thread);

                    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(file.InlineCommentThreads.Count, Is.EqualTo(1));
                    Assert.That(file.InlineCommentThreads[0].LineNumber, Is.EqualTo(2));
                }
            }
Ejemplo n.º 9
0
            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),
                        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);

                    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[]
                    {
                        Tuple.Create(2, DiffSide.Right),
                        Tuple.Create(4, DiffSide.Right),
                    },
                        linesChanged.ToArray());
                }
            }
            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);
                }
            }
Ejemplo n.º 11
0
            public async Task UpdatesInlineCommentThreadsFromEditorContent()
            {
                using (TestUtils.WithScheduler(Scheduler.CurrentThread))
                {
                    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()));
                    }
                }
            }
Ejemplo n.º 12
0
            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 = 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[0].Comments.Count);

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

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

                    Assert.Equal(2, file.InlineCommentThreads[0].Comments.Count);
                    Assert.Equal("Comment1", file.InlineCommentThreads[0].Comments[0].Body);
                    Assert.Equal("Comment2", file.InlineCommentThreads[0].Comments[1].Body);
                }
            }
            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);
                }
            }
Ejemplo n.º 14
0
            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     = CreateCommentThread(@"@@ -1,4 +1,4 @@
         Line 1
         Line 2
        -Line 3
        +Line 3 with comment", "Comment1");

                var comment2 = CreateCommentThread(@"@@ -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,
                        comment1);
                    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(1, Is.EqualTo(file.InlineCommentThreads[0].Comments.Count));

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

                    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].Comment.Body));
                    Assert.That("Comment2", Is.EqualTo(file.InlineCommentThreads[0].Comments[1].Comment.Body));
                }
            }
Ejemplo n.º 15
0
            public async Task UpdatesReviewCommentWithNewBody()
            {
                using (TestUtils.WithScheduler(Scheduler.CurrentThread))
                {
                    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 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),
                        CreateTeamExplorerContext(CreateRepositoryModel()));
                    var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

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

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

                    await file.LinesChanged.Take(1);

                    Assert.That("Updated Comment", Is.EqualTo(file.InlineCommentThreads[0].Comments[0].Body));
                }
            }
Ejemplo n.º 17
0
            public async Task UpdatesWithNewLineNumber()
            {
                var baseContents    = @"Line 1
Line 2
Line 3
Line 4";
                var headContents    = @"Line 1
Line 2
Line 3 with comment
Line 4";
                var newHeadContents = @"Inserted Line
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(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var threads = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff,
                        "HEAD_SHA");

                    Assert.That(2, Is.EqualTo(threads[0].LineNumber));

                    diff = await diffService.Diff(FilePath, newHeadContents);

                    var changedLines = target.UpdateCommentThreads(threads, diff);

                    Assert.That(3, Is.EqualTo(threads[0].LineNumber));
                    Assert.That(
                        new[]
                    {
                        Tuple.Create(2, DiffSide.Right),
                        Tuple.Create(3, DiffSide.Right)
                    },
                        Is.EqualTo(changedLines.ToArray()));
                }
            }
Ejemplo n.º 18
0
            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);
                }
            }
Ejemplo n.º 20
0
            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));
                }
            }
Ejemplo n.º 21
0
            public async Task UpdatesFileWithNewThread()
            {
                using (var diffService = new FakeDiffService())
                {
                    var target = await CreateTarget(diffService);

                    var file = await target.GetFile(FilePath);

                    Assert.Empty(file.InlineCommentThreads);

                    await target.PostReviewComment("New Comment", 0);

                    Assert.Equal(1, file.InlineCommentThreads.Count);
                    Assert.Equal(1, file.InlineCommentThreads[0].Comments.Count);
                    Assert.Equal("New Comment", file.InlineCommentThreads[0].Comments[0].Body);
                }
            }
Ejemplo n.º 22
0
        static IPullRequestSessionService CreateService(FakeDiffService diffService)
        {
            var result = Substitute.For <IPullRequestSessionService>();

            result.Diff(
                Arg.Any <ILocalRepositoryModel>(),
                Arg.Any <string>(),
                Arg.Any <string>(),
                Arg.Any <byte[]>())
            .Returns(i => diffService.Diff(
                         null,
                         i.ArgAt <string>(1),
                         i.ArgAt <string>(2),
                         i.ArgAt <byte[]>(3)));
            result.GetTipSha(Arg.Any <ILocalRepositoryModel>()).Returns("BRANCH_TIP");
            return(result);
        }
            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);
                }
            }
Ejemplo n.º 25
0
            public async Task ReturnsLineNumberMinus1ForNonMatchingComment()
            {
                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"Line 1
Line 2
Line 3 with comment
Line 4";

                var comment1 = CreateCommentThread(@"@@ -1,4 +1,4 @@
 Line 1
 Line 2
-Line 3
+Line 3 with comment", position: 1);

                var comment2 = CreateCommentThread(@"@@ -1,4 +1,4 @@
-Line 1
 Line 2
-Line 3
+Line 3 with comment", position: 2);

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment1, comment2);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff,
                        "HEAD_SHA");

                    Assert.That(result.Count, Is.EqualTo(2));
                    Assert.That(result[1].LineNumber, Is.EqualTo(-1));
                }
            }
            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 IgnoreCommentsWithNoDiffLineContext()
            {
                var baseContents = "Line 1";
                var headContents = "Line 1";

                var comment = CreateComment(@"@@ -10,7 +10,6 @@ class Program");

                using (var diffService = new FakeDiffService(FilePath, baseContents))
                {
                    var diff = await diffService.Diff(FilePath, headContents);

                    var pullRequest = CreatePullRequest(FilePath, comment);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        FilePath,
                        diff);

                    Assert.That(result, Is.Empty);
                }
            }
Ejemplo n.º 28
0
            public async Task HandlesDifferingPathSeparators()
            {
                var winFilePath    = @"foo\test.cs";
                var gitHubFilePath = "foo/test.cs";

                var baseContents = @"Line 1
Line 2
Line 3
Line 4";
                var headContents = @"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", gitHubFilePath);

                using (var diffService = new FakeDiffService(winFilePath, baseContents))
                {
                    var diff = await diffService.Diff(winFilePath, headContents);

                    var pullRequest = CreatePullRequest(gitHubFilePath, comment);
                    var target      = CreateTarget(diffService);

                    var result = target.BuildCommentThreads(
                        pullRequest,
                        winFilePath,
                        diff,
                        "HEAD_SHA");

                    var thread = result.First();
                    Assert.That(thread.LineNumber, Is.EqualTo(4));
                }
            }
Ejemplo n.º 29
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));
                }
            }
Ejemplo n.º 30
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);
                }
            }