internal async Task ProjectManager_ChangedTagHelpers_PublishesImmediately() { // Arrange var serializationSuccessful = false; var projectSnapshot = CreateProjectSnapshot("/path/to/project.csproj", new ProjectWorkspaceState(ImmutableArray <TagHelperDescriptor> .Empty, CodeAnalysis.CSharp.LanguageVersion.Default)); var changedProjectSnapshot = CreateProjectSnapshot("/path/to/project.csproj", new ProjectWorkspaceState(ImmutableArray <TagHelperDescriptor> .Empty, CodeAnalysis.CSharp.LanguageVersion.CSharp8)); var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var aboutToChange = false; var publisher = new TestDefaultRazorProjectChangePublisher( ProjectConfigurationFilePathStore, _razorLogger, onSerializeToFile: (snapshot, configurationFilePath) => { if (!aboutToChange) { return; } Assert.Same(changedProjectSnapshot, snapshot); Assert.Equal(expectedConfigurationFilePath, configurationFilePath); serializationSuccessful = true; }) { EnqueueDelay = 10, _active = true, }; publisher.Initialize(ProjectSnapshotManager); ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath); var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, documentFilePath: null, ProjectChangeKind.ProjectChanged); publisher.ProjectSnapshotManager_Changed(null, args); // Flush publish task var kvp = Assert.Single(publisher.DeferredPublishTasks); await kvp.Value.ConfigureAwait(false); aboutToChange = true; publisher.DeferredPublishTasks.Clear(); var changedTagHelpersArgs = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, changedProjectSnapshot, documentFilePath: null, ProjectChangeKind.ProjectChanged); // Act publisher.ProjectSnapshotManager_Changed(null, changedTagHelpersArgs); // Assert Assert.Empty(publisher.DeferredPublishTasks); Assert.True(serializationSuccessful); }
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); }
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); }
internal async Task ProjectManager_Changed_EnqueuesPublishAsync(ProjectChangeKind changeKind) { // Arrange var serializationSuccessful = 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) => { Assert.Same(projectSnapshot, snapshot); Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }) { EnqueueDelay = 10 }; publisher.SetPublishFilePath(projectSnapshot.FilePath, expectedPublishFilePath); var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, documentFilePath: null, changeKind); // Act publisher.ProjectSnapshotManager_Changed(null, args); // Assert var kvp = Assert.Single(publisher._deferredPublishTasks); await kvp.Value.ConfigureAwait(false); Assert.True(serializationSuccessful); }
internal async Task ProjectManager_Changed_EnqueuesPublishAsync(ProjectChangeKind changeKind) { // Arrange var serializationSuccessful = false; var projectSnapshot = CreateProjectSnapshot("/path/to/project.csproj", new ProjectWorkspaceState(ImmutableArray <TagHelperDescriptor> .Empty, CodeAnalysis.CSharp.LanguageVersion.Default)); var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestDefaultRazorProjectChangePublisher( ProjectConfigurationFilePathStore, RazorLogger, onSerializeToFile: (snapshot, configurationFilePath) => { Assert.Same(projectSnapshot, snapshot); Assert.Equal(expectedConfigurationFilePath, configurationFilePath); serializationSuccessful = true; }) { EnqueueDelay = 10 }; ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath); var args = ProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, documentFilePath: null, changeKind); // Act publisher.ProjectSnapshotManager_Changed(null, args); // Assert var kvp = Assert.Single(publisher._deferredPublishTasks); await kvp.Value.ConfigureAwait(false); Assert.True(serializationSuccessful); }
public async Task ProjectManager_Changed_Remove_Change_NoopsOnDelayedPublish() { // Arrange var serializationSuccessful = false; 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 initialProjectSnapshot = CreateProjectSnapshot("/path/to/project.csproj", new ProjectWorkspaceState(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.Preview)); var expectedProjectSnapshot = CreateProjectSnapshot("/path/to/project.csproj", new ProjectWorkspaceState(ImmutableArray <TagHelperDescriptor> .Empty, CodeAnalysis.CSharp.LanguageVersion.Preview)); var expectedConfigurationFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestDefaultRazorProjectChangePublisher( ProjectConfigurationFilePathStore, _razorLogger, onSerializeToFile: (snapshot, configurationFilePath) => { Assert.Same(expectedProjectSnapshot, snapshot); Assert.Equal(expectedConfigurationFilePath, configurationFilePath); serializationSuccessful = true; }) { EnqueueDelay = 10, _active = true, }; publisher.Initialize(ProjectSnapshotManager); ProjectConfigurationFilePathStore.Set(expectedProjectSnapshot.FilePath, expectedConfigurationFilePath); var documentRemovedArgs = ProjectChangeEventArgs.CreateTestInstance(initialProjectSnapshot, initialProjectSnapshot, documentFilePath: "/path/to/file.razor", ProjectChangeKind.DocumentRemoved); var projectChangedArgs = ProjectChangeEventArgs.CreateTestInstance(initialProjectSnapshot, expectedProjectSnapshot, documentFilePath: null, ProjectChangeKind.ProjectChanged); // Act publisher.ProjectSnapshotManager_Changed(null, documentRemovedArgs); publisher.ProjectSnapshotManager_Changed(null, projectChangedArgs); // Assert var stalePublishTask = Assert.Single(publisher.DeferredPublishTasks); await stalePublishTask.Value.ConfigureAwait(false); Assert.True(serializationSuccessful); }