public async Task SessionCanBeCollected() { WeakReference <IPullRequestSession> weakSession = null; var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); Func <Task> run = async() => { var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber); var session = await target.GetSession(newModel); Assert.NotNull(session); weakSession = new WeakReference <IPullRequestSession>(session); }; await run(); GC.Collect(); IPullRequestSession result; weakSession.TryGetTarget(out result); Assert.Null(result); }
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 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, CreateConnectionManager(), CreateModelServiceFactory(), 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); }
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, 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); Assert.Equal(2, file.TrackingPoints.Count); }
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, CreateConnectionManager(), CreateModelServiceFactory(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); Assert.Same(diff, file.Diff); }
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 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 void CreatesSessionWithCorrectRepositoryOwner() { var target = new PullRequestSessionManager( CreatePullRequestService("this-owner"), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); Assert.Equal("this-owner", target.CurrentSession.RepositoryOwner); }
public void CreatesSessionWithCorrectRepositoryOwner() { var target = new PullRequestSessionManager( CreatePullRequestService("this-owner"), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), CreateTeamExplorerContext(CreateRepositoryModel())); Assert.That("this-owner", Is.EqualTo(target.CurrentSession.RepositoryOwner)); }
public void CreatesSessionForCurrentBranch() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); Assert.NotNull(target.CurrentSession); Assert.True(target.CurrentSession.IsCheckedOut); }
public void LocalRepositoryModelNull() { var repositoryModel = null as LocalRepositoryModel; var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), CreateTeamExplorerContext(null)); Assert.That(target.CurrentSession, Is.Null); }
public void CreatesSessionForCurrentBranch() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), CreateTeamExplorerContext(CreateRepositoryModel())); Assert.That(target.CurrentSession, Is.Not.Null); Assert.That(target.CurrentSession.IsCheckedOut, Is.True); }
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 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), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); var file = await target.GetLiveFile(FilePath, textView, textView.TextBuffer); Assert.Null(file.CommitSha); }
public void RepoChangedHandlesNullRepository() { var teService = new FakeTeamExplorerServiceHolder(CreateRepositoryModel()); var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), teService); teService.ActiveRepo = null; Assert.Null(target.CurrentSession); }
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); }
public void RepoChangedHandlesNullRepository() { var teamExplorerContext = CreateTeamExplorerContext(CreateRepositoryModel()); var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), teamExplorerContext); SetActiveRepository(teamExplorerContext, null); Assert.That(target.CurrentSession, Is.Null); }
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)); }
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 GetSessionReturnsAndUpdatesCurrentSessionIfNumbersMatch() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber); var result = await target.GetSession(newModel); Assert.Same(target.CurrentSession, result); Assert.Same(target.CurrentSession.PullRequest, newModel); }
public void CurrentSessionIsNullIfNoPullRequestForCurrentBranch() { var service = CreatePullRequestService(); service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty <Tuple <string, int> >()); var target = new PullRequestSessionManager( service, Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); Assert.Null(target.CurrentSession); }
public async Task GetSessionReturnsSameSessionEachTime() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber); var result1 = await target.GetSession(newModel); var result2 = await target.GetSession(newModel); Assert.Same(result1, result2); }
public async Task GetSessionReturnsNewSessionForPullRequestWithDifferentBaseOwner() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber, "https://github.com/fork/repo"); var result = await target.GetSession(newModel); Assert.NotSame(target.CurrentSession, result); Assert.Same(result.PullRequest, newModel); Assert.False(result.IsCheckedOut); }
public async Task GetSessionReturnsAndUpdatesCurrentSessionIfNumbersMatch() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), CreateTeamExplorerContext(CreateRepositoryModel())); var newModel = CreatePullRequestModel(CurrentBranchPullRequestNumber); var result = await target.GetSession(newModel); Assert.That(target.CurrentSession, Is.SameAs(result)); Assert.That(result.PullRequest, Is.SameAs(newModel)); }
public void CurrentSessionIsNullIfNoPullRequestForCurrentBranch() { var service = CreatePullRequestService(); service.GetPullRequestForCurrentBranch(null).ReturnsForAnyArgs(Observable.Empty <Tuple <string, int> >()); var target = new PullRequestSessionManager( service, Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), CreateTeamExplorerContext(CreateRepositoryModel())); Assert.That(target.CurrentSession, Is.Null); }
public void CurrentSessionChangesWhenRepoChanged() { var teService = new FakeTeamExplorerServiceHolder(CreateRepositoryModel()); var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), teService); var session = target.CurrentSession; teService.ActiveRepo = CreateRepositoryModel("https://github.com/owner/other"); Assert.NotSame(session, target.CurrentSession); }
public void RepoChangedDoesntCreateNewSessionIfNotNecessary() { var teService = new FakeTeamExplorerServiceHolder(CreateRepositoryModel()); var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateRepositoryHosts(), teService); var session = target.CurrentSession; teService.NotifyActiveRepoChanged(); Assert.Same(session, target.CurrentSession); }
public async Task GetSessionReturnsSameSessionEachTime() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), CreateTeamExplorerContext(CreateRepositoryModel())); var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber); var result1 = await target.GetSession(newModel); var result2 = await target.GetSession(newModel); Assert.That(result1, Is.SameAs(result2)); }
public async Task GetSessionReturnsNewSessionForPullRequestWithDifferentNumber() { var target = new PullRequestSessionManager( CreatePullRequestService(), Substitute.For <IPullRequestSessionService>(), CreateConnectionManager(), CreateModelServiceFactory(), new FakeTeamExplorerServiceHolder(CreateRepositoryModel())); var newModel = CreatePullRequestModel(NotCurrentBranchPullRequestNumber); var result = await target.GetSession(newModel); Assert.NotSame(target.CurrentSession, result); Assert.Same(result.PullRequest, newModel); Assert.False(result.IsCheckedOut); }