public async Task TryHandleCommandAsync_BuildInProgress() { var tree = ProjectTreeParser.Parse(@" Root (flags: {ProjectRoot}) "); var nodes = ImmutableHashSet.Create(tree.Root); bool buildStarted = false, buildCancelled = false, buildCompleted = false; void onUpdateSolutionBegin() => buildStarted = true; void onUpdateSolutionCancel() => buildCancelled = true; void onUpdateSolutionDone() => buildCompleted = true; var solutionEventsListener = IVsUpdateSolutionEventsFactory.Create(onUpdateSolutionBegin, onUpdateSolutionCancel, onUpdateSolutionDone); var command = CreateInstance(solutionEventsListener: solutionEventsListener, isBuilding: true); // Ensure we handle the command, but don't invoke build as there is a build already in progress. var handled = await command.TryHandleCommandAsync(nodes, GetCommandId(), true, 0, IntPtr.Zero, IntPtr.Zero); Assert.True(handled); Assert.False(buildStarted); Assert.False(buildCompleted); Assert.False(buildCancelled); }
public async Task TryHandleCommandAsync_OnBuildCancelled() { bool buildStarted = false, buildCancelled = false, buildCompleted = false; void onUpdateSolutionBegin() { buildStarted = true; } void onUpdateSolutionCancel() { buildCancelled = true; } void onUpdateSolutionDone() { buildCompleted = true; } var solutionEventsListener = IVsUpdateSolutionEventsFactory.Create(onUpdateSolutionBegin, onUpdateSolutionCancel, onUpdateSolutionDone); var command = CreateInstance(solutionEventsListener: solutionEventsListener, cancelBuild: true); var tree = ProjectTreeParser.Parse(@" Root (flags: {ProjectRoot}) "); var nodes = ImmutableHashSet.Create(tree.Root); var result = await command.TryHandleCommandAsync(nodes, GetCommandId(), true, 0, IntPtr.Zero, IntPtr.Zero); Assert.True(result); Assert.True(buildStarted); Assert.False(buildCompleted); Assert.True(buildCancelled); }
public static ISolutionBuildManager Create( IVsUpdateSolutionEvents?solutionEventsListener = null, IVsHierarchy?hierarchyToBuild = null, bool isBuilding = false, bool cancelBuild = false) { var buildManager = new Mock <ISolutionBuildManager>(); solutionEventsListener ??= IVsUpdateSolutionEventsFactory.Create(); hierarchyToBuild ??= IVsHierarchyFactory.Create(); int isBusy = isBuilding ? 1 : 0; buildManager.Setup(b => b.QueryBuildManagerBusy()) .Returns(isBusy); if (hierarchyToBuild != null) { void onBuildStartedWithReturn(IVsHierarchy[] _, uint[] __, uint ___) { solutionEventsListener !.UpdateSolution_Begin(It.IsAny <int>()); if (cancelBuild) { solutionEventsListener.UpdateSolution_Cancel(); } else { solutionEventsListener.UpdateSolution_Done(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <int>()); } } buildManager.Setup(b => b.StartUpdateSpecificProjectConfigurations(It.IsAny <IVsHierarchy[]>(), It.IsAny <uint[]>(), It.IsAny <uint>())) .Callback((System.Action <IVsHierarchy[], uint[], uint>)onBuildStartedWithReturn); } return(buildManager.Object); }