public async Task ShouldGetRelativePathFromTextBufferInfoIfPresent() { var session = CreateSession(); var bufferInfo = new PullRequestTextBufferInfo(session, RelativePath, "123", DiffSide.Right); var sessionManager = CreateSessionManager( relativePath: "ShouldNotUseThis", session: session, textBufferInfo: bufferInfo); // There is an existing comment thread at line 10. var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), CreatePeekSession(), sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); // There should be an existing comment and a reply placeholder. Assert.That(target.Thread.IsNewThread, Is.False); Assert.That(target.Thread.Comments.Count, Is.EqualTo(2)); Assert.That(target.Thread.Comments[0].Body, Is.EqualTo("Existing comment")); Assert.That(target.Thread.Comments[1].Body, Is.EqualTo(null)); Assert.That(target.Thread.Comments[1].EditState, Is.EqualTo(CommentEditState.Placeholder)); }
public async Task SwitchesFromNewThreadToExistingThreadWhenCommentPosted() { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreateApiClientFactory(), CreatePeekService(lineNumber: 8), peekSession, sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.IsType <NewInlineCommentThreadViewModel>(target.Thread); target.Thread.Comments[0].Body = "New Comment"; sessionManager.CurrentSession .When(x => x.PostReviewComment(Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <int>())) .Do(async x => { // Simulate the thread being added to the session. var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); var newThread = CreateThread(8, "New Comment"); file.InlineCommentThreads.Returns(new[] { newThread }); }); await target.Thread.Comments[0].CommitEdit.ExecuteAsyncTask(null); Assert.IsType <InlineCommentThreadViewModel>(target.Thread); }
public async Task RetainsCommentBeingEditedWhenSessionRefreshed() { using (TestUtils.WithScheduler(Scheduler.CurrentThread)) { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), CreatePeekSession(), sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); Assert.That(target.Thread.Comments.Count, Is.EqualTo(2)); var placeholder = target.Thread.Comments.Last(); placeholder.BeginEdit.Execute().Subscribe(); placeholder.Body = "Comment being edited"; var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); AddCommentToExistingThread(file); placeholder = target.Thread.Comments.Last(); Assert.That(target.Thread.Comments.Count, Is.EqualTo(3)); Assert.That(placeholder.EditState, Is.EqualTo(CommentEditState.Editing)); Assert.That(placeholder.Body, Is.EqualTo("Comment being edited")); } }
public async Task DoesntRetainSubmittedCommentInPlaceholderAfterPost() { var sessionManager = CreateSessionManager(); var target = new InlineCommentPeekViewModel( CreateApiClientFactory(), CreatePeekService(lineNumber: 10), CreatePeekSession(), sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.Equal(2, target.Thread.Comments.Count); sessionManager.CurrentSession.AddComment(null) .ReturnsForAnyArgs(async x => { var file = await sessionManager.CurrentSession.GetFile(RelativePath); AddCommentToExistingThread(file); }); var placeholder = target.Thread.Comments.Last(); placeholder.BeginEdit.Execute(null); placeholder.Body = "Comment being edited"; placeholder.CommitEdit.Execute(null); placeholder = target.Thread.Comments.Last(); Assert.Equal(CommentEditState.Placeholder, placeholder.EditState); Assert.Equal(string.Empty, placeholder.Body); }
public async Task RefreshesWhenSessionInlineCommentThreadsChanges() { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), peekSession, sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); Assert.That(target.Thread.IsNewThread, Is.False); Assert.That(target.Thread.Comments.Count, Is.EqualTo(2)); var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); AddCommentToExistingThread(file); Assert.That(target.Thread.Comments.Count, Is.EqualTo(3)); }
public async Task StartingReviewDoesntRetainSubmittedCommentInPlaceholderAfterPost() { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), peekSession, sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.That(target.Thread.Comments.Count, Is.EqualTo(2)); sessionManager.CurrentSession.StartReview() .ReturnsForAnyArgs(async x => { var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); RaiseLinesChanged(file, Tuple.Create(10, DiffSide.Right)); }); var placeholder = (IPullRequestReviewCommentViewModel)target.Thread.Comments.Last(); placeholder.BeginEdit.Execute(null); placeholder.Body = "Comment being edited"; placeholder.StartReview.Execute(null); placeholder = (IPullRequestReviewCommentViewModel)target.Thread.Comments.Last(); Assert.That(placeholder.EditState, Is.EqualTo(CommentEditState.Placeholder)); Assert.That(placeholder.Body, Is.EqualTo(string.Empty)); }
public async Task RetainsCommentBeingEditedWhenSessionRefreshed() { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( Substitute.For <IApiClientFactory>(), CreatePeekService(lineNumber: 10), CreatePeekSession(), sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.Equal(2, target.Thread.Comments.Count); var placeholder = target.Thread.Comments.Last(); placeholder.BeginEdit.Execute(null); placeholder.Body = "Comment being edited"; var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); AddCommentToExistingThread(file); placeholder = target.Thread.Comments.Last(); Assert.Equal(3, target.Thread.Comments.Count); Assert.Equal(CommentEditState.Editing, placeholder.EditState); Assert.Equal("Comment being edited", placeholder.Body); }
public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems) { if (session.RelationshipName == InlineCommentPeekRelationship.Instance.Name) { var viewModel = new InlineCommentPeekViewModel( peekService, session, sessionManager, nextCommentCommand, previousCommentCommand); viewModel.Initialize().Forget(); peekableItems.Add(new InlineCommentPeekableItem(viewModel)); } }
public async Task ThreadIsCreatedForNewComment() { // There is no existing comment thread at line 9, but there is a + diff entry. var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 9), CreatePeekSession(), CreateSessionManager(), Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.That(target.Thread, Is.InstanceOf(typeof(NewInlineCommentThreadViewModel))); Assert.That(string.Empty, Is.EqualTo(target.Thread.Comments[0].Body)); Assert.That(CommentEditState.Editing, Is.EqualTo(target.Thread.Comments[0].EditState)); }
public async Task ThreadIsCreatedForNewComment() { // There is no existing comment thread at line 9, but there is a + diff entry. var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 9), CreatePeekSession(), CreateSessionManager(), Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); Assert.That(target.Thread.IsNewThread, Is.True); Assert.That(target.Thread.Comments[0].Body, Is.EqualTo(null)); Assert.That(target.Thread.Comments[0].EditState, Is.EqualTo(CommentEditState.Editing)); }
public async Task ThreadIsCreatedForNewComment() { // There is no existing comment thread at line 9, but there is a + diff entry. var target = new InlineCommentPeekViewModel( Substitute.For <IApiClientFactory>(), CreatePeekService(lineNumber: 9), CreatePeekSession(), CreateSessionManager(), Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.IsType <NewInlineCommentThreadViewModel>(target.Thread); Assert.Equal(string.Empty, target.Thread.Comments[0].Body); Assert.Equal(CommentEditState.Editing, target.Thread.Comments[0].EditState); }
public async Task SwitchesFromNewThreadToExistingThreadWhenCommentPosted() { using (TestUtils.WithScheduler(Scheduler.CurrentThread)) { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 8), peekSession, sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); Assert.That(target.Thread.IsNewThread, Is.True); target.Thread.Comments[0].Body = "New Comment"; sessionManager.CurrentSession .When(x => x.PostReviewComment( Arg.Any <string>(), Arg.Any <string>(), Arg.Any <string>(), Arg.Any <IReadOnlyList <DiffChunk> >(), Arg.Any <int>())) .Do(async _ => { // Simulate the thread being added to the session. var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); var newThread = CreateThread(8, "New Comment"); file.InlineCommentThreads.Returns(new[] { newThread }); RaiseLinesChanged(file, Tuple.Create(8, DiffSide.Right)); }); await target.Thread.Comments[0].CommitEdit.Execute(); Assert.That(target.Thread.IsNewThread, Is.False); } }
public async Task ThreadIsCreatedForExistingComments() { // There is an existing comment thread at line 10. var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), CreatePeekSession(), CreateSessionManager(), Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); // There should be an existing comment and a reply placeholder. Assert.That(target.Thread, Is.InstanceOf(typeof(InlineCommentThreadViewModel))); Assert.That(2, Is.EqualTo(target.Thread.Comments.Count)); Assert.That("Existing comment", Is.EqualTo(target.Thread.Comments[0].Body)); Assert.That(string.Empty, Is.EqualTo(target.Thread.Comments[1].Body)); Assert.That(CommentEditState.Placeholder, Is.EqualTo(target.Thread.Comments[1].EditState)); }
public async Task ThreadIsCreatedForExistingComments() { // There is an existing comment thread at line 10. var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), CreatePeekSession(), CreateSessionManager(), Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); // There should be an existing comment and a reply placeholder. Assert.That(target.Thread.IsNewThread, Is.False); Assert.That(target.Thread.Comments.Count, Is.EqualTo(2)); Assert.That(target.Thread.Comments[0].Body, Is.EqualTo("Existing comment")); Assert.That(target.Thread.Comments[1].Body, Is.EqualTo(null)); Assert.That(target.Thread.Comments[1].EditState, Is.EqualTo(CommentEditState.Placeholder)); }
public async Task ThreadIsCreatedForExistingComments() { // There is an existing comment thread at line 10. var target = new InlineCommentPeekViewModel( Substitute.For <IApiClientFactory>(), CreatePeekService(lineNumber: 10), CreatePeekSession(), CreateSessionManager(), Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); // There should be an existing comment and a reply placeholder. Assert.IsType <InlineCommentThreadViewModel>(target.Thread); Assert.Equal(2, target.Thread.Comments.Count); Assert.Equal("Existing comment", target.Thread.Comments[0].Body); Assert.Equal(string.Empty, target.Thread.Comments[1].Body); Assert.Equal(CommentEditState.Placeholder, target.Thread.Comments[1].EditState); }
public async Task CommittingEditDoesntRetainSubmittedCommentInPlaceholderAfterPost() { using (TestUtils.WithScheduler(Scheduler.CurrentThread)) { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), peekSession, sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>(), CreateFactory()); await target.Initialize(); Assert.That(target.Thread.Comments.Count, Is.EqualTo(2)); sessionManager.CurrentSession.PostReviewComment(null, null) .ReturnsForAnyArgs(async x => { var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); AddCommentToExistingThread(file); }); var placeholder = target.Thread.Comments.Last(); await placeholder.BeginEdit.Execute(); placeholder.Body = "Comment being edited"; await placeholder.CommitEdit.Execute(); placeholder = target.Thread.Comments.Last(); Assert.That(placeholder.EditState, Is.EqualTo(CommentEditState.Placeholder)); Assert.That(placeholder.Body, Is.EqualTo(null)); } }
public async Task RefreshesWhenSessionInlineCommentThreadsChanges() { var sessionManager = CreateSessionManager(); var target = new InlineCommentPeekViewModel( Substitute.For <IApiClientFactory>(), CreatePeekService(lineNumber: 10), CreatePeekSession(), sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.IsType <InlineCommentThreadViewModel>(target.Thread); Assert.Equal(2, target.Thread.Comments.Count); var file = await sessionManager.CurrentSession.GetFile(RelativePath); AddCommentToExistingThread(file); Assert.Equal(3, target.Thread.Comments.Count); }
public async Task DoesntRetainSubmittedCommentInPlaceholderAfterPost() { var sessionManager = CreateSessionManager(); var peekSession = CreatePeekSession(); var target = new InlineCommentPeekViewModel( CreatePeekService(lineNumber: 10), peekSession, sessionManager, Substitute.For <INextInlineCommentCommand>(), Substitute.For <IPreviousInlineCommentCommand>()); await target.Initialize(); Assert.That(2, Is.EqualTo(target.Thread.Comments.Count)); sessionManager.CurrentSession.PostReviewComment(null, 0) .ReturnsForAnyArgs(async x => { var file = await sessionManager.GetLiveFile( RelativePath, peekSession.TextView, peekSession.TextView.TextBuffer); AddCommentToExistingThread(file); return(file.InlineCommentThreads[0].Comments.Last()); }); var placeholder = target.Thread.Comments.Last(); placeholder.BeginEdit.Execute(null); placeholder.Body = "Comment being edited"; placeholder.CommitEdit.Execute(null); placeholder = target.Thread.Comments.Last(); Assert.That(CommentEditState.Placeholder, Is.EqualTo(placeholder.EditState)); Assert.That(string.Empty, Is.EqualTo(placeholder.Body)); }
public InlineCommentPeekResult(InlineCommentPeekViewModel viewModel) { Guard.ArgumentNotNull(viewModel, nameof(viewModel)); this.ViewModel = viewModel; }
public InlineCommentPeekResultPresentation(InlineCommentPeekViewModel viewModel) { this.viewModel = viewModel; }
public InlineCommentPeekableItem(InlineCommentPeekViewModel viewModel) { ViewModel = viewModel; }
public InlineCommentPeekableResultSource(InlineCommentPeekViewModel viewModel) { this.viewModel = viewModel; }