public async Task EnqueuePublish_BatchesPublishRequestsAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var firstSnapshot                 = CreateProjectSnapshot("/path/to/project.csproj");
            var secondSnapshot                = CreateProjectSnapshot("/path/to/project.csproj", new[] { "/path/to/file.cshtml" });
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Same(secondSnapshot, snapshot);
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            })
            {
                EnqueueDelay = 10,
                _active      = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            ProjectConfigurationFilePathStore.Set(firstSnapshot.FilePath, expectedConfigurationFilePath);

            // Act
            publisher.EnqueuePublish(firstSnapshot);
            publisher.EnqueuePublish(secondSnapshot);

            // Assert
            var kvp = Assert.Single(publisher._deferredPublishTasks);
            await kvp.Value.ConfigureAwait(false);

            Assert.True(serializationSuccessful);
        }
        public async Task ProjectManager_Changed_ProjectRemoved_AfterEnqueuedPublishAsync()
        {
            // Arrange
            var attemptedToSerialize    = false;
            var projectSnapshot         = CreateProjectSnapshot("/path/to/project.csproj");
            var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestDefaultRazorProjectChangePublisher(
                JoinableTaskContext,
                RazorLogger,
                onSerializeToFile: (snapshot, publishFilePath) => attemptedToSerialize = true,
                onDeleteFile: (path) => { })
            {
                EnqueueDelay = 10
            };

            publisher.SetPublishFilePath(projectSnapshot.FilePath, expectedPublishFilePath);
            publisher.EnqueuePublish(projectSnapshot);
            var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, newer: null, documentFilePath: null, ProjectChangeKind.ProjectRemoved);

            // Act
            publisher.ProjectSnapshotManager_Changed(null, args);

            // Assert
            await Task.Delay(publisher.EnqueueDelay * 3).ConfigureAwait(false);

            Assert.False(attemptedToSerialize);
        }
        public async Task ProjectManager_Changed_ProjectRemoved_AfterEnqueuedPublishAsync()
        {
            // Arrange
            var attemptedToSerialize          = false;
            var projectSnapshot               = CreateProjectSnapshot("/path/to/project.csproj");
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                RazorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true)
            {
                EnqueueDelay = 10,
                _active      = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath);
            publisher.EnqueuePublish(projectSnapshot);
            var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, newer: null, documentFilePath: null, ProjectChangeKind.ProjectRemoved);

            // Act
            publisher.ProjectSnapshotManager_Changed(null, args);

            // Assert
            var kvp = Assert.Single(publisher._deferredPublishTasks);
            await kvp.Value.ConfigureAwait(false);

            Assert.False(attemptedToSerialize);
        }
Esempio n. 4
0
        public async Task EnqueuePublish_OnProjectBeforeTagHelperProcessed_DoesNotPublish()
        {
            // Arrange
            var serializationSuccessful = false;
            var firstSnapshot           = CreateProjectSnapshot("/path/to/project.csproj");
            var tagHelpers = new TagHelperDescriptor[] {
                new DefaultTagHelperDescriptor(FileKinds.Component, "Namespace.FileNameOther", "Assembly", "FileName", "FileName document", "FileName hint",
                                               caseSensitive: false, tagMatchingRules: null, attributeDescriptors: null, allowedChildTags: null, metadata: null, diagnostics: null)
            };
            var secondSnapshot = CreateProjectSnapshot("/path/to/project.csproj", new ProjectWorkspaceState(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.CSharp8), new string[] {
                "FileName.razor"
            });
            var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json";
            var publisher = new TestDefaultRazorProjectChangePublisher(
                ProjectConfigurationFilePathStore,
                _razorLogger,
                onSerializeToFile: (snapshot, configurationFilePath) =>
            {
                Assert.Same(secondSnapshot, snapshot);
                Assert.Equal(expectedConfigurationFilePath, configurationFilePath);
                serializationSuccessful = true;
            },
                useRealShouldSerialize: true)
            {
                EnqueueDelay = 10,
                _active      = true,
            };

            publisher.Initialize(ProjectSnapshotManager);
            ProjectConfigurationFilePathStore.Set(firstSnapshot.FilePath, expectedConfigurationFilePath);

            // Act
            publisher.EnqueuePublish(secondSnapshot);

            // Assert
            var kvp = Assert.Single(publisher.DeferredPublishTasks);
            await kvp.Value.ConfigureAwait(false);

            Assert.False(serializationSuccessful);
        }