public async Task SolutionClosing_CancelsActiveWork() { // Arrange var projectManager = new TestProjectSnapshotManager(Workspace) { AllowNotifyListeners = true, }; var expectedProjectPath = SomeProject.FilePath; var expectedProjectSnapshot = await Dispatcher.RunOnDispatcherThreadAsync(() => { projectManager.ProjectAdded(SomeProject); projectManager.ProjectAdded(SomeOtherProject); return(projectManager.GetLoadedProject(SomeProject.FilePath)); }, CancellationToken.None); var projectService = new Mock <TextBufferProjectService>(MockBehavior.Strict); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(TestServiceProvider.Instance, projectService.Object, workspaceStateGenerator, Dispatcher, JoinableTaskFactory.Context); trigger.Initialize(projectManager); trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(MockBehavior.Strict), pCfgProj: default, pCfgSln: default, dwAction: default, fSuccess: default, fCancel: default);
public void UpdateProjectCfg_Done_KnownProject_Invokes_WorkspaceProjectChanged() { // Arrange var expectedProjectPath = SomeProject.FilePath; uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectService = new Mock <TextBufferProjectService>(); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var projectSnapshots = new[] { new DefaultProjectSnapshot(ProjectState.Create(Workspace.Services, SomeProject, SomeWorkspaceProject)), new DefaultProjectSnapshot(ProjectState.Create(Workspace.Services, SomeOtherProject, SomeOtherWorkspaceProject)), }; var called = false; var projectManager = new Mock <ProjectSnapshotManagerBase>(); projectManager.SetupGet(p => p.Workspace).Returns(Workspace); projectManager .Setup(p => p.GetLoadedProject(expectedProjectPath)) .Returns(projectSnapshots[0]); projectManager .Setup(p => p.WorkspaceProjectChanged(It.IsAny <Project>())) .Callback <Project>(c => { called = true; Assert.Equal(expectedProjectPath, c.FilePath); }); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object); trigger.Initialize(projectManager.Object); // Act trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(), Mock.Of <IVsCfg>(), Mock.Of <IVsCfg>(), 0, 0, 0); // Assert Assert.True(called); }
public void UpdateProjectCfg_Done_KnownProject_Invokes_ProjectBuildComplete() { // Arrange var expectedProjectName = "Test1"; var expectedProjectPath = "Path/To/Project"; uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectService = new Mock <TextBufferProjectService>(); projectService.Setup(p => p.GetProjectName(It.IsAny <IVsHierarchy>())).Returns(expectedProjectName); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var workspace = TestWorkspace.Create(ws => { CreateProjectInWorkspace(ws, expectedProjectName, expectedProjectPath); CreateProjectInWorkspace(ws, "Test2", "Path/To/AnotherProject"); }); var called = false; var projectManager = new Mock <ProjectSnapshotManagerBase>(); projectManager.SetupGet(p => p.Workspace).Returns(workspace); projectManager .Setup(p => p.ProjectBuildComplete(It.IsAny <Project>())) .Callback <Project>(c => { called = true; Assert.Equal(expectedProjectName, c.Name); }); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object); trigger.Initialize(projectManager.Object); // Act trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(), Mock.Of <IVsCfg>(), Mock.Of <IVsCfg>(), 0, 0, 0); // Assert Assert.True(called); }
public void UpdateProjectCfg_Done_KnownProject_Invokes_ProjectBuildComplete() { // Arrange var expectedProjectPath = "Path/To/Project"; uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectService = new Mock <TextBufferProjectService>(); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var projectSnapshots = new[] { Mock.Of <ProjectSnapshot>(p => p.FilePath == expectedProjectPath && p.HostProject == new HostProject(expectedProjectPath, RazorConfiguration.Default)), Mock.Of <ProjectSnapshot>(p => p.FilePath == "Test2.csproj" && p.HostProject == new HostProject("Test2.csproj", RazorConfiguration.Default)), }; var called = false; var projectManager = new Mock <ProjectSnapshotManagerBase>(); projectManager.SetupGet(p => p.Projects).Returns(projectSnapshots); projectManager .Setup(p => p.HostProjectBuildComplete(It.IsAny <HostProject>())) .Callback <HostProject>(c => { called = true; Assert.Equal(expectedProjectPath, c.FilePath); }); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object); trigger.Initialize(projectManager.Object); // Act trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(), Mock.Of <IVsCfg>(), Mock.Of <IVsCfg>(), 0, 0, 0); // Assert Assert.True(called); }
public void UpdateProjectCfg_Done_KnownProject_EnqueuesProjectStateUpdate() { // Arrange var expectedProjectPath = SomeProject.FilePath; uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(MockBehavior.Strict); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectService = new Mock <TextBufferProjectService>(MockBehavior.Strict); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var projectSnapshots = new[] { new DefaultProjectSnapshot(ProjectState.Create(Workspace.Services, SomeProject)), new DefaultProjectSnapshot(ProjectState.Create(Workspace.Services, SomeOtherProject)), }; var projectManager = new Mock <ProjectSnapshotManagerBase>(MockBehavior.Strict); projectManager.SetupGet(p => p.Workspace).Returns(Workspace); projectManager .Setup(p => p.GetLoadedProject(expectedProjectPath)) .Returns(projectSnapshots[0]); var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object, workspaceStateGenerator); trigger.Initialize(projectManager.Object); // Act trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(MockBehavior.Strict), Mock.Of <IVsCfg>(MockBehavior.Strict), Mock.Of <IVsCfg>(MockBehavior.Strict), 0, 0, 0); // Assert var update = Assert.Single(workspaceStateGenerator.UpdateQueue); Assert.Equal(update.workspaceProject.Id, SomeWorkspaceProject.Id); Assert.Same(update.projectSnapshot, projectSnapshots[0]); }
public void UpdateProjectCfg_Done_UnknownProject_DoesNotInvoke_WorkspaceProjectChanged() { // Arrange var expectedProjectPath = "Path/To/Project"; uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectService = new Mock <TextBufferProjectService>(); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var projectSnapshots = new[] { new DefaultProjectSnapshot(ProjectState.Create(Workspace.Services, SomeProject, SomeWorkspaceProject)), new DefaultProjectSnapshot(ProjectState.Create(Workspace.Services, SomeOtherProject, SomeOtherWorkspaceProject)), }; var projectManager = new Mock <ProjectSnapshotManagerBase>(); projectManager.SetupGet(p => p.Workspace).Returns(Workspace); projectManager .Setup(p => p.GetLoadedProject(expectedProjectPath)) .Returns((ProjectSnapshot)null); projectManager .Setup(p => p.WorkspaceProjectChanged(It.IsAny <Project>())) .Callback <Project>(c => { throw new InvalidOperationException("This should not be called."); }); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object); trigger.Initialize(projectManager.Object); // Act & Assert - Does not throw trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(), Mock.Of <IVsCfg>(), Mock.Of <IVsCfg>(), 0, 0, 0); }
public void UpdateProjectCfg_Done_UnknownProject_DoesNotInvoke_ProjectBuildComplete() { // Arrange var expectedProjectName = "Test1"; var expectedProjectPath = "Path/To/Project"; uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectService = new Mock <TextBufferProjectService>(); projectService.Setup(p => p.GetProjectName(It.IsAny <IVsHierarchy>())).Returns(expectedProjectName); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var workspace = new AdhocWorkspace(); CreateProjectInWorkspace(workspace, "Test2", "Path/To/AnotherProject"); CreateProjectInWorkspace(workspace, "Test3", "Path/To/DifferenProject"); var projectManager = new Mock <ProjectSnapshotManagerBase>(); projectManager.SetupGet(p => p.Workspace).Returns(workspace); projectManager .Setup(p => p.ProjectBuildComplete(It.IsAny <Project>())) .Callback <Project>(c => { throw new InvalidOperationException("This should not be called."); }); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object); trigger.Initialize(projectManager.Object); // Act & Assert - Does not throw trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(), Mock.Of <IVsCfg>(), Mock.Of <IVsCfg>(), 0, 0, 0); }
public void UpdateProjectCfg_Done_WithoutWorkspaceProject_DoesNotEnqueueUpdate() { // Arrange uint cookie; var buildManager = new Mock <IVsSolutionBuildManager>(MockBehavior.Strict); buildManager .Setup(b => b.AdviseUpdateSolutionEvents(It.IsAny <VsSolutionUpdatesProjectSnapshotChangeTrigger>(), out cookie)) .Returns(VSConstants.S_OK); var services = new Mock <IServiceProvider>(MockBehavior.Strict); services.Setup(s => s.GetService(It.Is <Type>(f => f == typeof(SVsSolutionBuildManager)))).Returns(buildManager.Object); var projectSnapshot = new DefaultProjectSnapshot( ProjectState.Create( Workspace.Services, new HostProject("/Some/Unknown/Path.csproj", RazorConfiguration.Default, "Path"))); var expectedProjectPath = projectSnapshot.FilePath; var projectService = new Mock <TextBufferProjectService>(MockBehavior.Strict); projectService.Setup(p => p.GetProjectPath(It.IsAny <IVsHierarchy>())).Returns(expectedProjectPath); var projectManager = new Mock <ProjectSnapshotManagerBase>(MockBehavior.Strict); projectManager.SetupGet(p => p.Workspace).Returns(Workspace); projectManager .Setup(p => p.GetLoadedProject(expectedProjectPath)) .Returns(projectSnapshot); var workspaceStateGenerator = new TestProjectWorkspaceStateGenerator(); var trigger = new VsSolutionUpdatesProjectSnapshotChangeTrigger(services.Object, projectService.Object, workspaceStateGenerator); trigger.Initialize(projectManager.Object); // Act trigger.UpdateProjectCfg_Done(Mock.Of <IVsHierarchy>(MockBehavior.Strict), Mock.Of <IVsCfg>(MockBehavior.Strict), Mock.Of <IVsCfg>(MockBehavior.Strict), 0, 0, 0); // Assert Assert.Empty(workspaceStateGenerator.UpdateQueue); }