public async Task WorkspaceChanged_DocumentChanged_Razor_UpdatesProjectState_AfterDelay() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator) { EnqueueDelay = 1, BlockDelayedUpdateWorkEnqueue = new ManualResetEventSlim(initialState: false), }; Workspace.TryApplyChanges(SolutionWithTwoProjects); var projectManager = new TestProjectSnapshotManager(new[] { detector }, Workspace); projectManager.ProjectAdded(HostProjectOne); workspaceStateGenerator.ClearQueue(); var solution = SolutionWithTwoProjects.WithDocumentText(RazorDocumentId, SourceText.From("Hello World")); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.DocumentChanged, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id, RazorDocumentId); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Empty(workspaceStateGenerator.UpdateQueue); detector.BlockDelayedUpdateWorkEnqueue.Set(); await detector._deferredUpdates.Single().Value.Task; var(workspaceProject, projectSnapshot) = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(workspaceProject.Id, ProjectNumberOne.Id); Assert.Equal(projectSnapshot.FilePath, HostProjectOne.FilePath); }
public async Task IsPartialComponentClass_InitializedDocument_ReturnsTrue() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator, Dispatcher, WorkQueue); var sourceText = SourceText.From( $@" public partial class TestComponent : {ComponentsApi.IComponent.MetadataName} {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = await CSharpSyntaxTree.ParseText(sourceText).GetRootAsync(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Initialize document await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.True(result); }
public async Task IsPartialComponentClass_NonComponents_ReturnsFalse() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var sourceText = SourceText.From( $@" public partial class NonComponent1 {{}} public class NonComponent2 {{}} public partial class NonComponent3 {{}} public class NonComponent4 {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Initialize document await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.False(result); }
public async Task WorkspaceChanged_ProjectChangeEvents_UpdatesProjectState_AfterDelay(WorkspaceChangeKind kind) { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator) { EnqueueDelay = 1, BlockDelayedUpdateWorkEnqueue = new ManualResetEventSlim(initialState: false), }; var projectManager = new TestProjectSnapshotManager(new[] { detector }, Workspace); projectManager.ProjectAdded(HostProjectOne); var solution = SolutionWithTwoProjects.WithProjectAssemblyName(ProjectNumberOne.Id, "Changed"); var e = new WorkspaceChangeEventArgs(kind, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Empty(workspaceStateGenerator.UpdateQueue); detector.BlockDelayedUpdateWorkEnqueue.Set(); await detector._deferredUpdates.Single().Value; var update = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(update.workspaceProject.Id, ProjectNumberOne.Id); Assert.Equal(update.projectSnapshot.FilePath, HostProjectOne.FilePath); }
public async Task WorkspaceChanged_DocumentChanged_CSHTML_UpdatesProjectState_AfterDelay() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator) { EnqueueDelay = 50, }; Workspace.TryApplyChanges(SolutionWithTwoProjects); var projectManager = new TestProjectSnapshotManager(new[] { detector }, Workspace); projectManager.ProjectAdded(HostProjectOne); workspaceStateGenerator.ClearQueue(); var solution = SolutionWithTwoProjects.WithDocumentText(CshtmlDocumentId, SourceText.From("Hello World")); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.DocumentChanged, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id, CshtmlDocumentId); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Empty(workspaceStateGenerator.UpdateQueue); await detector._deferredUpdates.Single().Value; var update = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(update.workspaceProject.Id, ProjectNumberOne.Id); Assert.Equal(update.projectSnapshot.FilePath, HostProjectOne.FilePath); }
public void IsPartialComponentClass_Uninitialized_ReturnsFalse() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var sourceText = SourceText.From( $@" public partial class TestComponent : {ComponentsApi.IComponent.MetadataName} {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.False(result); }
public void WorkspaceChanged_ProjectChangeEvents_UpdatesProject(WorkspaceChangeKind kind) { // Arrange var trigger = new WorkspaceProjectSnapshotChangeTrigger(); var projectManager = new TestProjectSnapshotManager(new[] { trigger }, Workspace); // Initialize with some projects. var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.SolutionAdded, oldSolution: EmptySolution, newSolution: SolutionWithTwoProjects); trigger.Workspace_WorkspaceChanged(Workspace, e); var solution = SolutionWithTwoProjects.WithProjectAssemblyName(ProjectNumberOne.Id, "Changed"); e = new WorkspaceChangeEventArgs(kind, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id); // Act trigger.Workspace_WorkspaceChanged(Workspace, e); // Assert Assert.Collection( projectManager.Projects.OrderBy(p => p.UnderlyingProject.Name), p => { Assert.Equal(ProjectNumberOne.Id, p.UnderlyingProject.Id); Assert.Equal("Changed", p.UnderlyingProject.AssemblyName); }, p => Assert.Equal(ProjectNumberTwo.Id, p.UnderlyingProject.Id)); }
public async Task WorkspaceChanged_ProjectRemovedEvent_QueuesProjectStateRemoval() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator, Dispatcher, WorkQueue) { NotifyWorkspaceChangedEventComplete = new ManualResetEventSlim(initialState: false), }; var projectManager = new TestProjectSnapshotManager(Dispatcher, new[] { detector }, Workspace); await Dispatcher.RunOnDispatcherThreadAsync(() => { projectManager.ProjectAdded(HostProjectOne); projectManager.ProjectAdded(HostProjectTwo); }, CancellationToken.None).ConfigureAwait(false); var solution = SolutionWithTwoProjects.RemoveProject(ProjectNumberOne.Id); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.ProjectRemoved, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id); // Act detector.Workspace_WorkspaceChanged(Workspace, e); WorkQueueTestAccessor.NotifyBackgroundWorkCompleted.Wait(); // Assert Assert.Collection( workspaceStateGenerator.UpdateQueue, p => Assert.Null(p.WorkspaceProject)); }
public async Task WorkspaceChanged_DocumentChanged_Razor_UpdatesProjectState_AfterDelay() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator, Dispatcher, WorkQueue); WorkQueueTestAccessor.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false); Workspace.TryApplyChanges(SolutionWithTwoProjects); var projectManager = new TestProjectSnapshotManager(Dispatcher, new[] { detector }, Workspace); await Dispatcher.RunOnDispatcherThreadAsync(() => projectManager.ProjectAdded(HostProjectOne), CancellationToken.None).ConfigureAwait(false); workspaceStateGenerator.ClearQueue(); var solution = SolutionWithTwoProjects.WithDocumentText(RazorDocumentId, SourceText.From("Hello World")); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.DocumentChanged, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id, RazorDocumentId); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Empty(workspaceStateGenerator.UpdateQueue); WorkQueueTestAccessor.BlockBackgroundWorkStart.Set(); WorkQueueTestAccessor.NotifyBackgroundWorkCompleted.Wait(); var update = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(update.WorkspaceProject.Id, ProjectNumberOne.Id); Assert.Equal(update.ProjectSnapshot.FilePath, HostProjectOne.FilePath); }
public void WorkspaceChanged_ProjectRemovedEvent_RemovesProject() { // Arrange var trigger = new WorkspaceProjectSnapshotChangeTrigger(); var projectManager = new TestProjectSnapshotManager(new[] { trigger }, Workspace); projectManager.HostProjectAdded(HostProjectOne); projectManager.HostProjectAdded(HostProjectTwo); // Initialize with some projects project. var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.SolutionAdded, oldSolution: EmptySolution, newSolution: SolutionWithTwoProjects); trigger.Workspace_WorkspaceChanged(Workspace, e); var solution = SolutionWithTwoProjects.RemoveProject(ProjectNumberOne.Id); e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.ProjectRemoved, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id); // Act trigger.Workspace_WorkspaceChanged(Workspace, e); // Assert Assert.Collection( projectManager.Projects.OrderBy(p => p.WorkspaceProject?.Name), p => Assert.Null(p.WorkspaceProject), p => Assert.Equal(ProjectNumberTwo.Id, p.WorkspaceProject.Id)); }
public async Task WorkspaceChanged_DocumentChanged_PartialComponent_UpdatesProjectState_AfterDelay() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator) { EnqueueDelay = 1, BlockDelayedUpdateWorkEnqueue = new ManualResetEventSlim(initialState: false), }; Workspace.TryApplyChanges(SolutionWithTwoProjects); var projectManager = new TestProjectSnapshotManager(new[] { detector }, Workspace); projectManager.ProjectAdded(HostProjectOne); workspaceStateGenerator.ClearQueue(); var sourceText = SourceText.From( $@" public partial class TestComponent : {ComponentsApi.IComponent.MetadataName} {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // The change detector only operates when a semantic model / syntax tree is available. await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.DocumentChanged, oldSolution: solution, newSolution: solution, projectId: ProjectNumberOne.Id, PartialComponentClassDocumentId); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Empty(workspaceStateGenerator.UpdateQueue); detector.BlockDelayedUpdateWorkEnqueue.Set(); await detector._deferredUpdates.Single().Value; var update = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(update.workspaceProject.Id, ProjectNumberOne.Id); Assert.Equal(update.projectSnapshot.FilePath, HostProjectOne.FilePath); }
public WorkspaceProjectStateChangeDetectorTest() { EmptySolution = Workspace.CurrentSolution.GetIsolatedSolution(); var projectId1 = ProjectId.CreateNewId("One"); var projectId2 = ProjectId.CreateNewId("Two"); var projectId3 = ProjectId.CreateNewId("Three"); CshtmlDocumentId = DocumentId.CreateNewId(projectId1); var cshtmlDocumentInfo = DocumentInfo.Create(CshtmlDocumentId, "Test", filePath: "file.cshtml.g.cs"); RazorDocumentId = DocumentId.CreateNewId(projectId1); var razorDocumentInfo = DocumentInfo.Create(RazorDocumentId, "Test", filePath: "file.razor.g.cs"); BackgroundVirtualCSharpDocumentId = DocumentId.CreateNewId(projectId1); var backgroundDocumentInfo = DocumentInfo.Create(BackgroundVirtualCSharpDocumentId, "Test", filePath: "file.razor__bg__virtual.cs"); PartialComponentClassDocumentId = DocumentId.CreateNewId(projectId1); var partialComponentClassDocumentInfo = DocumentInfo.Create(PartialComponentClassDocumentId, "Test", filePath: "file.razor.cs"); SolutionWithTwoProjects = Workspace.CurrentSolution .AddProject(ProjectInfo.Create( projectId1, VersionStamp.Default, "One", "One", LanguageNames.CSharp, filePath: "One.csproj", documents: new[] { cshtmlDocumentInfo, razorDocumentInfo, partialComponentClassDocumentInfo, backgroundDocumentInfo })) .AddProject(ProjectInfo.Create( projectId2, VersionStamp.Default, "Two", "Two", LanguageNames.CSharp, filePath: "Two.csproj")); SolutionWithOneProject = EmptySolution.GetIsolatedSolution() .AddProject(ProjectInfo.Create( projectId3, VersionStamp.Default, "Three", "Three", LanguageNames.CSharp, filePath: "Three.csproj")); ProjectNumberOne = SolutionWithTwoProjects.GetProject(projectId1); ProjectNumberTwo = SolutionWithTwoProjects.GetProject(projectId2); ProjectNumberThree = SolutionWithOneProject.GetProject(projectId3); HostProjectOne = new HostProject("One.csproj", FallbackRazorConfiguration.MVC_1_1, "One"); HostProjectTwo = new HostProject("Two.csproj", FallbackRazorConfiguration.MVC_1_1, "Two"); HostProjectThree = new HostProject("Three.csproj", FallbackRazorConfiguration.MVC_1_1, "Three"); }
public async Task WorkspaceChanged_DocumentChanged_PartialComponent_UpdatesProjectState_AfterDelay() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator, Dispatcher, WorkQueue); WorkQueueTestAccessor.BlockBackgroundWorkStart = new ManualResetEventSlim(initialState: false); Workspace.TryApplyChanges(SolutionWithTwoProjects); var projectManager = new TestProjectSnapshotManager(Dispatcher, new[] { detector }, Workspace); await Dispatcher.RunOnDispatcherThreadAsync(() => projectManager.ProjectAdded(HostProjectOne), CancellationToken.None).ConfigureAwait(false); workspaceStateGenerator.ClearQueue(); var sourceText = SourceText.From( $@" public partial class TestComponent : {ComponentsApi.IComponent.MetadataName} {{}} namespace Microsoft.AspNetCore.Components {{ public interface IComponent {{}} }} "); var syntaxTreeRoot = await CSharpSyntaxTree.ParseText(sourceText).GetRootAsync(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // The change detector only operates when a semantic model / syntax tree is available. await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.DocumentChanged, oldSolution: solution, newSolution: solution, projectId: ProjectNumberOne.Id, PartialComponentClassDocumentId); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Empty(workspaceStateGenerator.UpdateQueue); WorkQueueTestAccessor.BlockBackgroundWorkStart.Set(); WorkQueueTestAccessor.NotifyBackgroundWorkCompleted.Wait(); var update = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(update.WorkspaceProject.Id, ProjectNumberOne.Id); Assert.Equal(update.ProjectSnapshot.FilePath, HostProjectOne.FilePath); }
public WorkspaceProjectSnapshotChangeTriggerTest() { Workspace = TestWorkspace.Create(); EmptySolution = Workspace.CurrentSolution.GetIsolatedSolution(); var projectId1 = ProjectId.CreateNewId("One"); var projectId2 = ProjectId.CreateNewId("Two"); var projectId3 = ProjectId.CreateNewId("Three"); SolutionWithTwoProjects = Workspace.CurrentSolution .AddProject(ProjectInfo.Create( projectId1, VersionStamp.Default, "One", "One", LanguageNames.CSharp, filePath: "One.csproj")) .AddProject(ProjectInfo.Create( projectId2, VersionStamp.Default, "Two", "Two", LanguageNames.CSharp, filePath: "Two.csproj")); SolutionWithOneProject = EmptySolution.GetIsolatedSolution() .AddProject(ProjectInfo.Create( projectId3, VersionStamp.Default, "Three", "Three", LanguageNames.CSharp, filePath: "Three.csproj")); ProjectNumberOne = SolutionWithTwoProjects.GetProject(projectId1); ProjectNumberTwo = SolutionWithTwoProjects.GetProject(projectId2); ProjectNumberThree = SolutionWithOneProject.GetProject(projectId3); HostProjectOne = new HostProject("One.csproj", FallbackRazorConfiguration.MVC_1_1); HostProjectTwo = new HostProject("Two.csproj", FallbackRazorConfiguration.MVC_1_1); HostProjectThree = new HostProject("Three.csproj", FallbackRazorConfiguration.MVC_1_1); }
public async Task WorkspaceChanged_ProjectChangeEvents_UpdatesProject_AfterDelay(WorkspaceChangeKind kind) { // Arrange var trigger = new WorkspaceProjectSnapshotChangeTrigger() { ProjectChangeDelay = 50, }; var projectManager = new TestProjectSnapshotManager(new[] { trigger }, Workspace); projectManager.HostProjectAdded(HostProjectOne); projectManager.HostProjectAdded(HostProjectTwo); // Initialize with some projects. var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.SolutionAdded, oldSolution: EmptySolution, newSolution: SolutionWithTwoProjects); trigger.Workspace_WorkspaceChanged(Workspace, e); var solution = SolutionWithTwoProjects.WithProjectAssemblyName(ProjectNumberOne.Id, "Changed"); e = new WorkspaceChangeEventArgs(kind, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id); // Act trigger.Workspace_WorkspaceChanged(Workspace, e); // Assert // // The change hasn't come through yet. Assert.Equal("One", projectManager.Projects.Single().WorkspaceProject.AssemblyName); await trigger._deferredUpdates.Single().Value; Assert.Collection( projectManager.Projects.OrderBy(p => p.WorkspaceProject.Name), p => { Assert.Equal(ProjectNumberOne.Id, p.WorkspaceProject.Id); Assert.Equal("Changed", p.WorkspaceProject.AssemblyName); }, p => Assert.Equal(ProjectNumberTwo.Id, p.WorkspaceProject.Id)); }
public void WorkspaceChanged_ProjectRemovedEvent_QueuesProjectStateRemoval() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var projectManager = new TestProjectSnapshotManager(new[] { detector }, Workspace); projectManager.ProjectAdded(HostProjectOne); projectManager.ProjectAdded(HostProjectTwo); var solution = SolutionWithTwoProjects.RemoveProject(ProjectNumberOne.Id); var e = new WorkspaceChangeEventArgs(WorkspaceChangeKind.ProjectRemoved, oldSolution: SolutionWithTwoProjects, newSolution: solution, projectId: ProjectNumberOne.Id); // Act detector.Workspace_WorkspaceChanged(Workspace, e); // Assert Assert.Collection( workspaceStateGenerator.UpdateQueue, p => Assert.Null(p.workspaceProject)); }
public async Task IsPartialComponentClass_NonClass_ReturnsFalse() { // Arrange var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var detector = new WorkspaceProjectStateChangeDetector(workspaceStateGenerator); var sourceText = SourceText.From(string.Empty); var syntaxTreeRoot = CSharpSyntaxTree.ParseText(sourceText).GetRoot(); var solution = SolutionWithTwoProjects .WithDocumentText(PartialComponentClassDocumentId, sourceText) .WithDocumentSyntaxRoot(PartialComponentClassDocumentId, syntaxTreeRoot, PreservationMode.PreserveIdentity); var document = solution.GetDocument(PartialComponentClassDocumentId); // Initialize document await document.GetSyntaxRootAsync(); await document.GetSemanticModelAsync(); // Act var result = detector.IsPartialComponentClass(document); // Assert Assert.False(result); }
public WorkspaceProjectStateChangeDetectorTest() { EmptySolution = Workspace.CurrentSolution; var projectId1 = ProjectId.CreateNewId("One"); var projectId2 = ProjectId.CreateNewId("Two"); var projectId3 = ProjectId.CreateNewId("Three"); CshtmlDocumentId = DocumentId.CreateNewId(projectId1); var cshtmlDocumentInfo = DocumentInfo.Create(CshtmlDocumentId, "Test", filePath: "file.cshtml.g.cs"); RazorDocumentId = DocumentId.CreateNewId(projectId1); var razorDocumentInfo = DocumentInfo.Create(RazorDocumentId, "Test", filePath: "file.razor.g.cs"); BackgroundVirtualCSharpDocumentId = DocumentId.CreateNewId(projectId1); var backgroundDocumentInfo = DocumentInfo.Create(BackgroundVirtualCSharpDocumentId, "Test", filePath: "file.razor__bg__virtual.cs"); PartialComponentClassDocumentId = DocumentId.CreateNewId(projectId1); var partialComponentClassDocumentInfo = DocumentInfo.Create(PartialComponentClassDocumentId, "Test", filePath: "file.razor.cs"); SolutionWithTwoProjects = Workspace.CurrentSolution .AddProject(ProjectInfo.Create( projectId1, VersionStamp.Default, "One", "One", LanguageNames.CSharp, filePath: "One.csproj", documents: new[] { cshtmlDocumentInfo, razorDocumentInfo, partialComponentClassDocumentInfo, backgroundDocumentInfo })) .AddProject(ProjectInfo.Create( projectId2, VersionStamp.Default, "Two", "Two", LanguageNames.CSharp, filePath: "Two.csproj")); SolutionWithOneProject = EmptySolution .AddProject(ProjectInfo.Create( projectId3, VersionStamp.Default, "Three", "Three", LanguageNames.CSharp, filePath: "Three.csproj")); var project2Reference = new ProjectReference(projectId2); var project3Reference = new ProjectReference(projectId3); SolutionWithDependentProject = Workspace.CurrentSolution .AddProject(ProjectInfo.Create( projectId1, VersionStamp.Default, "One", "One", LanguageNames.CSharp, filePath: "One.csproj", documents: new[] { cshtmlDocumentInfo, razorDocumentInfo, partialComponentClassDocumentInfo, backgroundDocumentInfo }, projectReferences: new[] { project2Reference })) .AddProject(ProjectInfo.Create( projectId2, VersionStamp.Default, "Two", "Two", LanguageNames.CSharp, filePath: "Two.csproj", projectReferences: new[] { project3Reference })) .AddProject(ProjectInfo.Create( projectId3, VersionStamp.Default, "Three", "Three", LanguageNames.CSharp, filePath: "Three.csproj", documents: new[] { razorDocumentInfo })); ProjectNumberOne = SolutionWithTwoProjects.GetProject(projectId1); ProjectNumberTwo = SolutionWithTwoProjects.GetProject(projectId2); ProjectNumberThree = SolutionWithOneProject.GetProject(projectId3); HostProjectOne = new HostProject("One.csproj", FallbackRazorConfiguration.MVC_1_1, "One"); HostProjectTwo = new HostProject("Two.csproj", FallbackRazorConfiguration.MVC_1_1, "Two"); HostProjectThree = new HostProject("Three.csproj", FallbackRazorConfiguration.MVC_1_1, "Three"); WorkQueue = new BatchingWorkQueue(TimeSpan.FromMilliseconds(1), StringComparer.Ordinal, new DefaultErrorReporter()); WorkQueueTestAccessor = WorkQueue.GetTestAccessor(); WorkQueue.GetTestAccessor().NotifyBackgroundWorkCompleted = null; WorkQueueTestAccessor.NotifyBackgroundWorkCompleted = new ManualResetEventSlim(initialState: false); }