Exemplo n.º 1
0
        public void UpdateVirtualDocument_Noops_UnknownDocument()
        {
            // Arrange
            var manager       = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, ChangeTriggers);
            var changedCalled = false;

            manager.Changed += (sender, args) =>
            {
                changedCalled = true;
            };
            var changes = new[] { new VisualStudioTextChange(1, 1, string.Empty) };

            // Act
            manager.UpdateVirtualDocument <TestVirtualDocument>(Uri, changes, 123);

            // Assert
            Assert.False(changedCalled);
        }
        public void UpdateVirtualDocument_Noops_UnknownDocument()
        {
            // Arrange
            var changeListenerLazy = CreateChangeListenerForContentTypes(new[] { LSPDocumentSnapshot.Snapshot.ContentType.TypeName });

            var changeListenerMock = Mock.Get(changeListenerLazy.Value);

            changeListenerMock.Setup(l => l.Changed(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <LSPDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <LSPDocumentChangeKind>()));

            var manager = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, new[] { changeListenerLazy });
            var changes = new[] { new VisualStudioTextChange(1, 1, string.Empty) };

            // Act
            manager.UpdateVirtualDocument <TestVirtualDocument>(Uri, changes, 123, state: null);

            // Assert
            changeListenerMock.Verify(l => l.Changed(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <LSPDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <LSPDocumentChangeKind>()),
                                      Times.Never);
        }
Exemplo n.º 3
0
        public void TrackDocument_TriggersDocumentAdded()
        {
            // Arrange
            var manager       = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, ChangeTriggers);
            var changedCalled = false;

            manager.Changed += (sender, args) =>
            {
                changedCalled = true;
                Assert.Null(args.Old);
                Assert.Same(LSPDocumentSnapshot, args.New);
                Assert.Equal(LSPDocumentChangeKind.Added, args.Kind);
            };

            // Act
            manager.TrackDocument(TextBuffer);

            // Assert
            Assert.True(changedCalled);
        }
Exemplo n.º 4
0
        public void UpdateVirtualDocument_Noops_NoChangesSameVersion()
        {
            // Arrange
            var manager = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, ChangeTriggers);

            manager.TrackDocument(TextBuffer);
            var changedCalled = false;

            manager.Changed += (sender, args) =>
            {
                changedCalled = true;
            };
            var changes = Array.Empty <ITextChange>();

            // Act
            manager.UpdateVirtualDocument <TestVirtualDocument>(Uri, changes, 123);

            // Assert
            Assert.False(changedCalled);
        }
        public void UpdateVirtualDocument_Noops_NoChangesSameVersion()
        {
            // Arrange
            var changeListenerLazy = CreateChangeListenerForContentTypes(new[] { LSPDocumentSnapshot.Snapshot.ContentType.TypeName });

            var changeListenerMock = Mock.Get(changeListenerLazy.Value);

            changeListenerMock.Setup(l => l.Changed(null, LSPDocumentSnapshot, It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), LSPDocumentChangeKind.Added));
            changeListenerMock.Setup(l => l.Changed(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <LSPDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), LSPDocumentChangeKind.VirtualDocumentChanged));

            var manager = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, new[] { changeListenerLazy });

            manager.TrackDocument(TextBuffer);

            var changes = Array.Empty <ITextChange>();

            // Act
            manager.UpdateVirtualDocument <TestVirtualDocument>(Uri, changes, 123, state: null);

            // Assert
            changeListenerMock.Verify(l => l.Changed(It.IsAny <LSPDocumentSnapshot>(), It.IsAny <LSPDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), LSPDocumentChangeKind.VirtualDocumentChanged),
                                      Times.Never);
        }
Exemplo n.º 6
0
        public void UpdateVirtualDocument_InvokesVirtualDocumentChanged()
        {
            // Arrange
            var manager = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, ChangeTriggers);

            manager.TrackDocument(TextBuffer);
            var changedCalled = false;

            manager.Changed += (sender, args) =>
            {
                changedCalled = true;
                Assert.Same(LSPDocumentSnapshot, args.Old);
                Assert.NotSame(LSPDocumentSnapshot, args.New);
                Assert.Equal(LSPDocumentChangeKind.VirtualDocumentChanged, args.Kind);
            };
            var changes = new[] { new VisualStudioTextChange(1, 1, string.Empty) };

            // Act
            manager.UpdateVirtualDocument <TestVirtualDocument>(Uri, changes, 123);

            // Assert
            Assert.True(changedCalled);
        }
        public void UntrackDocument_TriggersDocumentRemoved()
        {
            // Arrange
            var changeListenerLazy = CreateChangeListenerForContentTypes(new[] { LSPDocumentSnapshot.Snapshot.ContentType.TypeName });

            var changeListenerMock = Mock.Get(changeListenerLazy.Value);

            changeListenerMock.Setup(l => l.Changed(null, LSPDocumentSnapshot, It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), LSPDocumentChangeKind.Added));
            changeListenerMock.Setup(l => l.Changed(LSPDocumentSnapshot, null, It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), LSPDocumentChangeKind.Removed));

            var manager = new DefaultLSPDocumentManager(JoinableTaskContext, UriProvider, LSPDocumentFactory, new[] { changeListenerLazy });

            manager.TrackDocument(TextBuffer);

            // We're untracking which is typically paired with the buffer going to the inert content type, lets emulate that to ensure document removed happens.
            TextBuffer.ChangeContentType(TestInertContentType.Instance, editTag: false);

            // Act
            manager.UntrackDocument(TextBuffer);

            // Assert
            changeListenerMock.Verify(l => l.Changed(LSPDocumentSnapshot, null, It.IsAny <VirtualDocumentSnapshot>(), It.IsAny <VirtualDocumentSnapshot>(), LSPDocumentChangeKind.Removed),
                                      Times.Once);
        }