public async Task EnqueuePublish_BatchesPublishRequests() { // 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 TestProjectChangePublisher( LoggerFactory, onSerializeToFile: (snapshot, publishFilePath) => { Assert.Same(secondSnapshot, snapshot); Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }); publisher.EnqueueDelay = 10; publisher.SetPublishFilePath(firstSnapshot.FilePath, expectedPublishFilePath); // Act publisher.EnqueuePublish(firstSnapshot); publisher.EnqueuePublish(secondSnapshot); // Assert var kvp = Assert.Single(publisher._deferredPublishTasks); await kvp.Value; Assert.True(serializationSuccessful); }
public async Task ProjectManager_Changed_EnqueuesPublish(OmniSharpProjectChangeKind 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 TestProjectChangePublisher( LoggerFactory, onSerializeToFile: (snapshot, publishFilePath) => { Assert.Same(projectSnapshot, snapshot); Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }); publisher.EnqueueDelay = 10; publisher.SetPublishFilePath(projectSnapshot.FilePath, expectedPublishFilePath); var args = OmniSharpProjectChangeEventArgs.CreateTestInstance(projectSnapshot, projectSnapshot, changeKind); // Act publisher.ProjectManager_Changed(null, args); // Assert var kvp = Assert.Single(publisher._deferredPublishTasks); await kvp.Value; Assert.True(serializationSuccessful); }
public async Task ProjectRemoved_DeletesPublishFile() { // Arrange var attemptedToDelete = false; var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestProjectChangePublisher(LoggerFactory, onSerializeToFile: (_, __) => { }, onDeleteFile: (publishFilePath) => { attemptedToDelete = true; Assert.Equal(expectedPublishFilePath, publishFilePath); }); publisher.Initialize(snapshotManager); var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace"); publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath); await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject)); // Act await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject)); // Assert Assert.True(attemptedToDelete); }
public async Task ProjectAdded_PublishesToCorrectFilePath() { // Arrange var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); var serializationSuccessful = false; var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestProjectChangePublisher( LoggerFactory, onSerializeToFile: (snapshot, publishFilePath) => { Assert.Equal(expectedPublishFilePath, publishFilePath); serializationSuccessful = true; }); publisher.Initialize(snapshotManager); var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace"); publisher.SetPublishFilePath(hostProject.FilePath, expectedPublishFilePath); // Act await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject)); // Assert Assert.True(serializationSuccessful); }
public async Task ProjectManager_Changed_ProjectRemoved_AfterEnqueuedPublish() { // Arrange var attemptedToSerialize = false; var projectSnapshot = CreateProjectSnapshot("/path/to/project.csproj"); var expectedPublishFilePath = "/path/to/obj/bin/Debug/project.razor.json"; var publisher = new TestProjectChangePublisher( LoggerFactory, onSerializeToFile: (snapshot, publishFilePath) => attemptedToSerialize = true, onDeleteFile: (path) => { }) { EnqueueDelay = 10 }; publisher.SetPublishFilePath(projectSnapshot.FilePath, expectedPublishFilePath); publisher.EnqueuePublish(projectSnapshot); var args = OmniSharpProjectChangeEventArgs.CreateTestInstance(projectSnapshot, newer: null, documentFilePath: null, OmniSharpProjectChangeKind.ProjectRemoved); // Act publisher.ProjectManager_Changed(null, args); // Assert await Task.Delay(publisher.EnqueueDelay * 3); Assert.False(attemptedToSerialize); }
public void Publish_UnsetPublishFilePath_Noops() { // Arrange var publisher = new TestProjectChangePublisher(LoggerFactory); var omniSharpProjectSnapshot = CreateProjectSnapshot("/path/to/project.csproj"); // Act & Assert publisher.Publish(omniSharpProjectSnapshot); }
public async Task ProjectRemoved_UnSetPublishFilePath_Noops() { // Arrange var snapshotManager = CreateProjectSnapshotManager(allowNotifyListeners: true); var publisher = new TestProjectChangePublisher(LoggerFactory); publisher.Initialize(snapshotManager); var hostProject = new OmniSharpHostProject("/path/to/project.csproj", RazorConfiguration.Default, "TestRootNamespace"); await RunOnForegroundAsync(() => snapshotManager.ProjectAdded(hostProject)); // Act & Assert await RunOnForegroundAsync(() => snapshotManager.ProjectRemoved(hostProject)); }
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 TestProjectChangePublisher( LoggerFactory, 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); }