public static string RenderHtmlQualitySpecification(
            [NotNull] HtmlQualitySpecification qualitySpecification,
            [NotNull] string templateFilePath,
            [NotNull] string reportFilePath,
            bool throwTemplateErrors = false)
        {
            Assert.ArgumentNotNull(qualitySpecification, nameof(qualitySpecification));
            Assert.ArgumentNotNullOrEmpty(templateFilePath, nameof(templateFilePath));
            Assert.ArgumentNotNullOrEmpty(reportFilePath, nameof(reportFilePath));
            Assert.ArgumentCondition(File.Exists(templateFilePath),
                                     "template file does not exist: {0}",
                                     (object)templateFilePath);

            _msg.DebugFormat(
                "Rendering quality specification documentation based on template {0}",
                templateFilePath);

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

            const string rootName = "specification";

            string output = LiquidUtils.Render(
                templateFilePath,
                throwTemplateErrors,
                new KeyValuePair <string, object>(rootName, qualitySpecification),
                new KeyValuePair <string, object>("text", new HtmlTexts()));

            _msg.DebugFormat("Writing quality specification report to {0}", reportFilePath);

            FileSystemUtils.WriteTextFile(output, reportFilePath);

            _msg.InfoFormat("Quality specification report written to {0}", reportFilePath);
            return(reportFilePath);
        }
示例#2
0
        public void RenderNameValuePairKeyAccessTest()
        {
            var dictionary = new Dictionary <string, object>
            {
                {
                    "header",
                    new NameValuePairs(new Dictionary <string, string>
                    {
                        { "NAME1", "VALUE1" },
                        { "NAME2", "VALUE2" },
                        { "NAME3", "VALUE3" },
                    })
                },
            };

            Template.NamingConvention = new CSharpNamingConvention();
            LiquidUtils.RegisterSafeType <NameValuePairs>();

            Hash hash = Hash.FromDictionary(dictionary);

            // Note: keys are case sensitive
            // Note: unknown name results in empty string
            Template template = Template.Parse("name 1: {{ header.Value.NAME1 }} " +
                                               "name 2: {{ header.Value.NAME2 }} " +
                                               "name 3: {{ header.Value.NAME3 }} " +
                                               "name 4: {{ header.Value.NAME4 }}");

            string output = template.Render(hash);

            Console.WriteLine(output);

            Assert.AreEqual("name 1: VALUE1 name 2: VALUE2 name 3: VALUE3 name 4: ", output);
        }
        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);
        }
示例#4
0
        public void LiquidUtilsRenderTest()
        {
            const string tempFolder = @"C:\Temp";

            Assert.True(Directory.Exists(tempFolder), "Directory {0} does not exist",
                        tempFolder);

            string templateFileName = Path.Combine(tempFolder, @"test.html.tpl");
            string reportFileName   = Path.Combine(tempFolder, @"report.html");

            File.Delete(templateFileName);
            File.Delete(reportFileName);

            var report = new TestReport();

            report.StartTime = new DateTime(2000, 12, 31, 23, 59, 58);
            report.AddVerifiedDataset(new VerifiedDataset("ds1", "ws1"));
            report.AddVerifiedDataset(new VerifiedDataset("ds2", "ws2"));

            var sb = new StringBuilder();

            sb.AppendLine(
                "<html><head><title>LiquidUtilsRenderTest{{report.StartTime}}</title></head>");
            sb.AppendLine("<body>");
            sb.AppendLine("<table>");
            sb.AppendLine("{% for dataset in report.VerifiedDatasets -%}");
            sb.AppendLine(
                "<tr><td>dataset:</td><td>{{dataset.Name}}</td><td>{{dataset.WorkspaceName | Upcase}}</td></tr>");
            sb.AppendLine("{% endfor -%}");
            sb.AppendLine("</table>");
            sb.AppendLine("</body>");
            sb.AppendLine("</html>");
            FileSystemUtils.WriteTextFile(sb.ToString(), templateFileName);
            Assert.True(File.Exists(templateFileName), "{0} does not exist", templateFileName);

            LiquidUtils.RegisterSafeType <TestReport>();
            string output = LiquidUtils.Render(templateFileName, report, "report");

            Assert.True(output.Length > 0, "output is empty");

            FileSystemUtils.WriteTextFile(output, reportFileName);
            Assert.True(File.Exists(reportFileName), "{0} does not exist", reportFileName);
        }
示例#5
0
        public void RenderHierarchyTest()
        {
            var items = new List <Item>
            {
                new Item("A",
                         new[]
                {
                    new Item("A1"),
                    new Item("A2")
                }),
                new Item("B",
                         new[]
                {
                    new Item("B1",
                             new[]
                    {
                        new Item("B11")
                    })
                }),
                new Item("C")
            };

            Template.NamingConvention = new CSharpNamingConvention();
            LiquidUtils.RegisterSafeType <Item>(recurse: false);

            Hash hash = Hash.FromDictionary(new Dictionary <string, object> {
                { "items", items }
            });

            Template.FileSystem = new HardcodedFileSystem("<ul><li>{{ item.Name }}" +
                                                          "{% include 'item' with item.Children %}" +
                                                          "</li></ul>");

            Template template = Template.Parse("<html>{% include 'item' with items %}</html>");

            string output = template.Render(hash);

            Console.WriteLine(output);

            Assert.AreEqual(
                @"<html><ul><li>A<ul><li>A1</li></ul><ul><li>A2</li></ul></li></ul><ul><li>B<ul><li>B1<ul><li>B11</li></ul></li></ul></li></ul><ul><li>C</li></ul></html>",
                output);
        }
示例#6
0
        public void RenderIteratedNameValuePairsTest()
        {
            var input = new Dictionary <string, string>
            {
                { "NAME1", "VALUE1" },
                { "NAME2", "VALUE2" },
                { "NAME3", "VALUE3" },
            };

            var dictionary = new Dictionary <string, object>
            {
                { "header", new NameValuePairs(input) },
            };

            Template.NamingConvention = new CSharpNamingConvention();
            LiquidUtils.RegisterSafeType <NameValuePairs>();

            RegisterSafeType <NameValuePair>();

            Hash hash = Hash.FromDictionary(dictionary);

            var sb = new StringBuilder();

            sb.AppendLine("{% for entry in header.Entries -%}");
            sb.AppendLine("- {{ entry.Name }}: {{ entry.Value }}");
            sb.AppendLine("{% endfor -%}");

            Template template = Template.Parse(sb.ToString());

            string output = template.Render(hash);

            Console.WriteLine(output);

            string expected = "- NAME1: VALUE1" + Environment.NewLine +
                              "- NAME2: VALUE2" + Environment.NewLine +
                              "- NAME3: VALUE3" + Environment.NewLine;

            Assert.AreEqual(expected, output);
        }