public void SubjectBuffersDisconnected_ForAnyTextBufferWithTracker_RemovesTextView() { // Arrange var textView1 = Mock.Of <IWpfTextView>(); var textView2 = Mock.Of <IWpfTextView>(); var buffers = new Collection <ITextBuffer>() { Mock.Of <ITextBuffer>(b => b.ContentType == RazorContentType && b.Properties == new PropertyCollection()), Mock.Of <ITextBuffer>(b => b.ContentType == NonRazorContentType && b.Properties == new PropertyCollection()), }; // Preload the buffer's properties with a tracker, so it's like we've already tracked this one. var tracker = new DefaultVisualStudioDocumentTracker("C:/File/Path/To/Tracker1.cshtml", ProjectManager, ProjectService, EditorSettingsManager, Workspace, buffers[0]); tracker.AddTextView(textView1); tracker.AddTextView(textView2); buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), tracker); tracker = new DefaultVisualStudioDocumentTracker("C:/File/Path/To/Tracker1.cshtml", ProjectManager, ProjectService, EditorSettingsManager, Workspace, buffers[1]); tracker.AddTextView(textView1); tracker.AddTextView(textView2); buffers[1].Properties.AddProperty(typeof(VisualStudioDocumentTracker), tracker); var textViewListener = new RazorTextViewConnectionListener(Dispatcher, Mock.Of <RazorEditorFactoryService>(), Workspace); // Act textViewListener.SubjectBuffersDisconnected(textView2, ConnectionReason.BufferGraphChange, buffers); // Assert tracker = buffers[0].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker)); Assert.Collection(tracker.TextViews, v => Assert.Same(v, textView1)); tracker = buffers[1].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker)); Assert.Collection(tracker.TextViews, v => Assert.Same(v, textView1)); }
public void SubjectBuffersDisconnected_ForAnyTextBufferWithoutTracker_DoesNothing() { // Arrange var textViewListener = new RazorTextViewConnectionListener(Dispatcher, Mock.Of <RazorEditorFactoryService>(), Workspace); var textView = Mock.Of <IWpfTextView>(); var buffers = new Collection <ITextBuffer>() { Mock.Of <ITextBuffer>(b => b.ContentType == RazorContentType && b.Properties == new PropertyCollection()), }; // Act textViewListener.SubjectBuffersDisconnected(textView, ConnectionReason.BufferGraphChange, buffers); // Assert Assert.False(buffers[0].Properties.ContainsProperty(typeof(VisualStudioDocumentTracker))); }