public void ProjectManager_Changed_DocumentOpened_UninitializedProject_NotActive_Noops() { // Arrange var attemptedToSerialize = false; var hostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace"); var hostDocument = new HostDocument("/path/to/file.razor", "file.razor"); ProjectSnapshotManager.ProjectAdded(hostProject); ProjectSnapshotManager.DocumentAdded(hostProject, hostDocument, new EmptyTextLoader(hostDocument.FilePath)); var publisher = new TestDefaultRazorProjectChangePublisher( ProjectConfigurationFilePathStore, RazorLogger, 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 ProjectManager_Changed_DocumentOpened_InitializedProject_NotActive_Publishes() { // Arrange var serializationSuccessful = false; var hostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, rootNamespace: "TestRootNamespace"); var hostDocument = new HostDocument("/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 = "/path/to/obj/bin/Debug/project.razor.json"; ProjectConfigurationFilePathStore.Set(projectSnapshot.FilePath, expectedConfigurationFilePath); var publisher = new TestDefaultRazorProjectChangePublisher( ProjectConfigurationFilePathStore, RazorLogger, 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); }