示例#1
0
        public async Task EnqueuePublish_BatchesPublishRequestsAsync()
        {
            // Arrange
            var serializationSuccessful       = false;
            var firstSnapshot                 = CreateProjectSnapshot(@"C:\path\to\project.csproj");
            var secondSnapshot                = CreateProjectSnapshot(@"C:\path\to\project.csproj", new[] { @"C:\path\to\file.cshtml" });
            var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json";
            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore,
                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);
        }
示例#2
0
        public async Task ProjectManager_Changed_ProjectRemoved_AfterEnqueuedPublishAsync()
        {
            // Arrange
            var attemptedToSerialize          = false;
            var projectSnapshot               = CreateProjectSnapshot(@"C:\path\to\project.csproj");
            var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json";
            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore,
                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);
        }
示例#3
0
        public async Task EnqueuePublish_OnProjectBeforeTagHelperProcessed_DoesNotPublish()
        {
            // Arrange
            var serializationSuccessful = false;
            var firstSnapshot           = CreateProjectSnapshot(@"C:\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(@"C:\path\to\project.csproj", new ProjectWorkspaceState(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.CSharp8), new string[] {
                "FileName.razor"
            });
            var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json";
            var publisher = new TestProjectRazorJsonPublisher(
                ProjectConfigurationFilePathStore,
                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);
        }