public async Task ProjectAdded_DoesNotFireWhenNotReadyAsync() { // Arrange var serializationSuccessful = false; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { Assert.Equal(expectedConfigurationFilePath, configurationFilePath); serializationSuccessful = true; }, shouldSerialize: false) { _active = true, }; publisher.Initialize(ProjectSnapshotManager); var projectFilePath = @"C:\path\to\project.csproj"; var hostProject = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace"); ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath); var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default); // Act await RunOnDispatcherThreadAsync(() => { ProjectSnapshotManager.ProjectAdded(hostProject); ProjectSnapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState); }).ConfigureAwait(false); // Assert Assert.False(serializationSuccessful); }
public async Task ProjectAdded_DoesNotPublishWithoutProjectWorkspaceStateAsync() { // Arrange var serializationSuccessful = false; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { Assert.True(false, "Serialization should not have been atempted because there is no ProjectWorkspaceState."); serializationSuccessful = true; }) { _active = true, }; publisher.Initialize(ProjectSnapshotManager); var hostProject = new HostProject(@"C:\path\to\project.csproj", RazorConfiguration.Default, "TestRootNamespace"); ProjectConfigurationFilePathStore.Set(hostProject.FilePath, expectedConfigurationFilePath); // Act await RunOnDispatcherThreadAsync(() => ProjectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false); Assert.Empty(publisher.DeferredPublishTasks); // Assert Assert.False(serializationSuccessful); }
public async Task EnqueuePublish_OnProjectWithoutRazor_Publishes() { // 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\objbin\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(secondSnapshot.FilePath, expectedConfigurationFilePath); // Act publisher.EnqueuePublish(secondSnapshot); // Assert var kvp = Assert.Single(publisher.DeferredPublishTasks); await kvp.Value.ConfigureAwait(false); Assert.True(serializationSuccessful); }
public void Publish_PublishesToSetPublishFilePath() { // Arrange var serializationSuccessful = false; var omniSharpProjectSnapshot = 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) => { Assert.Same(omniSharpProjectSnapshot, snapshot); Assert.Equal(expectedConfigurationFilePath, configurationFilePath); serializationSuccessful = true; }) { _active = true, }; publisher.Initialize(ProjectSnapshotManager); ProjectConfigurationFilePathStore.Set(omniSharpProjectSnapshot.FilePath, expectedConfigurationFilePath); // Act publisher.Publish(omniSharpProjectSnapshot); // Assert Assert.True(serializationSuccessful); }
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); }
internal async Task ProjectManager_Changed_EnqueuesPublishAsync(ProjectChangeKind changeKind) { // Arrange var serializationSuccessful = false; var projectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray <TagHelperDescriptor> .Empty, CodeAnalysis.CSharp.LanguageVersion.CSharp7_3)); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { Assert.Same(projectSnapshot, 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, changeKind); // Act publisher.ProjectSnapshotManager_Changed(null, args); // Assert var kvp = Assert.Single(publisher.DeferredPublishTasks); await kvp.Value.ConfigureAwait(false); Assert.True(serializationSuccessful); }
public void ProjectManager_Changed_DocumentOpened_InitializedProject_NotActive_Publishes() { // Arrange var serializationSuccessful = false; var hostProject = new HostProject(@"C:\path\to\project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace"); var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor"); ProjectSnapshotManager.ProjectAdded(hostProject); ProjectSnapshotManager.ProjectWorkspaceStateChanged(hostProject.FilePath, ProjectWorkspaceState.Default); ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath)); var projectSnapshot = ProjectSnapshotManager.Projects[0]; var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath); var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => { Assert.Equal(expectedConfigurationFilePath, configurationFilePath); serializationSuccessful = true; }) { EnqueueDelay = 10, }; publisher.Initialize(ProjectSnapshotManager); // Act ProjectSnapshotManager.DocumentOpened(hostProject.FilePath, hostDocument.FilePath, SourceText.From(string.Empty)); // Assert Assert.Empty(publisher.DeferredPublishTasks); Assert.True(serializationSuccessful); }
public void ProjectManager_Changed_DocumentOpened_UninitializedProject_NotActive_Noops() { // Arrange var attemptedToSerialize = false; var hostProject = new HostProject(@"C:\path\to\project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace"); var hostDocument = new HostDocument(@"C:\path\to\file.razor", "file.razor"); ProjectSnapshotManager.ProjectAdded(hostProject); ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath)); var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore, onSerializeToFile: (snapshot, configurationFilePath) => attemptedToSerialize = true) { EnqueueDelay = 10, }; publisher.Initialize(ProjectSnapshotManager); // Act ProjectSnapshotManager.DocumentOpened(hostProject.FilePath, hostDocument.FilePath, SourceText.From(string.Empty)); // Assert Assert.Empty(publisher.DeferredPublishTasks); Assert.False(attemptedToSerialize); }
public void Publish_UnsetConfigurationFilePath_Noops() { // Arrange var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore) { _active = true, }; publisher.Initialize(ProjectSnapshotManager); var omniSharpProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj"); // Act & Assert publisher.Publish(omniSharpProjectSnapshot); }
public async Task ProjectRemoved_UnSetPublishFilePath_NoopsAsync() { // Arrange var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore) { _active = true, }; publisher.Initialize(ProjectSnapshotManager); var hostProject = new HostProject(@"C:\path\to\project.csproj", RazorConfiguration.Default, "TestRootNamespace"); await RunOnDispatcherThreadAsync(() => ProjectSnapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false); // Act & Assert await RunOnDispatcherThreadAsync(() => ProjectSnapshotManager.ProjectRemoved(hostProject)).ConfigureAwait(false); Assert.Empty(publisher.DeferredPublishTasks); }
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(@"C:\path\to\project.csproj", new ProjectWorkspaceState(tagHelpers, CodeAnalysis.CSharp.LanguageVersion.Preview)); var expectedProjectSnapshot = CreateProjectSnapshot(@"C:\path\to\project.csproj", new ProjectWorkspaceState(ImmutableArray <TagHelperDescriptor> .Empty, CodeAnalysis.CSharp.LanguageVersion.Preview)); var expectedConfigurationFilePath = @"C:\path\to\obj\bin\Debug\project.razor.json"; var publisher = new TestProjectRazorJsonPublisher( ProjectConfigurationFilePathStore, 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: @"C:\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); }
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); }