Ejemplo n.º 1
0
        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 AddTextView_DoesNotAddDuplicateTextViews()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(FilePath, ProjectManager, ProjectService, EditorSettingsManager, Workspace, TextBuffer);
            var textView        = Mock.Of <ITextView>();

            // Act
            documentTracker.AddTextView(textView);
            documentTracker.AddTextView(textView);

            // Assert
            Assert.Collection(documentTracker.TextViews, v => Assert.Same(v, textView));
        }
        public void RemoveTextView_RemovesTextViewFromCollection_MultipleItems()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(FilePath, ProjectManager, ProjectService, EditorSettingsManager, Workspace, TextBuffer);
            var textView1       = Mock.Of <ITextView>();
            var textView2       = Mock.Of <ITextView>();
            var textView3       = Mock.Of <ITextView>();

            documentTracker.AddTextView(textView1);
            documentTracker.AddTextView(textView2);
            documentTracker.AddTextView(textView3);

            // Act
            documentTracker.RemoveTextView(textView2);

            // Assert
            Assert.Collection(
                documentTracker.TextViews,
                v => Assert.Same(v, textView1),
                v => Assert.Same(v, textView3));
        }
        public void RemoveTextView_UnsubscribesAfterLastTextViewRemoved()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(FilePath, ProjectManager, ProjectService, EditorSettingsManager, Workspace, TextBuffer);
            var textView1       = Mock.Of <ITextView>();
            var textView2       = Mock.Of <ITextView>();

            documentTracker.AddTextView(textView1);
            documentTracker.AddTextView(textView2);

            // Act - 1
            documentTracker.RemoveTextView(textView1);

            // Assert - 1
            Assert.True(documentTracker.IsSupportedProject);

            // Act - 2
            documentTracker.RemoveTextView(textView2);

            // Assert - 2
            Assert.False(documentTracker.IsSupportedProject);
        }
        public void RemoveTextView_RemovesTextViewFromCollection_SingleItem()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(FilePath, ProjectManager, ProjectService, EditorSettingsManager, Workspace, TextBuffer);
            var textView        = Mock.Of <ITextView>();

            documentTracker.AddTextView(textView);

            // Act
            documentTracker.RemoveTextView(textView);

            // Assert
            Assert.Empty(documentTracker.TextViews);
        }
        public void AddTextView_SubscribesAfterFirstTextViewAdded()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(FilePath, ProjectManager, ProjectService, EditorSettingsManager, Workspace, TextBuffer);
            var textView        = Mock.Of <ITextView>();

            // Assert - 1
            Assert.False(documentTracker.IsSupportedProject);

            // Act
            documentTracker.AddTextView(textView);

            // Assert - 2
            Assert.True(documentTracker.IsSupportedProject);
        }