public void UpdateDocument_TracksKnownDocumentVersion()
        {
            // Arrange
            var documentFilePath = "/C:/path/to/document.cshtml";
            var ownerProject     = TestProjectSnapshot.Create("/C:/path/to/project.csproj", new[] { documentFilePath });
            var projectResolver  = new TestProjectResolver(
                new Dictionary <string, ProjectSnapshot>
            {
                [documentFilePath] = ownerProject
            },
                TestProjectSnapshot.Create("/__MISC_PROJECT__"));
            DocumentSnapshot documentSnapshot = TestDocumentSnapshot.Create(documentFilePath);
            var documentResolver     = Mock.Of <DocumentResolver>(resolver => resolver.TryResolveDocument(It.IsAny <string>(), out documentSnapshot) == true);
            var documentVersionCache = new Mock <DocumentVersionCache>(MockBehavior.Strict);

            documentVersionCache.Setup(cache => cache.TrackDocumentVersion(documentSnapshot, It.IsAny <long>()))
            .Callback <DocumentSnapshot, long>((snapshot, version) =>
            {
                Assert.Same(documentSnapshot, snapshot);
                Assert.Equal(1337, version);
            });
            var newText        = SourceText.From("Something New");
            var projectService = CreateProjectService(
                projectResolver,
                Mock.Of <ProjectSnapshotManagerBase>(),
                documentResolver,
                documentVersionCache.Object);

            // Act
            projectService.UpdateDocument(documentFilePath, newText, 1337);

            // Assert
            documentVersionCache.VerifyAll();
        }
Ejemplo n.º 2
0
        public void ProjectSnapshotManager_WorkspacePopulated_SetsUIContext()
        {
            // Arrange
            var responseRouterReturns = new Mock <IResponseRouterReturns>(MockBehavior.Strict);

            responseRouterReturns.Setup(r => r.ReturningVoid(It.IsAny <CancellationToken>()))
            .Returns(() => Task.CompletedTask);

            var clientNotifierService = new Mock <ClientNotifierServiceBase>(MockBehavior.Strict);

            clientNotifierService.Setup(l => l.SendRequestAsync(_razorServerReadyEndpoint))
            .Returns(Task.FromResult(responseRouterReturns.Object));

            var razorServerReadyPublisher = new RazorServerReadyPublisher(Dispatcher, clientNotifierService.Object);

            var projectManager = TestProjectSnapshotManager.Create(Dispatcher);

            projectManager.AllowNotifyListeners = true;

            razorServerReadyPublisher.Initialize(projectManager);

            var document = TestDocumentSnapshot.Create("C:/file.cshtml");

            document.TryGetText(out var text);
            document.TryGetTextVersion(out var textVersion);
            var textAndVersion = TextAndVersion.Create(text, textVersion);

            // Act
            projectManager.ProjectAdded(document.ProjectInternal.HostProject);
            projectManager.ProjectWorkspaceStateChanged(document.ProjectInternal.HostProject.FilePath, CreateProjectWorkspace());

            // Assert
            clientNotifierService.VerifyAll();
            responseRouterReturns.VerifyAll();
        }
Ejemplo n.º 3
0
        public void DocumentProcessed_NewWorkQueued_RestartsTimer()
        {
            // Arrange
            var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath);
            var codeDocument          = CreateCodeDocument(SingleDiagnosticCollection);

            processedOpenDocument.With(codeDocument);
            var languageServerDocument = Mock.Of <ILanguageServerDocument>();
            var languageServer         = Mock.Of <ILanguageServer>(server => server.Document == languageServerDocument);

            using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer, LoggerFactory)
            {
                BlockBackgroundWorkCompleting = new ManualResetEventSlim(initialState: true),
                NotifyBackgroundWorkCompleting = new ManualResetEventSlim(initialState: false),
            })
            {
                publisher.Initialize(ProjectManager);
                publisher.DocumentProcessed(processedOpenDocument);
                Assert.True(publisher.NotifyBackgroundWorkCompleting.Wait(TimeSpan.FromSeconds(2)));
                publisher.NotifyBackgroundWorkCompleting.Reset();

                // Act
                publisher.DocumentProcessed(processedOpenDocument);
                publisher.BlockBackgroundWorkCompleting.Set();

                // Assert
                // Verify that background work starts completing "again"
                Assert.True(publisher.NotifyBackgroundWorkCompleting.Wait(TimeSpan.FromSeconds(2)));
            }
        }
Ejemplo n.º 4
0
        public void DocumentProcessed_DoesNothingIfAlreadySynchronized()
        {
            // Arrange
            var router          = new TestRouter();
            var documentVersion = VersionStamp.Default.GetNewerVersion();
            var document        = TestDocumentSnapshot.Create("C:/path/file.cshtml", documentVersion);
            var cache           = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>()
            {
                [document] = 1337,
            });
            var csharpDocument = RazorCSharpDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());

            // Force the state to already be up-to-date
            document.State.HostDocument.GeneratedCodeContainer.SetOutput(document, csharpDocument, documentVersion.GetNewerVersion(), VersionStamp.Default);

            var listener = new UnsynchronizableContentDocumentProcessedListener(Dispatcher, cache, router);

            listener.Initialize(ProjectSnapshotManager);

            // Act
            listener.DocumentProcessed(document);

            // Assert
            Assert.Empty(router.SynchronizedDocuments);
        }
Ejemplo n.º 5
0
        public void DocumentProcessed_SynchronizesIfSourceVersionsAreIdenticalButSyncVersionNewer()
        {
            // Arrange
            var router       = new TestRouter();
            var lastVersion  = VersionStamp.Default.GetNewerVersion();
            var lastDocument = TestDocumentSnapshot.Create("C:/path/old.cshtml", lastVersion);
            var document     = TestDocumentSnapshot.Create("C:/path/file.cshtml", lastVersion);
            var cache        = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>()
            {
                [document]     = 1338,
                [lastDocument] = 1337,
            });
            var csharpDocument = RazorCSharpDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());

            // Force the state to already be up-to-date
            document.State.HostDocument.GeneratedCodeContainer.SetOutput(lastDocument, csharpDocument, lastVersion, VersionStamp.Default);

            var listener = new UnsynchronizableContentDocumentProcessedListener(Dispatcher, cache, router);

            listener.Initialize(ProjectSnapshotManager);

            // Act
            listener.DocumentProcessed(document);

            // Assert
            var filePath = Assert.Single(router.SynchronizedDocuments);

            Assert.Equal(document.FilePath, filePath);
        }
        public void ReportUnsynchronizableContent_SynchronizesIfSourceVersionsAreIdenticalButSyncVersionNewer()
        {
            // Arrange
            var router       = new TestRouter();
            var lastVersion  = VersionStamp.Default.GetNewerVersion();
            var lastDocument = TestDocumentSnapshot.Create("C:/path/old.cshtml", lastVersion);
            var document     = TestDocumentSnapshot.Create("C:/path/file.cshtml", lastVersion);
            var cache        = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>()
            {
                [document]     = 1338,
                [lastDocument] = 1337,
            });
            var csharpDocument = RazorCSharpDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());

            // Force the state to already be up-to-date
            document.State.HostDocument.GeneratedCodeContainer.SetOutput(csharpDocument, lastDocument);

            var backgroundGenerator = new BackgroundDocumentGenerator(Dispatcher, cache, router, LoggerFactory);
            var work = new[] { new KeyValuePair <string, DocumentSnapshot>(document.FilePath, document) };

            // Act
            backgroundGenerator.ReportUnsynchronizableContent(work);

            // Assert
            var filePath = Assert.Single(router.SynchronizedDocuments);

            Assert.Equal(document.FilePath, filePath);
        }
Ejemplo n.º 7
0
        public void ProjectSnapshotManager_Changed_DocumentRemoved_DoesNotEvictDocument()
        {
            // Arrange
            var documentVersionCache   = new DefaultDocumentVersionCache(Dispatcher);
            var projectSnapshotManager = TestProjectSnapshotManager.Create(Dispatcher);

            projectSnapshotManager.AllowNotifyListeners = true;
            documentVersionCache.Initialize(projectSnapshotManager);
            var document = TestDocumentSnapshot.Create("C:/file.cshtml");

            document.TryGetText(out var text);
            document.TryGetTextVersion(out var textVersion);
            var textAndVersion = TextAndVersion.Create(text, textVersion);

            documentVersionCache.TrackDocumentVersion(document, 1337);
            projectSnapshotManager.ProjectAdded(document.ProjectInternal.HostProject);
            projectSnapshotManager.DocumentAdded(document.ProjectInternal.HostProject, document.State.HostDocument, TextLoader.From(textAndVersion));

            // Act - 1
            var result = documentVersionCache.TryGetDocumentVersion(document, out var version);

            // Assert - 1
            Assert.True(result);

            // Act - 2
            projectSnapshotManager.DocumentRemoved(document.ProjectInternal.HostProject, document.State.HostDocument);
            result = documentVersionCache.TryGetDocumentVersion(document, out version);

            // Assert - 2
            Assert.True(result);
        }
Ejemplo n.º 8
0
        public void DocumentProcessed_DoesNothingForOlderDocuments()
        {
            // Arrange
            var generatedDocumentPublisher = new Mock <GeneratedDocumentPublisher>(MockBehavior.Strict);
            var lastVersion  = VersionStamp.Default.GetNewerVersion();
            var lastDocument = TestDocumentSnapshot.Create("C:/path/old.cshtml", lastVersion);
            var oldDocument  = TestDocumentSnapshot.Create("C:/path/file.cshtml", VersionStamp.Default);
            var cache        = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, int?>()
            {
                [oldDocument]  = 1337,
                [lastDocument] = 1338,
            });
            var csharpDocument = RazorCSharpDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());
            var htmlDocument   = RazorHtmlDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault());
            var codeDocument   = CreateCodeDocument(csharpDocument, htmlDocument);

            // Force the state to already be up-to-date
            oldDocument.State.HostDocument.GeneratedDocumentContainer.SetOutput(lastDocument, codeDocument, lastVersion, VersionStamp.Default, VersionStamp.Default);

            var listener = new UnsynchronizableContentDocumentProcessedListener(Dispatcher, cache, generatedDocumentPublisher.Object);

            listener.Initialize(ProjectSnapshotManager);

            // Act & Assert
            listener.DocumentProcessed(oldDocument);
        }
Ejemplo n.º 9
0
        public void ProjectSnapshotManager_WorkspaceNull_DoesNothing()
        {
            // Arrange
            var clientNotifierService = new Mock <ClientNotifierServiceBase>(MockBehavior.Strict);

            var razorServerReadyPublisher = new RazorServerReadyPublisher(Dispatcher, clientNotifierService.Object);

            var projectManager = TestProjectSnapshotManager.Create(Dispatcher);

            projectManager.AllowNotifyListeners = true;

            razorServerReadyPublisher.Initialize(projectManager);

            var document = TestDocumentSnapshot.Create("C:/file.cshtml");

            document.TryGetText(out var text);
            document.TryGetTextVersion(out var textVersion);
            var textAndVersion = TextAndVersion.Create(text, textVersion);

            // Act
            projectManager.ProjectAdded(document.ProjectInternal.HostProject);
            projectManager.DocumentAdded(document.ProjectInternal.HostProject, document.State.HostDocument, TextLoader.From(textAndVersion));

            // Assert
            // Should not have been called
            clientNotifierService.Verify();
        }
        public void ReportUnsynchronizableContent_DoesNothingForOlderDocuments()
        {
            // Arrange
            var router       = new TestRouter();
            var lastVersion  = VersionStamp.Default.GetNewerVersion();
            var lastDocument = TestDocumentSnapshot.Create("C:/path/old.cshtml", lastVersion);
            var oldDocument  = TestDocumentSnapshot.Create("C:/path/file.cshtml", VersionStamp.Default);
            var cache        = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>()
            {
                [oldDocument]  = 1337,
                [lastDocument] = 1338,
            });
            var csharpDocument = RazorCSharpDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());

            // Force the state to already be up-to-date
            oldDocument.State.HostDocument.GeneratedCodeContainer.SetOutput(lastDocument, csharpDocument, lastVersion, VersionStamp.Default);

            var backgroundGenerator = new BackgroundDocumentGenerator(Dispatcher, cache, Listeners, router, LoggerFactory);
            var work = new[] { new KeyValuePair <string, DocumentSnapshot>(oldDocument.FilePath, oldDocument) };

            // Act
            backgroundGenerator.ReportUnsynchronizableContent(work);

            // Assert
            Assert.Empty(router.SynchronizedDocuments);
        }
Ejemplo n.º 11
0
        public void DocumentProcessed_SynchronizesIfSourceVersionsAreIdenticalButSyncVersionNewer()
        {
            // Arrange
            var lastVersion     = VersionStamp.Default.GetNewerVersion();
            var lastDocument    = TestDocumentSnapshot.Create("C:/path/old.cshtml", lastVersion);
            var document        = TestDocumentSnapshot.Create("C:/path/file.cshtml", lastVersion);
            var csharpPublisher = new Mock <CSharpPublisher>();

            csharpPublisher.Setup(publisher => publisher.Publish(It.IsAny <string>(), It.IsAny <SourceText>(), It.IsAny <long>()))
            .Callback <string, SourceText, long>((filePath, sourceText, hostDocumentVersion) =>
            {
                Assert.Equal(document.FilePath, filePath);
            })
            .Verifiable();
            var cache = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>()
            {
                [document]     = 1338,
                [lastDocument] = 1337,
            });
            var csharpDocument = RazorCSharpDocument.Create("Anything", RazorCodeGenerationOptions.CreateDefault(), Enumerable.Empty <RazorDiagnostic>());

            // Force the state to already be up-to-date
            document.State.HostDocument.GeneratedCodeContainer.SetOutput(lastDocument, csharpDocument, lastVersion, VersionStamp.Default);

            var listener = new UnsynchronizableContentDocumentProcessedListener(Dispatcher, cache, csharpPublisher.Object);

            listener.Initialize(ProjectSnapshotManager);

            // Act
            listener.DocumentProcessed(document);

            // Assert
            csharpPublisher.VerifyAll();
        }
        public void DocumentProcessed_NewWorkQueued_RestartsTimer()
        {
            // Arrange
            var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath);
            var codeDocument          = CreateCodeDocument(SingleDiagnosticCollection);

            processedOpenDocument.With(codeDocument);
            // ILanguageServerDocument
            var languageServerDocument = new Mock <ITextDocumentLanguageServer>(MockBehavior.Strict).Object;

            Mock.Get(languageServerDocument).Setup(d => d.SendNotification(It.IsAny <IRequest>())).Verifiable();
            using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServerDocument, LoggerFactory)
            {
                BlockBackgroundWorkCompleting = new ManualResetEventSlim(initialState: true),
                NotifyBackgroundWorkCompleting = new ManualResetEventSlim(initialState: false),
            })
            {
                publisher.Initialize(ProjectManager);
                publisher.DocumentProcessed(processedOpenDocument);
                Assert.True(publisher.NotifyBackgroundWorkCompleting.Wait(TimeSpan.FromSeconds(2)));
                publisher.NotifyBackgroundWorkCompleting.Reset();

                // Act
                publisher.DocumentProcessed(processedOpenDocument);
                publisher.BlockBackgroundWorkCompleting.Set();

                // Assert
                // Verify that background work starts completing "again"
                Assert.True(publisher.NotifyBackgroundWorkCompleting.Wait(TimeSpan.FromSeconds(2)));
            }
        }
        public async Task PublishDiagnosticsAsync_NewDocumentDiagnosticsGetPublished()
        {
            // Arrange
            var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath);
            var codeDocument          = CreateCodeDocument(SingleDiagnosticCollection);

            processedOpenDocument.With(codeDocument);
            var languageServerDocument = new Mock <ILanguageServerDocument>();

            languageServerDocument.Setup(lsd => lsd.SendNotification(It.IsAny <string>(), It.IsAny <PublishDiagnosticsParams>()))
            .Callback <string, PublishDiagnosticsParams>((method, diagnosticParams) =>
            {
                Assert.Equal(processedOpenDocument.FilePath.TrimStart('/'), diagnosticParams.Uri.AbsolutePath);
                var diagnostic      = Assert.Single(diagnosticParams.Diagnostics);
                var razorDiagnostic = SingleDiagnosticCollection[0];
                processedOpenDocument.TryGetText(out var sourceText);
                var expectedDiagnostic = RazorDiagnosticConverter.Convert(razorDiagnostic, sourceText);
                Assert.Equal(expectedDiagnostic.Message, diagnostic.Message);
                Assert.Equal(expectedDiagnostic.Severity, diagnostic.Severity);
                Assert.Equal(expectedDiagnostic.Range, diagnostic.Range);
            }).Verifiable();
            var languageServer = new Mock <ILanguageServer>();

            languageServer.Setup(server => server.Document).Returns(languageServerDocument.Object);
            using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory))
            {
                publisher.Initialize(ProjectManager);

                // Act
                await publisher.PublishDiagnosticsAsync(processedOpenDocument);

                // Assert
                languageServerDocument.VerifyAll();
            }
        }
        public async Task PublishDiagnosticsAsync_NewDiagnosticsGetPublished()
        {
            // Arrange
            var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath);
            var codeDocument          = CreateCodeDocument(SingleDiagnosticCollection);

            processedOpenDocument.With(codeDocument);
            var languageServer = new Mock <ITextDocumentLanguageServer>(MockBehavior.Strict);

            languageServer.Setup(server => server.SendNotification((It.IsAny <IRequest>()))).Callback <IRequest>((@params) =>
            {
                var diagnosticParams = (PublishDiagnosticsParams)@params;
                Assert.Equal(processedOpenDocument.FilePath.TrimStart('/'), diagnosticParams.Uri.ToUri().AbsolutePath);
                var diagnostic      = Assert.Single(diagnosticParams.Diagnostics);
                var razorDiagnostic = SingleDiagnosticCollection[0];
                processedOpenDocument.TryGetText(out var sourceText);
                var expectedDiagnostic = RazorDiagnosticConverter.Convert(razorDiagnostic, sourceText);
                Assert.Equal(expectedDiagnostic.Message, diagnostic.Message);
                Assert.Equal(expectedDiagnostic.Severity, diagnostic.Severity);
                Assert.Equal(expectedDiagnostic.Range, diagnostic.Range);
            });

            using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory))
            {
                publisher._publishedDiagnostics[processedOpenDocument.FilePath] = EmptyDiagnostics;
                publisher.Initialize(ProjectManager);

                // Act
                await publisher.PublishDiagnosticsAsync(processedOpenDocument);

                // Assert
                languageServer.VerifyAll();
            }
        }
Ejemplo n.º 15
0
        public void GetMappingBehavior_Razor()
        {
            // Arrange
            var documentPath     = "/path/to/document.razor";
            var documentSnapshot = TestDocumentSnapshot.Create(documentPath);

            // Act
            var result = RazorBreakpointSpanEndpoint.GetMappingBehavior(documentSnapshot);

            // Assert
            Assert.Equal(MappingBehavior.Strict, result);
        }
Ejemplo n.º 16
0
        public void GetMappingBehavior_CSHTML()
        {
            // Arrange
            var documentPath     = "/path/to/document.cshtml";
            var documentSnapshot = TestDocumentSnapshot.Create(documentPath);

            // Act
            var result = RazorBreakpointSpanEndpoint.GetMappingBehavior(documentSnapshot);

            // Assert
            Assert.Equal(MappingBehavior.Inclusive, result);
        }
Ejemplo n.º 17
0
        public void DocumentProcessed_DoesNothingForOldDocuments()
        {
            // Arrange
            var generatedDocumentPublisher = new Mock <GeneratedDocumentPublisher>(MockBehavior.Strict);
            var cache    = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, int?>());
            var listener = new UnsynchronizableContentDocumentProcessedListener(Dispatcher, cache, generatedDocumentPublisher.Object);

            listener.Initialize(ProjectSnapshotManager);
            var document = TestDocumentSnapshot.Create("C:/path/file.cshtml");

            // Act & Assert
            listener.DocumentProcessed(document);
        }
Ejemplo n.º 18
0
        public void TryGetDocumentVersion_UntrackedDocumentPath_ReturnsFalse()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");

            // Act
            var result = documentVersionCache.TryGetDocumentVersion(document, out var version);

            // Assert
            Assert.False(result);
            Assert.Null(version);
        }
Ejemplo n.º 19
0
        public void TryGetDocumentVersion_KnownDocument_ReturnsTrue()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");

            documentVersionCache.TrackDocumentVersion(document, 1337);

            // Act
            var result = documentVersionCache.TryGetDocumentVersion(document, out var version);

            // Assert
            Assert.True(result);
            Assert.Equal(1337, version);
        }
        public void ReportUnsynchronizableContent_DoesNothingForOldDocuments()
        {
            // Arrange
            var router = new TestRouter();
            var cache  = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>());
            var backgroundGenerator = new BackgroundDocumentGenerator(Dispatcher, cache, router, LoggerFactory);
            var document            = TestDocumentSnapshot.Create("C:/path/file.cshtml");
            var work = new[] { new KeyValuePair <string, DocumentSnapshot>(document.FilePath, document) };

            // Act
            backgroundGenerator.ReportUnsynchronizableContent(work);

            // Assert
            Assert.Empty(router.SynchronizedDocuments);
        }
Ejemplo n.º 21
0
        public void DocumentProcessed_DoesNothingForOldDocuments()
        {
            // Arrange
            var router   = new TestRouter();
            var cache    = new TestDocumentVersionCache(new Dictionary <DocumentSnapshot, long>());
            var listener = new UnsynchronizableContentDocumentProcessedListener(Dispatcher, cache, router);

            listener.Initialize(ProjectSnapshotManager);
            var document = TestDocumentSnapshot.Create("C:/path/file.cshtml");

            // Act
            listener.DocumentProcessed(document);

            // Assert
            Assert.Empty(router.SynchronizedDocuments);
        }
Ejemplo n.º 22
0
        public void MarkAsLatestVersion_KnownDocument_TracksNewDocumentAsLatest()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var documentInitial      = TestDocumentSnapshot.Create("C:/file.cshtml");

            documentVersionCache.TrackDocumentVersion(documentInitial, 123);
            var documentLatest = TestDocumentSnapshot.Create(documentInitial.FilePath);

            // Act
            documentVersionCache.MarkAsLatestVersion(documentLatest);

            // Assert
            Assert.True(documentVersionCache.TryGetDocumentVersion(documentLatest, out var version));
            Assert.Equal(123, version);
        }
Ejemplo n.º 23
0
        public void TryGetDocumentVersion_EvictedDocument_ReturnsFalse()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");
            var evictedDocument      = TestDocumentSnapshot.Create(document.FilePath);

            documentVersionCache.TrackDocumentVersion(document, 1337);

            // Act
            var result = documentVersionCache.TryGetDocumentVersion(evictedDocument, out var version);

            // Assert
            Assert.False(result);
            Assert.Equal(-1, version);
        }
Ejemplo n.º 24
0
        public void MarkAsLatestVersion_UntrackedDocument_Noops()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");

            documentVersionCache.TrackDocumentVersion(document, 123);
            var untrackedDocument = TestDocumentSnapshot.Create("C:/other.cshtml");

            // Act
            documentVersionCache.MarkAsLatestVersion(untrackedDocument);

            // Assert
            Assert.False(documentVersionCache.TryGetDocumentVersion(untrackedDocument, out var version));
            Assert.Null(version);
        }
        public void TryGetDocumentVersion_DeletedDocument_ReturnsFalse()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher, FilePathNormalizer);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");

            documentVersionCache.TrackDocumentVersion(document, 1337);
            documentVersionCache.RazorFileChanged(document.FilePath, RazorFileChangeKind.Removed);

            // Act
            var result = documentVersionCache.TryGetDocumentVersion(document, out var version);

            // Assert
            Assert.False(result);
            Assert.Equal(-1, version);
        }
        public async Task PublishDiagnosticsAsync_NoopsIfDiagnosticsAreSameAsPreviousPublish()
        {
            // Arrange
            var languageServer        = new Mock <ITextDocumentLanguageServer>();
            var processedOpenDocument = TestDocumentSnapshot.Create(OpenedDocument.FilePath);
            var codeDocument          = CreateCodeDocument(SingleDiagnosticCollection);

            processedOpenDocument.With(codeDocument);
            using (var publisher = new TestRazorDiagnosticsPublisher(Dispatcher, languageServer.Object, LoggerFactory))
            {
                publisher._publishedDiagnostics[processedOpenDocument.FilePath] = SingleDiagnosticCollection;
                publisher.Initialize(ProjectManager);

                // Act & Assert
                await publisher.PublishDiagnosticsAsync(processedOpenDocument);
            }
        }
Ejemplo n.º 27
0
        public void TryGetLatestVersionFromPath_TrackedDocument_ReturnsTrue()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var filePath             = "C:/file.cshtml";
            var document1            = TestDocumentSnapshot.Create(filePath);
            var document2            = TestDocumentSnapshot.Create(filePath);

            documentVersionCache.TrackDocumentVersion(document1, 123);
            documentVersionCache.TrackDocumentVersion(document2, 1337);

            // Act
            var result = documentVersionCache.TryGetLatestVersionFromPath(filePath, out var version);

            // Assert
            Assert.True(result);
            Assert.Equal(1337, version);
        }
Ejemplo n.º 28
0
        public void TrackDocumentVersion_AddsFirstEntry()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");

            // Act
            documentVersionCache.TrackDocumentVersion(document, 1337);

            // Assert
            var kvp = Assert.Single(documentVersionCache._documentLookup);

            Assert.Equal(document.FilePath, kvp.Key);
            var entry = Assert.Single(kvp.Value);

            Assert.True(entry.Document.TryGetTarget(out var actualDocument));
            Assert.Same(document, actualDocument);
            Assert.Equal(1337, entry.Version);
        }
Ejemplo n.º 29
0
        public void TrackDocumentVersion_EvictsOldEntries()
        {
            // Arrange
            var documentVersionCache = new DefaultDocumentVersionCache(Dispatcher);
            var document             = TestDocumentSnapshot.Create("C:/file.cshtml");

            for (var i = 0; i < DefaultDocumentVersionCache.MaxDocumentTrackingCount; i++)
            {
                documentVersionCache.TrackDocumentVersion(document, i);
            }

            // Act
            documentVersionCache.TrackDocumentVersion(document, 1337);

            // Assert
            var kvp = Assert.Single(documentVersionCache._documentLookup);

            Assert.Equal(DefaultDocumentVersionCache.MaxDocumentTrackingCount, kvp.Value.Count);
            Assert.Equal(1337, kvp.Value.Last().Version);
        }