Example #1
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();
        }
Example #2
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);
        }
        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);
        }
        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);
        }
Example #5
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);
        }
Example #6
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);
        }
Example #7
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);
        }
        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);
        }
Example #9
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);
        }