Пример #1
0
        public void SubjectBuffersConnected_ForRazorTextBufferWithoutTracker_CreatesTrackerAndTracksTextView_ForMultipleBuffers()
        {
            // Arrange
            var factory = new DefaultVisualStudioDocumentTrackerFactory(Dispatcher, ProjectManager, ProjectService, Workspace);

            var textView = 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()),
                Mock.Of <ITextBuffer>(b => b.ContentType == RazorContentType && b.Properties == new PropertyCollection()),
            };

            // Act
            factory.SubjectBuffersConnected(textView, ConnectionReason.BufferGraphChange, buffers);

            // Assert
            var tracker = buffers[0].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker));

            Assert.Collection(tracker.TextViews, v => Assert.Same(v, textView));
            Assert.Equal(buffers[0], tracker.TextBuffer);

            Assert.False(buffers[1].Properties.ContainsProperty(typeof(VisualStudioDocumentTracker)));

            tracker = buffers[2].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker));
            Assert.Collection(tracker.TextViews, v => Assert.Same(v, textView));
            Assert.Equal(buffers[2], tracker.TextBuffer);
        }
Пример #2
0
        public void GetTracker_ForRazorTextBufferWithTracker_ReturnsTheFirstTracker()
        {
            // Arrange
            var factory = new DefaultVisualStudioDocumentTrackerFactory(Dispatcher, ProjectManager, ProjectService, Workspace);

            var buffers = new Collection <ITextBuffer>()
            {
                Mock.Of <ITextBuffer>(b => b.ContentType == RazorContentType && b.Properties == new PropertyCollection()),
            };

            var bufferGraph = Mock.Of <IBufferGraph>(g => g.GetTextBuffers(It.IsAny <Predicate <ITextBuffer> >()) == buffers);

            var textView = Mock.Of <IWpfTextView>(v => v.BufferGraph == bufferGraph);

            // Preload the buffer's properties with a tracker, so it's like we've already tracked this one.
            var tracker = new DefaultVisualStudioDocumentTracker(ProjectManager, ProjectService, Workspace, buffers[0]);

            tracker.TextViewsInternal.Add(textView);
            buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), tracker);

            // Act
            var result = factory.GetTracker(textView);

            // Assert
            Assert.Same(tracker, result);
        }
Пример #3
0
        public void SubjectBuffersConnected_ForRazorTextBufferWithTracker_AddsEntryForADifferentTextView()
        {
            // Arrange
            var factory = new DefaultVisualStudioDocumentTrackerFactory(Dispatcher, ProjectManager, ProjectService, Workspace);

            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()),
            };

            // Preload the buffer's properties with a tracker, so it's like we've already tracked this one.
            var tracker = new DefaultVisualStudioDocumentTracker(ProjectManager, ProjectService, Workspace, buffers[0]);

            tracker.TextViewsInternal.Add(textView1);
            buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), tracker);

            // Act
            factory.SubjectBuffersConnected(textView2, ConnectionReason.BufferGraphChange, buffers);

            // Assert
            Assert.Same(tracker, buffers[0].Properties.GetProperty <DefaultVisualStudioDocumentTracker>(typeof(VisualStudioDocumentTracker)));
            Assert.Collection(tracker.TextViews, v => Assert.Same(v, textView1), v => Assert.Same(v, textView2));
        }
Пример #4
0
        public void GetTracker_WithoutRazorBuffer_ReturnsNull()
        {
            // Arrange
            var factory = new DefaultVisualStudioDocumentTrackerFactory(Dispatcher, ProjectManager, ProjectService, Workspace);

            var buffers = new Collection <ITextBuffer>();

            var bufferGraph = Mock.Of <IBufferGraph>(g => g.GetTextBuffers(It.IsAny <Predicate <ITextBuffer> >()) == buffers);

            var textView = Mock.Of <IWpfTextView>(v => v.BufferGraph == bufferGraph);

            // Act
            var result = factory.GetTracker(textView);

            // Assert
            Assert.Null(result);
        }
Пример #5
0
        public void SubjectBuffersConnected_ForNonRazorTextBuffer_DoesNothing()
        {
            // Arrange
            var factory = new DefaultVisualStudioDocumentTrackerFactory(Dispatcher, ProjectManager, ProjectService, Workspace);

            var textView = Mock.Of <IWpfTextView>();

            var buffers = new Collection <ITextBuffer>()
            {
                Mock.Of <ITextBuffer>(b => b.ContentType == NonRazorContentType && b.Properties == new PropertyCollection()),
            };

            // Act
            factory.SubjectBuffersConnected(textView, ConnectionReason.BufferGraphChange, buffers);

            // Assert
            Assert.False(buffers[0].Properties.ContainsProperty(typeof(VisualStudioDocumentTracker)));
        }