public async Task nTextViewClosed_UnsubscribesAfterLastTextViewClosed()
        {
            // Arrange
            var textView1 = Mock.Of <ITextView>(MockBehavior.Strict);
            var textView2 = Mock.Of <ITextView>(MockBehavior.Strict);
            var buffers   = new Collection <ITextBuffer>()
            {
                Mock.Of <ITextBuffer>(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection(), MockBehavior.Strict),
                Mock.Of <ITextBuffer>(b => b.ContentType == NonRazorCoreContentType && b.Properties == new PropertyCollection(), MockBehavior.Strict),
            };
            var documentTracker = new DefaultVisualStudioDocumentTracker(
                Dispatcher, JoinableTaskContext, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings,
                Workspace, buffers[0], ImportDocumentManager);

            buffers[0].Properties.AddProperty(typeof(VisualStudioDocumentTracker), documentTracker);
            var editorFactoryService = Mock.Of <RazorEditorFactoryService>(MockBehavior.Strict);
            var documentManager      = new DefaultRazorDocumentManager(Dispatcher, JoinableTaskContext, editorFactoryService);

            // Populate the text views
            documentTracker.Subscribe();
            documentTracker.AddTextView(textView1);
            documentTracker.AddTextView(textView2);

            // Act 1
            await documentManager.OnTextViewClosedAsync(textView2, buffers);

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

            // Act
            await documentManager.OnTextViewClosedAsync(textView1, buffers);

            // Assert 2
            Assert.False(documentTracker.IsSupportedProject);
        }
Esempio n. 2
0
        public void AddTextView_DoesNotAddDuplicateTextViews()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, TextBuffer, ImportDocumentManager);
            var textView        = Mock.Of <ITextView>();

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

            // Assert
            Assert.Collection(documentTracker.TextViews, v => Assert.Same(v, textView));
        }
Esempio n. 3
0
        public void AddTextView_AddsMultipleTextViewsToCollection()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(FilePath, ProjectPath, ProjectManager, EditorSettingsManager, Workspace, TextBuffer, ImportDocumentManager);
            var textView1       = Mock.Of <ITextView>();
            var textView2       = Mock.Of <ITextView>();

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

            // Assert
            Assert.Collection(
                documentTracker.TextViews,
                v => Assert.Same(v, textView1),
                v => Assert.Same(v, textView2));
        }
Esempio n. 4
0
        public void RemoveTextView_RemovesTextViewFromCollection_MultipleItems()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, TextBuffer, ImportDocumentManager);
            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 async Task OnTextViewClosed_ForAnyTextBufferWithTracker_RemovesTextView()
        {
            // Arrange
            var textView1 = Mock.Of <ITextView>(MockBehavior.Strict);
            var textView2 = Mock.Of <ITextView>(MockBehavior.Strict);
            var buffers   = new Collection <ITextBuffer>()
            {
                Mock.Of <ITextBuffer>(b => b.ContentType == RazorCoreContentType && b.Properties == new PropertyCollection(), MockBehavior.Strict),
                Mock.Of <ITextBuffer>(b => b.ContentType == NonRazorCoreContentType && b.Properties == new PropertyCollection(), MockBehavior.Strict),
            };

            // Preload the buffer's properties with a tracker, so it's like we've already tracked this one.
            var documentTracker = new DefaultVisualStudioDocumentTracker(
                Dispatcher, JoinableTaskContext, 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, JoinableTaskContext, 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>(MockBehavior.Strict);
            var documentManager      = new DefaultRazorDocumentManager(Dispatcher, JoinableTaskContext, editorFactoryService);

            // Act
            await documentManager.OnTextViewClosedAsync(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));
        }
Esempio n. 6
0
        public void RemoveTextView_RemovesTextViewFromCollection_SingleItem()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, WorkspaceEditorSettings, Workspace, TextBuffer, ImportDocumentManager);
            var textView        = Mock.Of <ITextView>();

            documentTracker.AddTextView(textView);

            // Act
            documentTracker.RemoveTextView(textView);

            // Assert
            Assert.Empty(documentTracker.TextViews);
        }
        public void RemoveTextView_NoopsWhenRemovingTextViewNotInCollection()
        {
            // Arrange
            var documentTracker = new DefaultVisualStudioDocumentTracker(Dispatcher, FilePath, ProjectPath, ProjectManager, EditorSettingsManager, Workspace, TextBuffer, ImportDocumentManager);
            var textView1       = Mock.Of <ITextView>();

            documentTracker.AddTextView(textView1);
            var textView2 = Mock.Of <ITextView>();

            // Act
            documentTracker.RemoveTextView(textView2);

            // Assert
            Assert.Collection(documentTracker.TextViews, v => Assert.Same(v, textView1));
        }