public void OnTextViewClosed_UnsubscribesAfterLastTextViewClosed() { // Arrange var textView1 = Mock.Of <ITextView>(); var textView2 = Mock.Of <ITextView>(); var buffers = new Collection <ITextBuffer>() { Mock.Of <ITextBuffer>(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection()), Mock.Of <ITextBuffer>(b => b.ContentType == NonRazorCoreContentType && b.Properties == new PropertyCollection()), }; var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, buffers[0], ImportDocumentManager); buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker); var editorFactoryService = Mock.Of <RazorEditorFactoryService>(); var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService); // Populate the text views documentTracker.Subscribe(); documentTracker.AddTextView(textView1); documentTracker.AddTextView(textView2); // Act 1 documentManager.OnTextViewClosed(textView2, buffers); // Assert 1 Assert.True(documentTracker.IsSupportedProject); // Act documentManager.OnTextViewClosed(textView1, buffers); // Assert 2 Assert.False(documentTracker.IsSupportedProject); }
public void OnTextViewClosed_TextViewWithoutDocumentTracker_DoesNothing() { // Arrange var documentManager = new DefaultRazorDocumentManager(Dispatcher, Mock.Of <RazorEditorFactoryService>()); var textView = Mock.Of <ITextView>(); var buffers = new Collection <ITextBuffer>() { Mock.Of <ITextBuffer>(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection()), }; // Act documentManager.OnTextViewClosed(textView, buffers); // Assert Assert.False(buffers[0].Properties.ContainsProperty(typeof(VisualStudioDocumentTracker))); }
public void OnTextViewClosed_ForAnyTextBufferWithTracker_RemovesTextView() { // Arrange var textView1 = Mock.Of <ITextView>(); var textView2 = Mock.Of <ITextView>(); var buffers = new Collection <ITextBuffer>() { Mock.Of <ITextBuffer>(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection()), Mock.Of <ITextBuffer>(b => b.ContentType == NonRazorCoreContentType && b.Properties == new PropertyCollection()), }; // Preload the buffer's properties with a tracker, so it's like we've already tracked this one. var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, buffers[0], ImportDocumentManager); documentTracker.AddTextView(textView1); documentTracker.AddTextView(textView2); buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker); documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, buffers[1], ImportDocumentManager); documentTracker.AddTextView(textView1); documentTracker.AddTextView(textView2); buffers[1].Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker); var editorFactoryService = Mock.Of <RazorEditorFactoryService>(); var documentManager = new DefaultRazorDocumentManager(Dispatcher, editorFactoryService); // Act documentManager.OnTextViewClosed(textView2, buffers); // Assert documentTracker = buffers[0].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker)); Assert.Collection(documentTracker.TextViews, v => Assert.Same(v, textView1)); documentTracker = buffers[1].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker)); Assert.Collection(documentTracker.TextViews, v => Assert.Same(v, textView1)); }