private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { RunAsync(async() => { await TryAndLogExceptionAsync(() => OperationState_StateChangedAsync(e)); }); }
private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs operationStateChangedEventArgs) { if (onTestRunCompleted && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished)) { PlaySafe(testCompleteSoundPlayer); } }
private async Task OperationState_StateChangedAsync(OperationStateChangedEventArgs e) { if (testOperationStateChangeHandlers.TryGetValue(e.State, out var handler)) { await handler(e.Operation); } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { if (e.State == TestOperationStates.TestExecutionFinished) { var s = e.Operation; } }
public static void OnChangeDetected(object sender, OperationStateChangedEventArgs stateArgs) { if (ClearCoverageOnChange) { CoverageRepository.ClearAll(); } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionCanceling) { fccEngine.StopCoverage(); } if (e.State == TestOperationStates.TestExecutionStarting) { TestExecutionStarting(e.Operation); } if (e.State == TestOperationStates.TestExecutionFinished) { TestExecutionFinished(e.Operation); } } catch (Exception exception) { logger.Log("Error processing unit test events", exception); } }
private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs operationStateChangedEventArgs) { if (Options.IsBeepOnTestComplete && operationStateChangedEventArgs.State.HasFlag(TestOperationStates.TestExecutionFinished)) { try { // Issue #8: VS 2015 stops working when looking at Test Manager Window #8 // This extention can't take dependency on Microsoft.VisualStudio.TestWindow.Core.dll // Because it will crash VS 2015. But DominantTestState is defined in that assembly. // So as a workaround - cast it to dynamic (ewww, but alternative - to create new project/build and publish it separately.) var testOperation = (dynamic)(operationStateChangedEventArgs.Operation); var dominantTestState = (TestState)testOperation.DominantTestState; var isTestsFailed = dominantTestState == TestState.Failed; var eventType = isTestsFailed ? EventType.TestsCompletedFailure : EventType.TestsCompletedSuccess; if (Options.IsBeepOnTestFailed && isTestsFailed) { HandleEventSafe(eventType, "Test execution failed!", ToolTipIcon.Error); } else { HandleEventSafe(eventType, "Test execution has been completed."); } } catch (Exception ex) { ActivityLog.LogError(GetType().FullName, ex.Message); // Unable to get dominate test status, beep default sound for test HandleEventSafe(EventType.TestsCompletedSuccess, "Test execution has been completed."); } } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionFinished) { Logger.Clear(); Logger.Log("Updating coverage ..."); var operationType = e.Operation.GetType(); var testConfiguration = (operationType.GetProperty("Configuration") ?? operationType.GetProperty("Configuration", BindingFlags.Instance | BindingFlags.NonPublic)).GetValue(e.Operation); var testConfigurationSources = (IEnumerable <string>)testConfiguration.GetType().GetProperty("TestSources").GetValue(testConfiguration); foreach (var testDllFile in testConfigurationSources) { CoverageUtil.LoadCoverageFromTestDllFile(testDllFile, exception => { if (exception != null) { Logger.Log(exception); return; } TaggerProvider.ReloadTags(); Logger.Log("Coverage updated!"); }); } } } catch (Exception exception) { Logger.Log(exception); } }
private void OperationOnStateChanged(object sender, OperationStateChangedEventArgs e) { State = e.OperationState; switch (State) { case OperationState.NotStarted: case OperationState.InProgress: case OperationState.Blocked: case OperationState.Paused: case OperationState.Pausing: case OperationState.Unpausing: case OperationState.Cancelling: case OperationState.Skipped: break; case OperationState.Finished: case OperationState.Cancelled: case OperationState.Failed: UnsubscribeFromEvents(); break; default: throw new ArgumentOutOfRangeException(nameof(State), State, null); } }
private void StateChange(object sender, OperationStateChangedEventArgs e) { if (e.State == TestOperationStates.TestExecutionFinished) { var resultUris = e.Operation.GetRunSettingsDataCollectorResultUri(PythonCodeCoverageUri); if (resultUris != null) { foreach (var eachAttachment in resultUris) { string filePath = eachAttachment.LocalPath; if (File.Exists(filePath)) { object inObj = filePath; object outObj = null; var dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); dte.Commands.Raise( GuidList.guidPythonToolsCmdSet.ToString("B"), cmdidImportCoverage, ref inObj, ref outObj ); } } } } }
public static void OnTestExecutionFinished(object sender, OperationStateChangedEventArgs stateArgs) { lock (_coverageSession) { var _sessions = _coverageSession.Keys.ToList(); if (!_sessions.Any()) { return; } foreach (var sessionKey in _sessions) { var result = _coverageSession[sessionKey].GetCoverageResult(); var covergeDetails = Loaders.CoverletLoader.LoadCoverage(result); foreach (var cd in covergeDetails) { CoverageRepository.AddUpdateCoverage(cd.SourceFile, cd.CoveredFile, cd.LineVisits); } } } reloadTaggers(); }
private void OperationOnStateChanged(object sender, OperationStateChangedEventArgs e) { var operation = (IOperation)sender; if (e.OperationState.IsCompleted()) { RemoveOperation(operation); } }
private void OperationOnStateChanged(object sender, OperationStateChangedEventArgs e) { var operation = (IOperation)sender; if (e.OperationState == OperationState.Finished || e.OperationState == OperationState.Cancelled) { RemoveOperation(operation); } }
private void OperationStateChanged(object sender, OperationStateChangedEventArgs e) { if (e.State == TestOperationStates.ChangeDetectionStarting) { this.detectingChanges = true; } else if (e.State == TestOperationStates.ChangeDetectionFinished) { this.detectingChanges = false; } }
private void OperationStateOnStateChanged(object sender, OperationStateChangedEventArgs args) { if (args.State.HasFlag(TestOperationStates.TestExecutionStarted)) { Output("Test execution started"); sm.On(VSStateMachine.Events.TestStarted); } else if (args.State.HasFlag(TestOperationStates.TestExecutionFinished)) { Output("Test execution finished"); sm.On(VSStateMachine.Events.TestFinished); } }
public void TestRemovingOperation() { Assert.Empty(_operationsStateService.ActiveOperations); var operationMock = new Mock <IOperation>(); _operationsStateService.AddOperation(operationMock.Object); var args = new OperationStateChangedEventArgs(OperationState.Finished); operationMock.Raise(m => m.StateChanged += null, args); Assert.Empty(_operationsStateService.ActiveOperations); }
public void TestOperationChangedState() { Assert.Empty(_operationsStateService.ActiveOperations); var operationMock = new Mock <IOperation>(); _operationsStateService.AddOperation(operationMock.Object); var args = new OperationStateChangedEventArgs(OperationState.InProgress); operationMock.Raise(m => m.StateChanged += null, args); Assert.NotEmpty(_operationsStateService.ActiveOperations); }
public void TestIncorrectState() { var viewModel = _autoMocker.CreateInstance <OperationStateViewModel>(); Assert.Equal(0, viewModel.Progress); const OperationState operationState = (OperationState)42; var args = new OperationStateChangedEventArgs(operationState); void RaiseEvent() => _autoMocker .GetMock <IOperation>() .Raise(o => o.StateChanged += null, args); Assert.Throws <ArgumentOutOfRangeException>(RaiseEvent); Assert.Equal(0, viewModel.Progress); }
private void CurrentOperationOnStateChanged(object sender, OperationStateChangedEventArgs e) { if (e.OperationState != OperationState.Finished) { return; } var operation = (IInternalOperation)sender; UnsubscribeFromEvents(operation); var finishedOperationsCount = Interlocked.Increment(ref _finishedOperationsCount); if (finishedOperationsCount == _groupOperationsCount) { _taskCompletionSource.SetResult(true); } CurrentProgress = (double)finishedOperationsCount / _totalOperationsCount; }
private async void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { if (e.State == TestOperationStates.TestExecutionStarted) { InfoControl.ResetBackgroundColor(); } else if (e.State == TestOperationStates.TestExecutionFinished) { IEnumerable <ITest> tests; try { IDisposableQuery <ITest> obsoleteTests = await TestsService.GetTestsAsync(); tests = obsoleteTests.AsEnumerable(); } catch { tests = await TestsService.GetTestsAsEnumerableAsync(); } InfoControl.UpdateWithTestResult(tests); } }
public static void OnTestExecutionStarting(object sender, OperationStateChangedEventArgs stateArgs) { _coverageSession = new Dictionary <string, Coverlet.Core.Coverage>(); // You can get this lovely DLL in your visual studio directory Microsoft.VisualStudio.TestWindow.Core.dll // var g = ((Microsoft.VisualStudio.TestWindow.Controller.Request)stateArgs.Operation); // If you know a better to get the actual "DLL path" without doing a Directory.Get files.. please let me know try { // This works for VS2017 but not for 2019 due to them sealing the DLL's // Track this for the fix https://github.com/ppumkin/PrestoCoverage/issues/17 var testRequestConfiguration = stateArgs.Operation.GetType() .GetProperty("Configuration", BindingFlags.NonPublic | BindingFlags.Instance) .GetValue(stateArgs.Operation) as Microsoft.VisualStudio.TestWindow.Controller.TestRunConfiguration; if (testRequestConfiguration.Debug) { return; } foreach (var testDll in testRequestConfiguration.TestSources) { //Hacky McHack face here. lots of cool settings and stuff we can expand on but this just gets it going bare bones var _coverage = new Coverlet.Core.Coverage(testDll, new string[0], new string[0], new string[0], new string[0], new string[0], true, string.Empty, false, null); _coverage.PrepareModules(); _coverageSession.Add(testDll, _coverage); } } catch (Exception ex) { return; } }
private void StateChange(object sender, OperationStateChangedEventArgs e) { if (e.State == TestOperationStates.TestExecutionFinished) { var resultUris = e.Operation.GetRunSettingsDataCollectorResultUri(PythonCodeCoverageUri); if (resultUris != null) { foreach (var eachAttachment in resultUris) { string filePath = eachAttachment.LocalPath; if (File.Exists(filePath)) { object inObj = filePath; object outObj = null; var dte = (EnvDTE.DTE)_serviceProvider.GetService(typeof(EnvDTE.DTE)); dte.Commands.Raise( GuidList.guidPythonToolsCmdSet.ToString("B"), cmdidImportCoverage, ref inObj, ref outObj ); } } } } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionStarting) { StopCoverageProcess(); // just to be sure } if (e.State == TestOperationStates.TestExecutionFinished) { var settings = AppOptions.Get(); if (!settings.Enabled) { FCCEngine.CoverageLines.Clear(); UpdateMarginTags?.Invoke(this, null); UpdateOutputWindow?.Invoke(this, null); return; } Logger.Log("================================== START =================================="); var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase); CoverageProject[] projects = null; try { var testConfiguration = new Operation(e.Operation).Configuration; var userRunSettings = testConfiguration.UserRunSettings; var runSettingsRetriever = new RunSettingsRetriever(); var testContainers = testConfiguration.Containers; projects = testConfiguration.Containers.Select(container => { var project = new CoverageProject(); project.ProjectName = container.ProjectName; project.TestDllFile = container.Source; project.Is64Bit = container.TargetPlatform.ToString().ToLower().Equals("x64"); var containerData = container.ProjectData; project.ProjectFile = container.ProjectData.ProjectFilePath; project.RunSettingsFile = ThreadHelper.JoinableTaskFactory.Run(() => runSettingsRetriever.GetRunSettingsFileAsync(userRunSettings, containerData)); return(project); }).ToArray(); }catch (Exception exc) { throw new Exception("Error test container discoverer reflection", exc); } _reloadCoverageThread = new Thread(() => { try { // compute coverage FCCEngine.ReloadCoverage(projects, darkMode); // update margins { UpdateMarginTagsEventArgs updateMarginTagsEventArgs = null; try { updateMarginTagsEventArgs = new UpdateMarginTagsEventArgs { }; } catch { // ignore } finally { UpdateMarginTags?.Invoke(this, updateMarginTagsEventArgs); } } // update output window { UpdateOutputWindowEventArgs updateOutputWindowEventArgs = null; try { updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs { HtmlContent = File.ReadAllText(FCCEngine.HtmlFilePath) }; } catch { // ignore } finally { UpdateOutputWindow?.Invoke(this, updateOutputWindowEventArgs); } } // log Logger.Log("================================== DONE ==================================="); } catch (Exception exception) { if (!(exception is ThreadAbortException) && _reloadCoverageThread != null) { Logger.Log("Error", exception); Logger.Log("================================== ERROR =================================="); } } }); _reloadCoverageThread.Start(); } } catch (Exception exception) { Logger.Log("Error processing unit test events", exception); } }
public async Task TestBlockedOperationCancel() { var taskCompletionSource = new TaskCompletionSource <bool>(); _autoMocker .Setup <IApplicationDispatcher>(m => m.Dispatch(It.IsAny <Action>())) .Callback <Action>(action => action()); _autoMocker .Setup <IApplicationDispatcher>(m => m.DispatchAsync(It.IsAny <Func <Task> >())) .Callback <Func <Task> >(async func => { await func(); taskCompletionSource.SetResult(true); }); var viewModel = _autoMocker.CreateInstance <OperationsStatesListViewModel>(); var state = OperationState.InProgress; var operationMock = new Mock <IOperation>(); operationMock .Setup(m => m.CancelAsync()) .Verifiable(); operationMock .SetupGet(m => m.State) .Returns(() => state); operationMock .SetupGet(m => m.CurrentBlockedFile) .Returns((Source, Destination)); var array = new string[0]; var dictionary = new Dictionary <string, string>(); for (var i = 0; i < 5; i++) { dictionary[i.ToString()] = i.ToString(); } var settings = new BinaryFileSystemOperationSettings( array, array, array, array, dictionary, array); var operationInfo = new OperationInfo(OperationType.Copy, settings); operationMock .SetupGet(m => m.Info) .Returns(operationInfo); var operationStartedEventArgs = new OperationStartedEventArgs(operationMock.Object); _autoMocker .GetMock <IOperationsStateService>() .Raise(m => m.OperationStarted += null, operationStartedEventArgs); Assert.True(viewModel.AreAnyOperationsAvailable); state = OperationState.Blocked; var operationStateChangedEventArgs = new OperationStateChangedEventArgs(state); operationMock.Raise(m => m.StateChanged += null, operationStateChangedEventArgs); Assert.True(viewModel.AreAnyOperationsAvailable); var task = await Task.WhenAny(Task.Delay(1000), taskCompletionSource.Task); if (task != taskCompletionSource.Task) { taskCompletionSource.SetResult(false); } var result = await taskCompletionSource.Task; Assert.True(result); await Task.Delay(500); operationMock.Verify(m => m.CancelAsync(), Times.Once); }
public async Task TestInProgressOperation(OperationState operationState, bool isLastSuccessful) { var stateViewModelMock = new Mock <IOperationStateViewModel>(); stateViewModelMock .Setup(m => m.State) .Returns(operationState); _autoMocker .Setup <IApplicationDispatcher>(m => m.Dispatch(It.IsAny <Action>())) .Callback <Action>(action => action()); _autoMocker .Setup <IOperationStateViewModelFactory, IOperationStateViewModel>(m => m.Create(It.IsAny <IOperation>())) .Returns(stateViewModelMock.Object); var configuration = new OperationsStatesConfiguration { MaximumFinishedOperationsCount = 1 }; _autoMocker.Use(configuration); var viewModel = _autoMocker.CreateInstance <OperationsStatesListViewModel>(); var state = OperationState.InProgress; var operationMock = new Mock <IOperation>(); operationMock .SetupGet(m => m.State) .Returns(() => state); var array = new string[0]; var dictionary = new Dictionary <string, string>(); for (var i = 0; i < 5; i++) { dictionary[i.ToString()] = i.ToString(); } var settings = new BinaryFileSystemOperationSettings( array, array, array, array, dictionary, array); var operationInfo = new OperationInfo(OperationType.Copy, settings); operationMock .SetupGet(m => m.Info) .Returns(operationInfo); Assert.False(viewModel.IsInProgress); Assert.Equal(0, viewModel.TotalProgress); var operationStartedEventArgs = new OperationStartedEventArgs(operationMock.Object); _autoMocker .GetMock <IOperationsStateService>() .Raise(m => m.OperationStarted += null, operationStartedEventArgs); Assert.NotEmpty(viewModel.ActiveOperations); Assert.Single(viewModel.ActiveOperations); Assert.Empty(viewModel.InactiveOperations); _autoMocker .Setup <IOperationsStateService, IReadOnlyList <IOperation> >(m => m.ActiveOperations) .Returns(new[] { operationMock.Object }); const double progress = 0.5; var args = new OperationProgressChangedEventArgs(progress); operationMock .Setup(m => m.CurrentProgress) .Returns(progress); operationMock .Raise(m => m.ProgressChanged += null, args); Assert.NotEmpty(viewModel.ActiveOperations); Assert.Single(viewModel.ActiveOperations); Assert.Empty(viewModel.InactiveOperations); Assert.True(viewModel.IsInProgress); Assert.Equal(50, viewModel.TotalProgress); var taskCompletionSource = new TaskCompletionSource <bool>(); _autoMocker .Setup <IApplicationDispatcher>(m => m.Dispatch(It.IsAny <Action>())) .Callback <Action>(action => { action(); taskCompletionSource.SetResult(true); }); state = operationState; var finishedArgs = new OperationStateChangedEventArgs(state); operationMock .Raise(m => m.StateChanged += null, finishedArgs); var task = await Task.WhenAny(Task.Delay(1000), taskCompletionSource.Task); if (task != taskCompletionSource.Task) { taskCompletionSource.SetResult(false); } var result = await taskCompletionSource.Task; Assert.True(result); Assert.NotEmpty(viewModel.InactiveOperations); Assert.Single(viewModel.InactiveOperations); Assert.Empty(viewModel.ActiveOperations); Assert.Equal(viewModel.IsLastOperationSuccessful, isLastSuccessful); }
private void OperationOnStateChanged(object sender, OperationStateChangedEventArgs e) => UpdateOperationStatus((IOperation)sender);
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { switch (e.State) { case TestOperationStates.None: break; case TestOperationStates.Starting: break; case TestOperationStates.Started: break; case TestOperationStates.Cancel: break; case TestOperationStates.Canceling: break; case TestOperationStates.Finished: break; case TestOperationStates.Canceled: break; case TestOperationStates.Discovery: break; case TestOperationStates.TestExecution: break; case TestOperationStates.ChangeDetection: break; case TestOperationStates.PlaylistRefresh: break; case TestOperationStates.ChangeDetectionStarting: PrestoCoverageCore.OnChangeDetected(this, e); break; case TestOperationStates.ChangeDetectionFinished: break; case TestOperationStates.DiscoveryStarting: break; case TestOperationStates.DiscoveryStarted: break; case TestOperationStates.DiscoveryFinished: break; case TestOperationStates.DiscoveryCanceled: break; case TestOperationStates.TestExecutionStarting: PrestoCoverageCore.OnTestExecutionStarting(this, e); break; case TestOperationStates.TestExecutionStarted: break; case TestOperationStates.TestExecutionCanceling: break; case TestOperationStates.TestExecutionFinished: PrestoCoverageCore.OnTestExecutionFinished(this, e); break; case TestOperationStates.TestExecutionCancelAndFinished: break; case TestOperationStates.PlaylistRefreshStarting: break; case TestOperationStates.PlaylistRefreshFinished: break; case TestOperationStates.OperationSetStarted: break; case TestOperationStates.OperationSetFinished: break; default: break; } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionStarting) { try { _reloadCoverageThread?.Abort(); } catch { // ignore } finally { _reloadCoverageThread = null; FCCEngine.ClearProcesses(); } } if (e.State == TestOperationStates.TestExecutionFinished) { var settings = AppOptions.Get(); if (!settings.Enabled) { FCCEngine.CoverageLines.Clear(); UpdateMarginTags?.Invoke(this, null); UpdateOutputWindow?.Invoke(this, null); return; } Logger.Log("================================== START =================================="); var operationType = e.Operation.GetType(); var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase); var testConfiguration = (operationType.GetProperty("Configuration") ?? operationType.GetProperty("Configuration", BindingFlags.Instance | BindingFlags.NonPublic)).GetValue(e.Operation); var testContainers = ((IEnumerable <object>)testConfiguration.GetType().GetProperty("Containers").GetValue(testConfiguration)).ToArray(); var projects = new List <CoverageProject>(); foreach (var container in testContainers) { var project = new CoverageProject(); var containerType = container.GetType(); var containerData = containerType.GetProperty("ProjectData").GetValue(container); var containerDataType = containerData.GetType(); project.ProjectGuid = containerType.GetProperty("ProjectGuid").GetValue(container).ToString(); project.ProjectName = containerType.GetProperty("ProjectName").GetValue(container).ToString(); project.TestDllFileInOutputFolder = containerType.GetProperty("Source").GetValue(container).ToString(); project.TestDllCompilationMode = AssemblyUtil.GetCompilationMode(project.TestDllFileInOutputFolder); project.ProjectFile = containerDataType.GetProperty("ProjectFilePath", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic).GetValue(containerData).ToString(); var defaultOutputFolder = Path.GetDirectoryName(containerDataType.GetProperty("DefaultOutputPath", BindingFlags.Instance | BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.NonPublic).GetValue(containerData).ToString()); project.WorkFolder = Path.Combine(Path.GetDirectoryName(defaultOutputFolder), "fine-code-coverage"); projects.Add(project); } _reloadCoverageThread = new Thread(() => { try { // compute coverage FCCEngine.ReloadCoverage(projects.ToArray(), darkMode); // update margins { UpdateMarginTagsEventArgs updateMarginTagsEventArgs = null; try { updateMarginTagsEventArgs = new UpdateMarginTagsEventArgs { }; } catch { // ignore } finally { UpdateMarginTags?.Invoke(this, updateMarginTagsEventArgs); } } // update output window { UpdateOutputWindowEventArgs updateOutputWindowEventArgs = null; try { updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs { HtmlContent = File.ReadAllText(FCCEngine.HtmlFilePath) }; } catch { // ignore } finally { UpdateOutputWindow?.Invoke(this, updateOutputWindowEventArgs); } } // log Logger.Log("================================== DONE ==================================="); } catch (Exception exception) { if (!(exception is ThreadAbortException) && _reloadCoverageThread != null) { Logger.Log("Error", exception); Logger.Log("================================== ERROR =================================="); } } }); _reloadCoverageThread.Start(); } } catch (Exception exception) { Logger.Log("Error processing unit test events", exception); } }
private void OperationState_StateChanged(object sender, OperationStateChangedEventArgs e) { try { if (e.State == TestOperationStates.TestExecutionCanceling) { FCCEngine.StopCoverage(); } if (e.State == TestOperationStates.TestExecutionStarting) { FCCEngine.StopCoverage(); FCCEngine.TryReloadCoverage(settings => { if (!settings.RunInParallel) { return(null); } return(GetCoverageProjects(new Operation(e.Operation).Configuration)); }); } if (e.State == TestOperationStates.TestExecutionFinished) { FCCEngine.TryReloadCoverage(settings => { if (settings.RunInParallel) { return(null); } var operation = new Operation(e.Operation); if (!settings.RunWhenTestsFail && operation.Response.FailedTests > 0) { Logger.Log($"Skipping coverage due to failed tests. Option {nameof(AppOptions.RunWhenTestsFail)} is false"); return(null); } var totalTests = operation.TotalTests; var runWhenTestsExceed = settings.RunWhenTestsExceed; if (totalTests > 0) // in case this changes to not reporting total tests { if (totalTests <= runWhenTestsExceed) { Logger.Log($"Skipping coverage as total tests ({totalTests}) <= {nameof(AppOptions.RunWhenTestsExceed)} ({runWhenTestsExceed})"); return(null); } } return(GetCoverageProjects(operation.Configuration)); }); } } catch (PropertyDoesNotExistException propertyDoesNotExistException) { Logger.Log("Error test container discoverer reflection"); throw new Exception(propertyDoesNotExistException.Message); } catch (Exception exception) { Logger.Log("Error processing unit test events", exception); } }
private void OperationStateChanged(object sender, OperationStateChangedEventArgs e) { if (e.State == TestOperationStates.ChangeDetectionStarting) { _detectingChanges = true; } else if (e.State == TestOperationStates.ChangeDetectionFinished) { _detectingChanges = false; } }
public async Task TestBlockedOperationCancel(bool areMultipleFilesAvailable, int filesCount) { var taskCompletionSource = new TaskCompletionSource <bool>(); var options = OperationContinuationOptions.CreateContinuationOptions(FilePath, true, OperationContinuationMode.Skip); var operationsStateServiceMock = new Mock <IOperationsStateService>(); var operationStateViewModelFactoryMock = new Mock <IOperationStateViewModelFactory>(); var applicationDispatcherMock = new Mock <IApplicationDispatcher>(); applicationDispatcherMock .Setup(m => m.Dispatch(It.IsAny <Action>())) .Callback <Action>(action => action()); applicationDispatcherMock .Setup(m => m.DispatchAsync(It.IsAny <Func <Task> >())) .Callback <Func <Task> >(async func => { await func(); taskCompletionSource.SetResult(true); }); var dialogServiceMock = new Mock <IDialogService>(); dialogServiceMock .Setup(m => m.ShowDialogAsync <OverwriteOptionsDialogResult, OverwriteOptionsNavigationParameter>( nameof(OverwriteOptionsDialogViewModel), It.IsAny <OverwriteOptionsNavigationParameter>())) .Callback <string, OverwriteOptionsNavigationParameter>((_, p) => { Assert.Equal(areMultipleFilesAvailable, p.AreMultipleFilesAvailable); Assert.Equal(Source, p.SourceFilePath); Assert.Equal(Destination, p.DestinationFilePath); }) .Returns(Task.FromResult(new OverwriteOptionsDialogResult(options))); var viewModel = new OperationsStatesListViewModel( operationsStateServiceMock.Object, operationStateViewModelFactoryMock.Object, applicationDispatcherMock.Object, dialogServiceMock.Object); var state = OperationState.InProgress; var operationMock = new Mock <IOperation>(); operationMock .Setup(m => m.ContinueAsync(options)) .Verifiable(); operationMock .SetupGet(m => m.State) .Returns(() => state); operationMock .SetupGet(m => m.CurrentBlockedFile) .Returns((Source, Destination)); var array = new string[0]; var dictionary = new Dictionary <string, string>(); for (var i = 0; i < filesCount; i++) { dictionary[i.ToString()] = i.ToString(); } var settings = new BinaryFileSystemOperationSettings( array, array, array, array, dictionary, array); var operationInfo = new OperationInfo(OperationType.Copy, settings); operationMock .SetupGet(m => m.Info) .Returns(operationInfo); var operationStartedEventArgs = new OperationStartedEventArgs(operationMock.Object); operationsStateServiceMock.Raise(m => m.OperationStarted += null, operationStartedEventArgs); Assert.True(viewModel.AreAnyOperationsAvailable); state = OperationState.Blocked; var operationStateChangedEventArgs = new OperationStateChangedEventArgs(state); operationMock.Raise(m => m.StateChanged += null, operationStateChangedEventArgs); Assert.True(viewModel.AreAnyOperationsAvailable); var task = await Task.WhenAny(Task.Delay(1000), taskCompletionSource.Task); if (task != taskCompletionSource.Task) { taskCompletionSource.SetResult(false); } var result = await taskCompletionSource.Task; Assert.True(result); await Task.Delay(500); operationMock.Verify(m => m.ContinueAsync(options), Times.Once()); }