Esempio n. 1
0
        public void ClearUI()
        {
            CoverageLines = null;
            UpdateMarginTags?.Invoke(new UpdateMarginTagsEventArgs());

            UpdateOutputWindow?.Invoke(new UpdateOutputWindowEventArgs {
            });
        }
Esempio n. 2
0
        public static void TryReloadCoverage(Func <AppOptions, List <CoverageProject> > coverageProjectFactory)
        {
            var settings  = AppOptions.Get();
            var canReload = settings.Enabled;

            if (!canReload)
            {
                CoverageLines.Clear();
                UpdateMarginTags?.Invoke(null);
                UpdateOutputWindow?.Invoke(null);
            }

            if (canReload)
            {
                var coverageProjects = coverageProjectFactory(settings);
                if (coverageProjects != null)
                {
                    ReloadCoverage(coverageProjects);
                }
            }
        }
Esempio n. 3
0
        private void RaiseUpdateOutputWindow(string reportFilePath)
        {
            UpdateOutputWindowEventArgs updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs {
            };

            try
            {
                if (!string.IsNullOrEmpty(reportFilePath))
                {
                    var htmlContent = File.ReadAllText(reportFilePath);
                    updateOutputWindowEventArgs.HtmlContent = htmlContent;
                }
            }
            catch
            {
                logger.Log(errorReadingReportGeneratorOutputMessage);
            }
            finally
            {
                UpdateOutputWindow?.Invoke(updateOutputWindowEventArgs);
            }
        }
        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);
            }
        }
Esempio n. 5
0
        private static void ReloadCoverage(List <CoverageProject> projects)
        {
            Logger.Log("================================== START ==================================");

            Reset();

            var coverageTask = System.Threading.Tasks.Task.Run(async() =>
            {
                // process pipeline

                await PrepareCoverageProjectsAsync(projects);

                foreach (var project in projects)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    await project.StepAsync("Run Coverage Tool", RunCoverToolAsync);
                }

                var passedProjects = projects.Where(x => !x.HasFailed);

                var coverOutputFiles = passedProjects
                                       .Select(x => x.CoverageOutputFile)
                                       .ToArray();

                if (coverOutputFiles.Any())
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    // run reportGenerator process

                    var darkMode = CurrentTheme.Equals("Dark", StringComparison.OrdinalIgnoreCase);

                    var result = await ReportGeneratorUtil.RunReportGeneratorAsync(coverOutputFiles, darkMode, true);

                    if (result.Success)
                    {
                        // update CoverageLines

                        CoverageReport = CoberturaUtil.ProcessCoberturaXmlFile(result.UnifiedXmlFile, out var coverageLines);
                        CoverageLines  = coverageLines;
                        // update HtmlFilePath

                        ReportGeneratorUtil.ProcessUnifiedHtmlFile(result.UnifiedHtmlFile, darkMode, out var htmlFilePath);
                        HtmlFilePath = htmlFilePath;
                    }

                    // update margins

                    {
                        UpdateMarginTagsEventArgs updateMarginTagsEventArgs = null;

                        try
                        {
                            updateMarginTagsEventArgs = new UpdateMarginTagsEventArgs
                            {
                            };
                        }
                        catch
                        {
                            // ignore
                        }
                        finally
                        {
                            UpdateMarginTags?.Invoke(updateMarginTagsEventArgs);
                        }
                    }

                    // update output window

                    {
                        UpdateOutputWindowEventArgs updateOutputWindowEventArgs = null;

                        try
                        {
                            if (!string.IsNullOrEmpty(HtmlFilePath))
                            {
                                updateOutputWindowEventArgs = new UpdateOutputWindowEventArgs
                                {
                                    HtmlContent = File.ReadAllText(HtmlFilePath)
                                };
                            }
                        }
                        catch
                        {
                            // ignore
                        }
                        finally
                        {
                            UpdateOutputWindow?.Invoke(updateOutputWindowEventArgs);
                        }
                    }
                }


                // log

                Logger.Log("================================== DONE ===================================");

                cancellationTokenSource.Dispose();
                cancellationTokenSource = null;
            }, cancellationToken);
        }
        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);
            }
        }