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 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 expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestDefaultRazorProjectChangePublisher( JoinableTaskContext, RazorLogger, onSerializeToFile: (snapshot, publishFilePath) => { Assert.Same(secondSnapshot, snapshot); Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }) { EnqueueDelay = 10 }; publisher.SetPublishFilePath(firstSnapshot.FilePath, expectedPublishFilePath); // Act publisher.EnqueuePublish(firstSnapshot); publisher.EnqueuePublish(secondSnapshot); // 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"); 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); }
public async Task ProjectRemoved_DeletesPublishFileAsync() { // Arrange var attemptedToDelete = false; var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestDefaultRazorProjectChangePublisher( JoinableTaskContext, RazorLogger, onSerializeToFile: (_, __) => { }, onDeleteFile: (publishFilePath) => { attemptedToDelete = true; Assert.Equal(expectedPublishFilePath, publishFilePath); }); publisher.Initialize(snapshotManager); var hostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace"); publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath); await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false); // Act await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject)).ConfigureAwait(false); // Assert Assert.True(attemptedToDelete); }
public async Task ProjectAdded_DoesNotPublishWithoutProjectWorkspaceStateAsync() { // Arrange var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); var serializationSuccessful = false; var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestDefaultRazorProjectChangePublisher( JoinableTaskContext, RazorLogger, onSerializeToFile: (snapshot, publishFilePath) => { Assert.True(false, "Serialization should not have been atempted because there is no ProjectWorkspaceState."); serializationSuccessful = true; }); publisher.Initialize(snapshotManager); var hostProject = new HostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace"); publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath); // Act await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject)).ConfigureAwait(false); // Assert Assert.False(serializationSuccessful); }
public void Publish_PublishesToSetPublishFilePath() { // Arrange var serializationSuccessful = false; var omniSharpProjectSnapshot = 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(omniSharpProjectSnapshot, snapshot); Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }); publisher.SetPublishFilePath(omniSharpProjectSnapshot.FilePath, expectedPublishFilePath); // Act publisher.Publish(omniSharpProjectSnapshot); // Assert Assert.True(serializationSuccessful); }
public async Task ProjectAdded_PublishesToCorrectFilePathAsync() { // Arrange var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); var serializationSuccessful = false; var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestDefaultRazorProjectChangePublisher( JoinableTaskContext, RazorLogger, onSerializeToFile: (snapshot, publishFilePath) => { Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }); publisher.Initialize(snapshotManager); var projectFilePath = "/path/to/project.csproj"; var hostProject = new HostProject(projectFilePath, RazorConfiguration.Default, "TestRootNamespace"); publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath); var projectWorkspaceState = new ProjectWorkspaceState(Array.Empty <TagHelperDescriptor>(), CodeAnalysis.CSharp.LanguageVersion.Default); // Act await RunOnForegroundAsync(() => { snapshotManager.ProjectAdded(hostProject); snapshotManager.ProjectWorkspaceStateChanged(projectFilePath, projectWorkspaceState); }).ConfigureAwait(false); // Assert var kvp = Assert.Single(publisher._deferredPublishTasks); await kvp.Value.ConfigureAwait(false); Assert.True(serializationSuccessful); }