Example #1
0
        private static void WriteMarkdown(string output, DocumentComparison docComparison)
        {
            var build = new StringBuilder();

            build.AppendLine($"#{docComparison.TestNamePrefix} ({docComparison.WhenUtc:u})");
            build.AppendLine();
            build.AppendLine("Comparison of:");
            build.AppendLine();
            build.AppendLine($"* Reference: [{docComparison.ReferenceDocumentPath}]({docComparison.ReferenceDocumentPath})");
            build.AppendLine($"* Test File: [{docComparison.TestDocumentPath}]({docComparison.TestDocumentPath})");
            build.AppendLine();
            build.AppendLine($"There {(docComparison.CountPages > 1 ? "were" : "was")} {docComparison.CountPages} page{(docComparison.CountPages > 1 ? "s" : "")}.");
            build.AppendLine();
            build.AppendLine($"{docComparison.CountPagesWithDifferences} page{(docComparison.CountPagesWithDifferences > 1 ? "s" : "")} had differences.");
            build.AppendLine();
            build.AppendLine("##Page Details");
            build.AppendLine();
            build.AppendLine("| Reference | Difference | Test File | ");
            build.AppendLine("|---|---|---|");

            foreach (var page in docComparison.PageComparisons)
            {
                build.AppendLine($"| {(ImageLink("reference", page))} | {(ImageLink("result", page))} | {(ImageLink("test", page))} |");
            }

            File.WriteAllText(output, build.ToString());
        }
Example #2
0
        public static string DoComparison(string testNamePrefix, string outputBasePath, string referencePdf, string testFilePdf)
        {
            var when = DateTime.UtcNow;

            var outputPath    = Path.Combine(outputBasePath, $"{testNamePrefix}_{when:yy_MM_dd_HH_mm_ss}");
            var referencePath = Path.Combine(outputPath, PageComparison.ReferenceRelativePath);
            var testPath      = Path.Combine(outputPath, PageComparison.TestRelativePath);
            var resultPath    = Path.Combine(outputPath, PageComparison.ResultRelativePath);

            Directory.CreateDirectory(outputPath);
            Directory.CreateDirectory(referencePath);
            Directory.CreateDirectory(testPath);
            Directory.CreateDirectory(resultPath);

            var referencePages = Split(referencePdf, referencePath);
            var testPages      = Split(testFilePdf, testPath);

            var compareResults = Compare(Math.Max(referencePages, testPages), outputPath, referencePath, testPath, resultPath);

            var docComparison = new DocumentComparison()
            {
                WhenUtc               = when,
                FolderName            = outputPath,
                TestNamePrefix        = testNamePrefix,
                TestDocumentPath      = testFilePdf,
                ReferenceDocumentPath = referencePdf,
                PageComparisons       = compareResults.ToList()
            };

            return(WriteOutputs(outputPath, docComparison));
        }
Example #3
0
        private static string WriteOutputs(string outputPath, DocumentComparison docComparison)
        {
            var resultFilePath = Path.Combine(outputPath, "results.json");
            var json           = JsonConvert.SerializeObject(docComparison, Formatting.Indented);

            File.WriteAllText(resultFilePath, json);

            var md   = Path.ChangeExtension(resultFilePath, "md");
            var html = Path.ChangeExtension(resultFilePath, "html");

            WriteMarkdown(md, docComparison);
            CreateHtmlFromMarkdown(md, html);
            return(resultFilePath);
        }