Exemplo n.º 1
0
        public static void ReloadCoverage(IEnumerable <CoverageProject> projects, bool darkMode)
        {
            // reset

            ClearProcesses();

            HtmlFilePath = null;

            CoverageLines.Clear();

            // process pipeline

            projects = projects
                       .Select(project =>
            {
                project.ProjectFileXElement = XElementUtil.Load(project.ProjectFile, true);
                project.Settings            = GetSettings(project);

                if (!project.Settings.Enabled)
                {
                    project.FailureDescription = $"Disabled";
                    return(project);
                }

                if (string.IsNullOrWhiteSpace(project.ProjectFile))
                {
                    project.FailureDescription = $"Unsupported project type for DLL '{project.TestDllFile}'";
                    return(project);
                }

                project.CoverageOutputFolder = Path.Combine(project.ProjectOutputFolder, "fine-code-coverage");
                project.CoverageOutputFile   = Path.Combine(project.CoverageOutputFolder, "project.coverage.xml");
                project.IsDotNetSdkStyle     = IsDotNetSdkStyle(project);
                project.ReferencedProjects   = GetReferencedProjects(project);
                project.HasExcludeFromCodeCoverageAssemblyAttribute = HasExcludeFromCodeCoverageAssemblyAttribute(project.ProjectFileXElement);
                project.AssemblyName = GetAssemblyName(project.ProjectFileXElement, Path.GetFileNameWithoutExtension(project.ProjectFile));

                project.EnsureEmptyOutputFolder();

                try
                {
                    var legacyOutputFolder = Path.Combine(project.ProjectOutputFolder, "_outputFolder");
                    Directory.Delete(legacyOutputFolder, true);
                }
                catch
                {
                    // ignore
                }

                return(project);
            })
                       .Select(p => p.Step("Run Coverage Tool", project =>
            {
                // run the appropriate cover tool

                if (project.IsDotNetSdkStyle)
                {
                    CoverletUtil.RunCoverlet(project, true);
                }
                else
                {
                    OpenCoverUtil.RunOpenCover(project, true);
                }
            }))
                       .Where(x => !x.HasFailed)
                       .ToArray();

            // project files

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

            if (!coverOutputFiles.Any())
            {
                return;
            }

            // run reportGenerator process

            ReportGeneratorUtil.RunReportGenerator(coverOutputFiles, darkMode, out var unifiedHtmlFile, out var unifiedXmlFile, true);

            // update CoverageLines

            CoverageReport = CoberturaUtil.ProcessCoberturaXmlFile(unifiedXmlFile, out var coverageLines);
            CoverageLines  = coverageLines;

            // update HtmlFilePath

            ReportGeneratorUtil.ProcessUnifiedHtmlFile(unifiedHtmlFile, darkMode, out var coverageHtml);
            HtmlFilePath = coverageHtml;
        }
Exemplo n.º 2
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);
        }