Exemplo n.º 1
0
            public async Task UpdatingCurrentSessionPullRequestTriggersLinesChanged()
            {
                var textView           = CreateTextView();
                var sessionService     = CreateSessionService();
                var expectedLineNumber = 2;
                var threads            = new[]
                {
                    CreateInlineCommentThreadModel(expectedLineNumber),
                };

                sessionService.BuildCommentThreads(null, null, null).ReturnsForAnyArgs(threads);

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                var raised      = false;
                var pullRequest = target.CurrentSession.PullRequest;

                file.LinesChanged.Subscribe(x => raised = x.Count == 1 && x[0].Item1 == expectedLineNumber);

                // LinesChanged should be raised even if the IPullRequestModel is the same.
                await target.CurrentSession.Update(target.CurrentSession.PullRequest);

                Assert.True(raised);
            }
            public async Task DiffIsSet()
            {
                var textView       = CreateTextView();
                var contents       = Encoding.UTF8.GetBytes("File contents");
                var diff           = new List <DiffChunk>();
                var sessionService = CreateSessionService();

                sessionService.GetContents(textView.TextBuffer).Returns(contents);
                sessionService.GetPullRequestMergeBase(null, null).ReturnsForAnyArgs("MERGE_BASE");
                sessionService.Diff(
                    Arg.Any <ILocalRepositoryModel>(),
                    "MERGE_BASE",
                    "HEADSHA",
                    FilePath,
                    contents).Returns(diff);

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Same(diff, file.Diff);
            }
            public async Task MovingToNoRepositoryShouldNullOutProperties()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();
                var threads        = new List <IInlineCommentThreadModel>();
                var teHolder       = new FakeTeamExplorerServiceHolder(CreateRepositoryModel());

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateRepositoryHosts(),
                    teHolder);

                sessionService.BuildCommentThreads(
                    target.CurrentSession.PullRequest,
                    FilePath,
                    Arg.Any <IReadOnlyList <DiffChunk> >())
                .Returns(threads);

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

                Assert.NotNull(file.BaseSha);
                Assert.NotNull(file.CommitSha);
                Assert.NotNull(file.Diff);
                Assert.NotNull(file.InlineCommentThreads);
                Assert.NotNull(file.TrackingPoints);

                teHolder.ActiveRepo = null;

                Assert.Null(file.BaseSha);
                Assert.Null(file.CommitSha);
                Assert.Null(file.Diff);
                Assert.Null(file.InlineCommentThreads);
                Assert.Null(file.TrackingPoints);
            }
            public async Task CreatesTrackingPointsForThreads()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();
                var threads        = new List <IInlineCommentThreadModel>
                {
                    CreateInlineCommentThreadModel(1),
                    CreateInlineCommentThreadModel(2),
                };

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                sessionService.BuildCommentThreads(
                    target.CurrentSession.PullRequest,
                    FilePath,
                    Arg.Any <IReadOnlyList <DiffChunk> >())
                .Returns(threads);

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

                Assert.Equal(2, file.TrackingPoints.Count);
            }
            public async Task RebuildSignalUpdatesCommitSha()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();

                sessionService.CreateRebuildSignal().Returns(new Subject <ITextSnapshot>());

                var threads = new List <IInlineCommentThreadModel>
                {
                    CreateInlineCommentThreadModel(1),
                    CreateInlineCommentThreadModel(2),
                };

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Same("TIPSHA", file.CommitSha);

                sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false);
                file.Rebuild.OnNext(textView.TextBuffer.CurrentSnapshot);

                Assert.Null(file.CommitSha);
            }
Exemplo n.º 6
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());
                }
            }
Exemplo n.º 7
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 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));
                }
            }
            public async Task CommitShaIsNullIfModified()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(true),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Null(file.CommitSha);
            }
            public async Task BaseShaIsSet()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Same("BASESHA", file.BaseSha);
            }
            public async Task CommitShaIsNullIfModified()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(true),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    CreateTeamExplorerContext(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.That(file.CommitSha, Is.Null);
            }
Exemplo n.º 12
0
            public async Task CommitShaIsSet()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Same("TIPSHA", file.CommitSha);
            }
            public async Task BaseShaIsSet()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    CreateTeamExplorerContext(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.That("BASESHA", Is.SameAs(file.BaseSha));
            }
Exemplo n.º 14
0
            public async Task ModifyingBufferMarksThreadsAsStaleAndSignalsRebuild()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();
                var rebuild        = Substitute.For <ISubject <ITextSnapshot, ITextSnapshot> >();

                sessionService.CreateRebuildSignal().Returns(rebuild);

                var threads = new List <IInlineCommentThreadModel>
                {
                    CreateInlineCommentThreadModel(1),
                    CreateInlineCommentThreadModel(2),
                };

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                sessionService.BuildCommentThreads(
                    target.CurrentSession.PullRequest,
                    FilePath,
                    Arg.Any <IReadOnlyList <DiffChunk> >())
                .Returns(threads);

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

                var linesChangedReceived = false;

                file.LinesChanged.Subscribe(x => linesChangedReceived = true);

                // Make the first tracking points return a different value so that the thread is marked as stale.
                var snapshot = textView.TextSnapshot;

                file.TrackingPoints[file.InlineCommentThreads[0]].GetPosition(snapshot).ReturnsForAnyArgs(5);

                SignalTextChanged(textView.TextBuffer);

                threads[0].Received().IsStale      = true;
                threads[1].DidNotReceive().IsStale = true;

                Assert.True(linesChangedReceived);
                file.Rebuild.Received().OnNext(Arg.Any <ITextSnapshot>());
            }
            public async Task ClosingTextViewDisposesFile()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.NotNull(file.ToDispose);

                textView.Closed += Raise.Event();

                Assert.Null(file.ToDispose);
            }
            public async Task CommitShaIsUpdatedOnTextChange()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Equal("TIPSHA", file.CommitSha);

                sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false);
                SignalTextChanged(textView.TextBuffer);

                Assert.Null(file.CommitSha);
            }
            public async Task CommitShaIsUpdatedOnTextChange()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    CreateTeamExplorerContext(CreateRepositoryModel()));
                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.That("TIPSHA", Is.EqualTo(file.CommitSha));

                sessionService.IsUnmodifiedAndPushed(null, null, null).ReturnsForAnyArgs(false);
                SignalTextChanged(textView.TextBuffer);

                Assert.That(file.CommitSha, Is.Null);
            }
Exemplo n.º 18
0
            public async Task ClosingTextViewDisposesFile()
            {
                var textView = CreateTextView();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));
                var file = (PullRequestSessionLiveFile)await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                var compositeDisposable = file.ToDispose as CompositeDisposable;

                Assert.NotNull(compositeDisposable);
                Assert.False(compositeDisposable.IsDisposed);

                textView.Closed += Raise.Event();

                Assert.True(compositeDisposable.IsDisposed);
            }
            public async Task InlineCommentThreadsIsSet()
            {
                var textView       = CreateTextView();
                var sessionService = CreateSessionService();
                var threads        = new List <IInlineCommentThreadModel>();

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    sessionService,
                    CreateRepositoryHosts(),
                    new FakeTeamExplorerServiceHolder(CreateRepositoryModel()));

                sessionService.BuildCommentThreads(
                    target.CurrentSession.PullRequest,
                    FilePath,
                    Arg.Any <IReadOnlyList <DiffChunk> >())
                .Returns(threads);

                var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer);

                Assert.Same(threads, file.InlineCommentThreads);
            }
Exemplo n.º 20
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);
                }
            }
            public async Task MovingToNoRepositoryShouldNullOutProperties()
            {
                var textView            = CreateTextView();
                var sessionService      = CreateSessionService();
                var threads             = new List <IInlineCommentThreadModel>();
                var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel());

                var target = new PullRequestSessionManager(
                    CreatePullRequestService(),
                    CreateSessionService(),
                    CreateConnectionManager(),
                    CreateModelServiceFactory(),
                    teamExplorerContext);

                sessionService.BuildCommentThreads(
                    target.CurrentSession.PullRequest,
                    FilePath,
                    Arg.Any <IReadOnlyList <DiffChunk> >())
                .Returns(threads);

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

                Assert.That(file.BaseSha, Is.Not.Null);
                Assert.That(file.CommitSha, Is.Not.Null);
                Assert.That(file.Diff, Is.Not.Null);
                Assert.That(file.InlineCommentThreads, Is.Not.Null);
                Assert.That(file.TrackingPoints, Is.Not.Null);

                SetActiveRepository(teamExplorerContext, null);

                Assert.That(file.BaseSha, Is.Null);
                Assert.That(file.CommitSha, Is.Null);
                Assert.That(file.Diff, Is.Null);
                Assert.That(file.InlineCommentThreads, Is.Null);
                Assert.That(file.TrackingPoints, Is.Null);
            }