Пример #1
0
        public void CanGroupQualityConditionsWithCompleteExclusion()
        {
            var catA   = new DataQualityCategory("A");
            var catA1  = new DataQualityCategory("A1");
            var catA11 = new DataQualityCategory("A11");

            catA.AddSubCategory(catA1);
            catA1.AddSubCategory(catA11);

            var test = new TestDescriptor("test", new ClassDescriptor(typeof(QaMinSegAngle)));

            var qc1 = new QualityCondition("qc1", test)
            {
                Category = catA11
            };
            var qc2 = new QualityCondition("qc2", test)
            {
                Category = catA11
            };
            var qc3 = new QualityCondition("qc3", test)
            {
                Category = catA11
            };

            var issueGroups = new List <IssueGroup>
            {
                CreateIssueGroup(qc1, "ic1", 3),
                CreateIssueGroup(qc2, "ic2", 4),
                CreateIssueGroup(qc3, "ic3", 5),
                CreateIssueGroup(qc3, "ic4", 6)
            };

            var reportDefinition = new HtmlReportDefinition(
                "templatepath", "fileName",
                new List <HtmlDataQualityCategoryOptions>
            {
                new HtmlDataQualityCategoryOptions(catA.Uuid, ignoreCategoryLevel: true),
                new HtmlDataQualityCategoryOptions(catA1.Uuid, ignoreCategoryLevel: true),
                new HtmlDataQualityCategoryOptions(catA11.Uuid, ignoreCategoryLevel: true),
            });

            List <HtmlReportIssueGroup>          reportIssueGroups;
            List <HtmlReportDataQualityCategory> reportCategories =
                GroupByCategories(issueGroups, reportDefinition,
                                  out reportIssueGroups);

            Assert.AreEqual(4, reportIssueGroups.Count);
            Assert.AreEqual(18, reportIssueGroups.Sum(ig => ig.IssueCount));

            Assert.AreEqual(1, reportCategories.Count);
            Assert.AreEqual(18, reportCategories.Sum(qc => qc.IssueCount));

            List <HtmlReportDataQualityCategory> rootCategories =
                reportCategories.Where(qc => qc.IsRoot)
                .ToList();

            Assert.AreEqual(1, rootCategories.Count);
            Assert.AreEqual(18, rootCategories.Sum(qc => qc.IssueCountWithChildren));
        }
        public static List <string> WriteHtmlReports(
            [NotNull] QualitySpecification qualitySpecification,
            [NotNull] string directory,
            [NotNull] IssueStatistics issueStatistics,
            [NotNull] XmlVerificationReport verificationReport,
            [NotNull] string verificationReportFileName,
            [CanBeNull] string defaultReportTemplatePath = null,
            [CanBeNull] XmlVerificationOptions options   = null,
            [CanBeNull] string issueGdbPath = null,
            [CanBeNull] IList <string> issueMapFilePaths = null,
            [CanBeNull] IList <string> qualitySpecificationReportFilePaths = null)
        {
            string defaultTemplateDirectory =
                VerificationOptionUtils.GetDefaultTemplateDirectory(options);

            var reportDefinitions = new List <HtmlReportDefinition>();

            foreach (XmlHtmlReportOptions reportOptions in
                     VerificationOptionUtils.GetHtmlReportOptions(
                         options, defaultReportTemplatePath))
            {
                HtmlReportDefinition reportDefinition =
                    VerificationOptionUtils.GetReportDefinition(reportOptions,
                                                                defaultReportTemplatePath,
                                                                defaultTemplateDirectory);
                if (!File.Exists(reportDefinition.TemplatePath))
                {
                    _msg.WarnFormat("Template file does not exist: {0}",
                                    reportOptions.TemplatePath);
                    continue;
                }

                reportDefinitions.Add(reportDefinition);
            }

            List <string> filePaths =
                reportDefinitions.Select(d => Path.Combine(directory, d.FileName))
                .ToList();

            foreach (HtmlReportDefinition reportDefinition in reportDefinitions)
            {
                WriteHtmlReport(qualitySpecification, directory,
                                reportDefinition,
                                issueStatistics, verificationReport,
                                verificationReportFileName,
                                issueGdbPath,
                                issueMapFilePaths,
                                filePaths,
                                qualitySpecificationReportFilePaths);
            }

            return(filePaths);
        }
        private static void WriteHtmlReport(
            [NotNull] QualitySpecification qualitySpecification,
            [NotNull] string directory,
            [NotNull] HtmlReportDefinition reportDefinition,
            [NotNull] IssueStatistics issueStatistics,
            [NotNull] XmlVerificationReport verificationReport,
            [NotNull] string verificationReportFileName,
            [CanBeNull] string issueGdbPath,
            [CanBeNull] IEnumerable <string> issueMapFilePaths,
            [NotNull] IEnumerable <string> htmlReportFileNames,
            [CanBeNull] IEnumerable <string> qualitySpecificationReportFilePaths)
        {
            Assert.ArgumentNotNull(reportDefinition, nameof(reportDefinition));
            Assert.ArgumentCondition(File.Exists(reportDefinition.TemplatePath),
                                     "Template file does not exist: {0}",
                                     reportDefinition.TemplatePath);

            string reportFilePath = Path.Combine(directory, reportDefinition.FileName);

            _msg.DebugFormat("Preparing html report model");
            var reportModel = new HtmlReportModel(qualitySpecification,
                                                  issueStatistics,
                                                  verificationReport,
                                                  directory,
                                                  verificationReportFileName,
                                                  issueGdbPath,
                                                  issueMapFilePaths,
                                                  htmlReportFileNames,
                                                  qualitySpecificationReportFilePaths,
                                                  reportDefinition);

            _msg.DebugFormat("Rendering html report based on template {0}",
                             reportDefinition.TemplatePath);

            LiquidUtils.RegisterSafeType <HtmlReportModel>();
            LiquidUtils.RegisterSafeType <HtmlTexts>();

            string output = LiquidUtils.Render(
                reportDefinition.TemplatePath,
                new KeyValuePair <string, object>("report", reportModel),
                new KeyValuePair <string, object>("text", new HtmlTexts()));

            _msg.DebugFormat("Writing html report to {0}", reportFilePath);
            FileSystemUtils.WriteTextFile(output, reportFilePath);

            _msg.InfoFormat("Html report written to {0}", reportFilePath);
        }