private async Task StopCoverage()
        {
            var mockSuitableCoverageProject = new Mock <ICoverageProject>();

            mockSuitableCoverageProject.Setup(p => p.ProjectFile).Returns("Defined.csproj");
            mockSuitableCoverageProject.Setup(p => p.Settings.Enabled).Returns(true);

            mockSuitableCoverageProject.Setup(p => p.PrepareForCoverageAsync()).Callback(() =>
            {
                fccEngine.StopCoverage();
            }).Returns(Task.CompletedTask);

            await ReloadInitializedCoverage(mockSuitableCoverageProject.Object);
        }
 public void Should_Not_Throw_When_StopCoverage_And_There_Is_No_Coverage_Running()
 {
     fccEngine.StopCoverage();
 }
        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);
            }
        }