Beispiel #1
0
        /// <summary>
        /// Writes a coverage report in the configured format.
        /// </summary>
        /// <param name="models">The models to include in the coverage file.</param>
        /// <param name="configuration">The report configuration,</param>
        public void WriteReport(IEnumerable <CoverageNodeModel> models, ReportConfigurationModel configuration)
        {
            Contract.RequiresNotNull(models, nameof(models));
            Contract.Requires(models.Any(), "No coverage data to create a report for.", nameof(models));
            Contract.RequiresNotNull(configuration, nameof(configuration));

            ReportWriter writer;

            switch (configuration.ReportFormat)
            {
            case ReportFormat.HtmlSingleFile:
                writer = new HtmlSingleFileReportWriter();
                break;

            case ReportFormat.HtmlMultiFile:
                writer = new HtmlMultiFileReportWriter();
                break;

            default:
                throw Utility.UnreachableCode("Unexpected report type.");
            }

            CoverageDSPriv merged      = ConcatenateFiles(models.Select(CreateSerializable));
            var            reportModel = new CoverageExport(configuration.ProjectName, merged);

            writer.WriteReport(reportModel, configuration);
        }
Beispiel #2
0
        /// <summary>
        /// Creates a temporary file containing the given coverage data.
        /// </summary>
        /// <param name="dataset">The data to write to the temporary file.</param>
        /// <returns>A disposable wrapper for the temporary file.</returns>
        protected static TempFile WriteToTempFile(CoverageExport dataset)
        {
            var tempFile = new TempFile();

            var ser = new XmlSerializer(typeof(CoverageExport));

            ser.Serialize(tempFile.Stream, dataset);

            tempFile.ResetPosition();

            return(tempFile);
        }
Beispiel #3
0
        /// <inheritdoc />
        public override void WriteReport(CoverageExport dataset, ReportConfigurationModel configuration)
        {
            using (var tempFile = WriteToTempFile(dataset))
            {
                var transform = new XslCompiledTransform();
                using (var xslReader = XmlReader.Create(new StringReader(Resources.HTMLTransform)))
                {
                    transform.Load(xslReader);
                }

                var args = new XsltArgumentList();

                args.AddParam(ReportConstants.HtmlGenDate, "",
                              DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"));

                args.AddParam(ReportConstants.HtmlTotalLines, "",
                              dataset.LinesCovered + dataset.LinesPartiallyCovered + dataset.LinesNotCovered);

                args.AddParam(ReportConstants.HtmlTotalBlocks, "",
                              dataset.BlocksCovered + dataset.BlocksNotCovered);

                args.AddParam(ReportConstants.HtmlExpansionDepth, "",
                              (int)configuration.DefaultExpansion);

                args.AddParam("jQuerySource", "",
                              ReportConstants.JQueryCDNLocation);


                using (var outputFile = new FileStream(configuration.DestinationPath, FileMode.Create, FileAccess.Write))
                {
                    using (var tempReader = XmlReader.Create(tempFile.Stream))
                    {
                        transform.Transform(tempReader, args, outputFile);
                    }
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Writes a report containing the given coverage data.
 /// </summary>
 /// <param name="dataset">The coverage dataset to write to the report.</param>
 /// <param name="configuration">The report configuration.</param>
 public abstract void WriteReport(CoverageExport dataset, ReportConfigurationModel configuration);
        /// <inheritdoc />
        /// <devdoc>
        /// This will delete a pre-existing _files folder. Be sure the user has at least seen an
        /// overwrite prompt for the web page by now!
        /// </devdoc>
        public override void WriteReport(CoverageExport dataset, ReportConfigurationModel configuration)
        {
            EnsureJQueryIsCached();

            // Note (Windows-specific):
            // when a web page ("Page.html") is accompanied by a folder named like "Page_files",
            // windows will try to keep the folder with the html page when moved, and warn if one of
            // these are renamed (since the other will not be, and any links in the page will not work).
            string filesDirName = Path.GetFileNameWithoutExtension(configuration.DestinationPath) + "_files";
            string filesDirPath = Path.Combine(Path.GetDirectoryName(configuration.DestinationPath), filesDirName);


            // make sure we're working with a fresh files folder.
            var filesDir = new DirectoryInfo(filesDirPath);

            if (filesDir.Exists)
            {
                filesDir.Delete(recursive: true);
            }
            filesDir.Create();


            string jQueryFullPath = Path.Combine(filesDirPath, ReportConstants.JQueryFileName);

            File.Copy(JQueryCachedPath, jQueryFullPath);


            using (var tempFile = WriteToTempFile(dataset))
            {
                var transform = new XslCompiledTransform();
                using (var xslReader = XmlReader.Create(new StringReader(Resources.HTMLTransform)))
                {
                    transform.Load(xslReader);
                }

                var args = new XsltArgumentList();

                args.AddParam(ReportConstants.HtmlGenDate, "",
                              DateTime.Now.ToString("dd MMM yyyy HH:mm:ss"));

                args.AddParam(ReportConstants.HtmlTotalLines, "",
                              dataset.LinesCovered + dataset.LinesPartiallyCovered + dataset.LinesNotCovered);

                args.AddParam(ReportConstants.HtmlTotalBlocks, "",
                              dataset.BlocksCovered + dataset.BlocksNotCovered);

                args.AddParam(ReportConstants.HtmlExpansionDepth, "",
                              (int)configuration.DefaultExpansion);

                args.AddParam("jQuerySource", "",
                              Path.Combine(filesDirName, ReportConstants.JQueryFileName));


                using (var outputFile = new FileStream(configuration.DestinationPath, FileMode.Create, FileAccess.Write))
                {
                    using (var tempReader = XmlReader.Create(tempFile.Stream))
                    {
                        transform.Transform(tempReader, args, outputFile);
                    }
                }
            }
        }