From 64985dff7199b273b188cd8c043d6341d6cf34ed Mon Sep 17 00:00:00 2001 From: dpvreony Date: Thu, 6 Apr 2023 15:41:05 +0100 Subject: [PATCH 01/16] add ability to run PDF generation via Docset API --- src/Microsoft.DocAsCode.App/Docset.cs | 52 +++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DocAsCode.App/Docset.cs b/src/Microsoft.DocAsCode.App/Docset.cs index 8fa71cee795..2642fc4c495 100644 --- a/src/Microsoft.DocAsCode.App/Docset.cs +++ b/src/Microsoft.DocAsCode.App/Docset.cs @@ -37,9 +37,57 @@ public static Task Build(string configPath, BuildOptions options) { var configDirectory = Path.GetDirectoryName(Path.GetFullPath(configPath)); + var defaultSerializer = JsonUtility.DefaultSerializer.Value; + + var config = JObject.Parse(File.ReadAllText(configPath)); + if (config.TryGetValue("build", out var build)) + RunBuild.Exec(build.ToObject(defaultSerializer), options, configDirectory); + + return Task.CompletedTask; + } + finally + { + Logger.Flush(); + Logger.PrintSummary(); + Logger.UnregisterAllListeners(); + } + } + + /// + /// Builds a pdf specified by docfx.json config. + /// + /// The path to docfx.json config file. + /// The build options. + /// A task to await for build completion. + public static Task Pdf(string configPath, BuildOptions options) + { + return Exec( + configPath, + options, + "pdf", + RunPdf.Exec); + } + + private static Task Exec( + string configPath, + BuildOptions options, + string elementKey, + Action execAction) + { + var consoleLogListener = new ConsoleLogListener(); + Logger.RegisterListener(consoleLogListener); + + try + { + var configDirectory = Path.GetDirectoryName(Path.GetFullPath(configPath)); + + var defaultSerializer = JsonUtility.DefaultSerializer.Value; + var config = JObject.Parse(File.ReadAllText(configPath)); - if (config.TryGetValue("build", out var value)) - RunBuild.Exec(value.ToObject(JsonUtility.DefaultSerializer.Value), options, configDirectory); + + if (config.TryGetValue(elementKey, out var pdf)) + execAction(pdf.ToObject(defaultSerializer), options, configDirectory, null); + return Task.CompletedTask; } finally From a7c00f0c6b300b52eaef3de799bea23642c84b4b Mon Sep 17 00:00:00 2001 From: dpvreony Date: Thu, 6 Apr 2023 15:42:32 +0100 Subject: [PATCH 02/16] refactor build to use exec helper --- src/Microsoft.DocAsCode.App/Docset.cs | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Microsoft.DocAsCode.App/Docset.cs b/src/Microsoft.DocAsCode.App/Docset.cs index 2642fc4c495..d04b65efec1 100644 --- a/src/Microsoft.DocAsCode.App/Docset.cs +++ b/src/Microsoft.DocAsCode.App/Docset.cs @@ -30,27 +30,11 @@ public static Task Build(string configPath) /// A task to await for build completion. public static Task Build(string configPath, BuildOptions options) { - var consoleLogListener = new ConsoleLogListener(); - Logger.RegisterListener(consoleLogListener); - - try - { - var configDirectory = Path.GetDirectoryName(Path.GetFullPath(configPath)); - - var defaultSerializer = JsonUtility.DefaultSerializer.Value; - - var config = JObject.Parse(File.ReadAllText(configPath)); - if (config.TryGetValue("build", out var build)) - RunBuild.Exec(build.ToObject(defaultSerializer), options, configDirectory); - - return Task.CompletedTask; - } - finally - { - Logger.Flush(); - Logger.PrintSummary(); - Logger.UnregisterAllListeners(); - } + return Exec( + configPath, + options, + "build", + RunBuild.Exec); } /// From a432fe1b4df108a6427b9db29712e072b8c959d6 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Thu, 6 Apr 2023 15:43:40 +0100 Subject: [PATCH 03/16] rename pdf variable --- src/Microsoft.DocAsCode.App/Docset.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.DocAsCode.App/Docset.cs b/src/Microsoft.DocAsCode.App/Docset.cs index d04b65efec1..dd50e4491ed 100644 --- a/src/Microsoft.DocAsCode.App/Docset.cs +++ b/src/Microsoft.DocAsCode.App/Docset.cs @@ -69,8 +69,8 @@ private static Task Exec( var config = JObject.Parse(File.ReadAllText(configPath)); - if (config.TryGetValue(elementKey, out var pdf)) - execAction(pdf.ToObject(defaultSerializer), options, configDirectory, null); + if (config.TryGetValue(elementKey, out var value)) + execAction(value.ToObject(defaultSerializer), options, configDirectory, null); return Task.CompletedTask; } From 59a41976a2ccd65801a5fd438a912aaa11b93dda Mon Sep 17 00:00:00 2001 From: dpvreony Date: Mon, 3 Jul 2023 21:56:53 +0100 Subject: [PATCH 04/16] remove method groups --- src/Microsoft.DocAsCode.App/Docset.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.DocAsCode.App/Docset.cs b/src/Microsoft.DocAsCode.App/Docset.cs index 1025d3db92d..d9ada1fad53 100644 --- a/src/Microsoft.DocAsCode.App/Docset.cs +++ b/src/Microsoft.DocAsCode.App/Docset.cs @@ -21,7 +21,7 @@ public static Task Build(string configPath) { return Build(configPath, new()); } - + /// /// Builds a docset specified by docfx.json config. /// @@ -34,7 +34,17 @@ public static Task Build(string configPath, BuildOptions options) configPath, options, "build", - RunBuild.Exec); + (config, exeOptions, configDirectory, outputDirectory) => RunBuild.Exec(config, exeOptions, configDirectory, outputDirectory)); + } + + /// + /// Builds a pdf specified by docfx.json config. + /// + /// The path to docfx.json config file. + /// A task to await for build completion. + public static Task Pdf(string configPath) + { + return Pdf(configPath, new()); } /// @@ -49,14 +59,14 @@ public static Task Pdf(string configPath, BuildOptions options) configPath, options, "pdf", - RunPdf.Exec); + (config, exeOptions, configDirectory, outputDirectory) => RunPdf.Exec(config, exeOptions, configDirectory, outputDirectory)); } private static Task Exec( string configPath, BuildOptions options, string elementKey, - Action execAction) + Action execAction) { var consoleLogListener = new ConsoleLogListener(); Logger.RegisterListener(consoleLogListener); @@ -70,7 +80,13 @@ private static Task Exec( var config = JObject.Parse(File.ReadAllText(configPath)); if (config.TryGetValue(elementKey, out var value)) + { execAction(value.ToObject(defaultSerializer), options, configDirectory, null); + } + else + { + Logger.LogError($"Unable to find '{elementKey}' in '{configPath}'."); + } return Task.CompletedTask; } From 2938e01a6fc7bef5fbc00f0b03d7b9c26a8c80c9 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Mon, 3 Jul 2023 23:10:43 +0100 Subject: [PATCH 05/16] prep for pdf unit tests --- test/docfx.Snapshot.Tests/SamplesTest.cs | 21 +++ test/docfx.Tests/DocsetTest.cs | 167 +++++++++++++++++++++++ 2 files changed, 188 insertions(+) diff --git a/test/docfx.Snapshot.Tests/SamplesTest.cs b/test/docfx.Snapshot.Tests/SamplesTest.cs index 75cf878025d..4164bb51fee 100644 --- a/test/docfx.Snapshot.Tests/SamplesTest.cs +++ b/test/docfx.Snapshot.Tests/SamplesTest.cs @@ -193,6 +193,27 @@ public async Task CSharp() await Verifier.VerifyDirectory($"{samplePath}/_site", IncludeFile).AutoVerify(includeBuildServer: false); } + [SnapshotFact] + public async Task CSharpPdf() + { + var samplePath = $"{s_samplesDir}/csharp"; + Clean(samplePath); + + Environment.SetEnvironmentVariable("DOCFX_SOURCE_BRANCH_NAME", "main"); + + try + { + await DotnetApiCatalog.GenerateManagedReferenceYamlFiles($"{samplePath}/docfx.json"); + await Docset.Pdf($"{samplePath}/docfx.json"); + } + finally + { + Environment.SetEnvironmentVariable("DOCFX_SOURCE_BRANCH_NAME", null); + } + + await Verifier.VerifyDirectory($"{samplePath}/_site", IncludeFile).AutoVerify(includeBuildServer: false); + } + [SnapshotFact] public Task Extensions() { diff --git a/test/docfx.Tests/DocsetTest.cs b/test/docfx.Tests/DocsetTest.cs index 0952c6cbd5f..a95483d3ef5 100644 --- a/test/docfx.Tests/DocsetTest.cs +++ b/test/docfx.Tests/DocsetTest.cs @@ -6,6 +6,8 @@ using Microsoft.DocAsCode.Tests.Common; using Xunit; +using Xunit.Abstractions; +using Xunit.Sdk; namespace Microsoft.DocAsCode.Tests; @@ -34,6 +36,31 @@ private static async Task>> Build(Dictionary new Func(() => File.ReadAllText(f))); } + private static async Task>> Pdf(Dictionary files, [CallerMemberName] string testName = null) + { + var testDirectory = $"{nameof(DocsetTest)}/{testName}"; + var outputDirectory = $"{testDirectory}/_pdf"; + + if (Directory.Exists(testDirectory)) + Directory.Delete(testDirectory, recursive: true); + + Directory.CreateDirectory(testDirectory); + foreach (var (path, content) in files) + { + var targetPath = Path.Combine(testDirectory, path); + Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); + + File.WriteAllText(targetPath, content); + } + + await Docset.Pdf($"{testDirectory}/docfx.json"); + + return Directory.GetFiles(outputDirectory, "*", SearchOption.AllDirectories) + .ToDictionary( + f => Path.GetRelativePath(outputDirectory, f), + f => new Func(() => File.ReadAllText(f))); + } + [Fact] public static async Task CustomLogo_Override_LogoFromTemplate() { @@ -55,6 +82,33 @@ public static async Task CustomLogo_Override_LogoFromTemplate() Assert.Equal("my svg", outputs["logo.svg"]()); } + [Fact] + public static async Task CustomLogo_Override_LogoFromTemplate_Pdf() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content" : [ + {"files": "**/*.{md,yml}" } + ], + "resource": [{ "files": [ "logo.svg" ] }], + "dest": "_pdf", + "wkhtmltopdf": { "additionalArguments": "--enable-local-file-access" } + } + } + """, + ["logo.svg"] = "my svg", + ["toc.yml"] = "- name: Introduction\r\n href: intro.md", + ["intro.md"] = "# Introduction", + ["cover.md"] = "# My Cover Page", + }); + + Assert.Equal("my svg", outputs["logo.svg"]()); + } + [Fact] public static async Task Load_Custom_Plugin_From_Template() { @@ -77,6 +131,28 @@ public static async Task Load_Custom_Plugin_From_Template() Assert.Equal("customPostProcessor", outputs["customPostProcessor.txt"]()); } + [Fact] + public static async Task Load_Custom_Plugin_From_Template_Pdf() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "build": { + "content": [{ "files": [ "*.md" ] }], + "template": ["default", "../../Assets/template"], + "dest": "_site", + "postProcessors": ["CustomPostProcessor"] + } + } + """, + ["index.md"] = "" + }); + + Assert.Equal("customPostProcessor", outputs["customPostProcessor.txt"]()); + } + [Fact] public static async Task Build_With_Global_Metadata_Files() { @@ -119,6 +195,48 @@ public static async Task Build_With_Global_Metadata_Files() Assert.Equal("docfx.json", metadata.GetProperty("meta3").GetString()); } + [Fact] + public static async Task Build_With_Global_Metadata_Files_Pdf() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "build": { + "content": [{ "files": [ "*.md" ] }], + "dest": "_site", + "exportRawModel": true, + "globalMetadataFiles": ["projectMetadata1.json", "projectMetadata2.json"], + "globalMetadata": { + "meta1": "docfx.json", + "meta3": "docfx.json" + } + } + } + """, + ["projectMetadata1.json"] = + """ + { + "meta1": "projectMetadata1.json", + "meta2": "projectMetadata2.json" + } + """, + ["projectMetadata2.json"] = + """ + { + "meta2": "projectMetadata2.json" + } + """, + ["index.md"] = "" + }); + + var metadata = JsonDocument.Parse(outputs["index.raw.json"]()).RootElement; + Assert.Equal("projectMetadata1.json", metadata.GetProperty("meta1").GetString()); + Assert.Equal("projectMetadata2.json", metadata.GetProperty("meta2").GetString()); + Assert.Equal("docfx.json", metadata.GetProperty("meta3").GetString()); + } + [Fact] public static async Task Build_With_File_Metadata_Files() { @@ -166,4 +284,53 @@ public static async Task Build_With_File_Metadata_Files() Assert.Equal("fileMetadata1.json", a.GetProperty("meta1").GetString()); Assert.Equal("fileMetadata2.json", b.GetProperty("meta1").GetString()); } + + + [Fact] + public static async Task Build_With_File_Metadata_Files_Pdf() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "build": { + "content": [{ "files": [ "*.md" ] }], + "dest": "_site", + "exportRawModel": true, + "fileMetadataFiles": ["fileMetadata1.json", "fileMetadata2.json"], + "fileMetadata": { + "meta1": { + "a.md": "docfx.json" + } + } + } + } + """, + ["fileMetadata1.json"] = + """ + { + "meta1": { + "a.md": "fileMetadata1.json", + "b.md": "fileMetadata1.json" + } + } + """, + ["fileMetadata2.json"] = + """ + { + "meta1": { + "b.md": "fileMetadata2.json" + } + } + """, + ["a.md"] = "", + ["b.md"] = "" + }); + + var a = JsonDocument.Parse(outputs["a.raw.json"]()).RootElement; + var b = JsonDocument.Parse(outputs["b.raw.json"]()).RootElement; + Assert.Equal("fileMetadata1.json", a.GetProperty("meta1").GetString()); + Assert.Equal("fileMetadata2.json", b.GetProperty("meta1").GetString()); + } } From aee3920d77ebafef5908e00d8d6e34e832d89be6 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Tue, 4 Jul 2023 09:26:06 +0100 Subject: [PATCH 06/16] Update DocsetTest.cs --- test/docfx.Tests/DocsetTest.cs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/docfx.Tests/DocsetTest.cs b/test/docfx.Tests/DocsetTest.cs index a95483d3ef5..17900730ac9 100644 --- a/test/docfx.Tests/DocsetTest.cs +++ b/test/docfx.Tests/DocsetTest.cs @@ -92,18 +92,22 @@ public static async Task CustomLogo_Override_LogoFromTemplate_Pdf() { "pdf": { "content" : [ - {"files": "**/*.{md,yml}" } + { + "files": ["*.md"] + }, + {"files": "pdf/toc.yml"} ], - "resource": [{ "files": [ "logo.svg" ] }], "dest": "_pdf", - "wkhtmltopdf": { "additionalArguments": "--enable-local-file-access" } + "wkhtmltopdf": { "additionalArguments": "-q --enable-local-file-access" }, + "cleanupCacheHistory": false, + "force" : true } } """, ["logo.svg"] = "my svg", - ["toc.yml"] = "- name: Introduction\r\n href: intro.md", + ["pdf/toc.yml"] = "- name: Introduction\r\n href: ../intro.md\r\n- name: Another Page\r\n href: ../anotherpage.md", ["intro.md"] = "# Introduction", - ["cover.md"] = "# My Cover Page", + ["anotherpage.md"] = "# Another Page" }); Assert.Equal("my svg", outputs["logo.svg"]()); From 2683e9d30948859c5f98cbbd8acbc2fc0bacec2d Mon Sep 17 00:00:00 2001 From: dpvreony Date: Tue, 4 Jul 2023 22:38:13 +0100 Subject: [PATCH 07/16] Update DocsetTest.cs --- test/docfx.Tests/DocsetTest.cs | 36 ++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/test/docfx.Tests/DocsetTest.cs b/test/docfx.Tests/DocsetTest.cs index 17900730ac9..c5aecb2600c 100644 --- a/test/docfx.Tests/DocsetTest.cs +++ b/test/docfx.Tests/DocsetTest.cs @@ -90,24 +90,30 @@ public static async Task CustomLogo_Override_LogoFromTemplate_Pdf() ["docfx.json"] = """ { - "pdf": { - "content" : [ - { - "files": ["*.md"] - }, - {"files": "pdf/toc.yml"} - ], - "dest": "_pdf", - "wkhtmltopdf": { "additionalArguments": "-q --enable-local-file-access" }, - "cleanupCacheHistory": false, - "force" : true - } + "pdf": { + "content": [ + { + "files": [ + "**/**.md" + ] + }, + { + "files": "**/toc.yml" + } + ], + "wkhtmltopdf": { + "additionalArguments": "--enable-local-file-access" + }, + "dest": "_pdf", + "cleanupCacheHistory": false, + "force": true + } } """, ["logo.svg"] = "my svg", - ["pdf/toc.yml"] = "- name: Introduction\r\n href: ../intro.md\r\n- name: Another Page\r\n href: ../anotherpage.md", - ["intro.md"] = "# Introduction", - ["anotherpage.md"] = "# Another Page" + ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["pdf/intro.md"] = "# Introduction\r\n\r\n", + ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" }); Assert.Equal("my svg", outputs["logo.svg"]()); From cba3e1408e40341061b2a9fa4a5a374ccfafc2b7 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Wed, 5 Jul 2023 00:03:30 +0100 Subject: [PATCH 08/16] log issues hidden by templates not resolving --- .../TemplateProcessors/TemplateModelTransformer.cs | 1 + .../TemplateProcessors/TemplateProcessor.cs | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateModelTransformer.cs b/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateModelTransformer.cs index 1ec1e7ec115..deb581fce89 100644 --- a/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateModelTransformer.cs +++ b/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateModelTransformer.cs @@ -77,6 +77,7 @@ internal ManifestItem Transform(InternalManifestItem item) var templateBundle = _templateCollection[item.DocumentType]; if (templateBundle == null) { + Logger.LogInfo($"No template bundle found for {item.DocumentType}, model will be ignored."); return manifestItem; } diff --git a/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs b/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs index e8b69d01688..a4a2162f8e5 100644 --- a/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs +++ b/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs @@ -35,6 +35,10 @@ public TemplateProcessor(ResourceFileReader resourceProvider, DocumentBuildConte _resourceProvider = resourceProvider; _maxParallelism = maxParallelism; _templateCollection = new TemplateCollection(resourceProvider, context, maxParallelism); + if (_templateCollection.Count == 0) + { + Logger.LogWarning("No template bundles were found, no template will be applied to the documents. 1) Check your docfx.json 2) or your working directory has the templates subfolder"); + } Tokens = TemplateProcessorUtility.LoadTokens(resourceProvider) ?? new Dictionary(); } From 451797717bb4bb10d8441fc7d6e45191da66757b Mon Sep 17 00:00:00 2001 From: dpvreony Date: Wed, 5 Jul 2023 12:25:12 +0100 Subject: [PATCH 09/16] housekeeping on tests --- test/docfx.Tests/DocsetTest.cs | 230 +++++++++++++++++---------------- 1 file changed, 120 insertions(+), 110 deletions(-) diff --git a/test/docfx.Tests/DocsetTest.cs b/test/docfx.Tests/DocsetTest.cs index c5aecb2600c..6fc1374988b 100644 --- a/test/docfx.Tests/DocsetTest.cs +++ b/test/docfx.Tests/DocsetTest.cs @@ -82,43 +82,6 @@ public static async Task CustomLogo_Override_LogoFromTemplate() Assert.Equal("my svg", outputs["logo.svg"]()); } - [Fact] - public static async Task CustomLogo_Override_LogoFromTemplate_Pdf() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "pdf": { - "content": [ - { - "files": [ - "**/**.md" - ] - }, - { - "files": "**/toc.yml" - } - ], - "wkhtmltopdf": { - "additionalArguments": "--enable-local-file-access" - }, - "dest": "_pdf", - "cleanupCacheHistory": false, - "force": true - } - } - """, - ["logo.svg"] = "my svg", - ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", - ["pdf/intro.md"] = "# Introduction\r\n\r\n", - ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" - }); - - Assert.Equal("my svg", outputs["logo.svg"]()); - } - [Fact] public static async Task Load_Custom_Plugin_From_Template() { @@ -141,28 +104,6 @@ public static async Task Load_Custom_Plugin_From_Template() Assert.Equal("customPostProcessor", outputs["customPostProcessor.txt"]()); } - [Fact] - public static async Task Load_Custom_Plugin_From_Template_Pdf() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "build": { - "content": [{ "files": [ "*.md" ] }], - "template": ["default", "../../Assets/template"], - "dest": "_site", - "postProcessors": ["CustomPostProcessor"] - } - } - """, - ["index.md"] = "" - }); - - Assert.Equal("customPostProcessor", outputs["customPostProcessor.txt"]()); - } - [Fact] public static async Task Build_With_Global_Metadata_Files() { @@ -205,48 +146,6 @@ public static async Task Build_With_Global_Metadata_Files() Assert.Equal("docfx.json", metadata.GetProperty("meta3").GetString()); } - [Fact] - public static async Task Build_With_Global_Metadata_Files_Pdf() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "build": { - "content": [{ "files": [ "*.md" ] }], - "dest": "_site", - "exportRawModel": true, - "globalMetadataFiles": ["projectMetadata1.json", "projectMetadata2.json"], - "globalMetadata": { - "meta1": "docfx.json", - "meta3": "docfx.json" - } - } - } - """, - ["projectMetadata1.json"] = - """ - { - "meta1": "projectMetadata1.json", - "meta2": "projectMetadata2.json" - } - """, - ["projectMetadata2.json"] = - """ - { - "meta2": "projectMetadata2.json" - } - """, - ["index.md"] = "" - }); - - var metadata = JsonDocument.Parse(outputs["index.raw.json"]()).RootElement; - Assert.Equal("projectMetadata1.json", metadata.GetProperty("meta1").GetString()); - Assert.Equal("projectMetadata2.json", metadata.GetProperty("meta2").GetString()); - Assert.Equal("docfx.json", metadata.GetProperty("meta3").GetString()); - } - [Fact] public static async Task Build_With_File_Metadata_Files() { @@ -295,18 +194,128 @@ public static async Task Build_With_File_Metadata_Files() Assert.Equal("fileMetadata2.json", b.GetProperty("meta1").GetString()); } + [Fact] + public static async Task Pdf_Basic() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [ + { + "files": [ + "**/**.md" + ] + }, + { + "files": "**/toc.yml" + } + ], + "wkhtmltopdf": { + "additionalArguments": "--enable-local-file-access" + }, + "dest": "_pdf" + } + } + """, + ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["pdf/intro.md"] = "# Introduction\r\n\r\n", + ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_Basic_pdf.pdf")); + } + + [Fact] + public static async Task Pdf_With_Cover_Page() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [ + { + "files": [ + "**/**.md" + ] + }, + { + "files": "**/toc.yml" + } + ], + "wkhtmltopdf": { + "additionalArguments": "--enable-local-file-access" + }, + "dest": "_pdf" + } + } + """, + ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["pdf/cover.md"] = "# My Basic Cover Page\r\n\r\n", + ["pdf/intro.md"] = "# Introduction\r\n\r\n", + ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_With_Cover_Page_pdf.pdf")); + } + + [Fact] + public static async Task Pdf_With_Global_Metadata_Files() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [{ "files": [ "*.md" ] },{ "files": "toc.yml" }], + "dest": "_pdf", + "exportRawModel": true, + "globalMetadataFiles": ["projectMetadata1.json", "projectMetadata2.json"], + "globalMetadata": { + "meta1": "docfx.json", + "meta3": "docfx.json" + } + } + } + """, + ["projectMetadata1.json"] = + """ + { + "meta1": "projectMetadata1.json", + "meta2": "projectMetadata2.json" + } + """, + ["projectMetadata2.json"] = + """ + { + "meta2": "projectMetadata2.json" + } + """, + ["toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["cover.md"] = "# My Basic Cover Page\r\n\r\n", + ["intro.md"] = "# Introduction\r\n\r\n", + ["anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_With_Global_Metadata_Files.pdf")); + } [Fact] - public static async Task Build_With_File_Metadata_Files_Pdf() + public static async Task Pdf_With_File_Metadata_Files() { var outputs = await Pdf(new() { ["docfx.json"] = """ { - "build": { - "content": [{ "files": [ "*.md" ] }], - "dest": "_site", + "pdf": { + "content": [{ "files": [ "*.md" ] },{ "files": "toc.yml" }], + "dest": "_pdf", "exportRawModel": true, "fileMetadataFiles": ["fileMetadata1.json", "fileMetadata2.json"], "fileMetadata": { @@ -335,12 +344,13 @@ public static async Task Build_With_File_Metadata_Files_Pdf() } """, ["a.md"] = "", - ["b.md"] = "" + ["b.md"] = "", + ["toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["cover.md"] = "# My Basic Cover Page\r\n\r\n", + ["intro.md"] = "# Introduction\r\n\r\n", + ["anotherpage.md"] = "# Another Page\r\n\r\n" }); - var a = JsonDocument.Parse(outputs["a.raw.json"]()).RootElement; - var b = JsonDocument.Parse(outputs["b.raw.json"]()).RootElement; - Assert.Equal("fileMetadata1.json", a.GetProperty("meta1").GetString()); - Assert.Equal("fileMetadata2.json", b.GetProperty("meta1").GetString()); + Assert.True(outputs.ContainsKey("Pdf_With_File_Metadata_Files.pdf")); } } From fdbf4d80548fdc5a76a229e6d526a64b37283f50 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Wed, 5 Jul 2023 18:30:47 +0100 Subject: [PATCH 10/16] remove snapshot test --- test/docfx.Snapshot.Tests/SamplesTest.cs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/test/docfx.Snapshot.Tests/SamplesTest.cs b/test/docfx.Snapshot.Tests/SamplesTest.cs index 4164bb51fee..75cf878025d 100644 --- a/test/docfx.Snapshot.Tests/SamplesTest.cs +++ b/test/docfx.Snapshot.Tests/SamplesTest.cs @@ -193,27 +193,6 @@ public async Task CSharp() await Verifier.VerifyDirectory($"{samplePath}/_site", IncludeFile).AutoVerify(includeBuildServer: false); } - [SnapshotFact] - public async Task CSharpPdf() - { - var samplePath = $"{s_samplesDir}/csharp"; - Clean(samplePath); - - Environment.SetEnvironmentVariable("DOCFX_SOURCE_BRANCH_NAME", "main"); - - try - { - await DotnetApiCatalog.GenerateManagedReferenceYamlFiles($"{samplePath}/docfx.json"); - await Docset.Pdf($"{samplePath}/docfx.json"); - } - finally - { - Environment.SetEnvironmentVariable("DOCFX_SOURCE_BRANCH_NAME", null); - } - - await Verifier.VerifyDirectory($"{samplePath}/_site", IncludeFile).AutoVerify(includeBuildServer: false); - } - [SnapshotFact] public Task Extensions() { From 036cd7cab8e638e011c70815c4234c91f9f62cdf Mon Sep 17 00:00:00 2001 From: dpvreony Date: Thu, 6 Jul 2023 09:06:49 +0100 Subject: [PATCH 11/16] restore missing docset fact --- test/docfx.Tests/DocsetTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/test/docfx.Tests/DocsetTest.cs b/test/docfx.Tests/DocsetTest.cs index 33ce6e9ede1..acf780312f9 100644 --- a/test/docfx.Tests/DocsetTest.cs +++ b/test/docfx.Tests/DocsetTest.cs @@ -195,6 +195,7 @@ public static async Task Build_With_File_Metadata_Files() Assert.Equal("fileMetadata2.json", b.GetProperty("meta1").GetString()); } + [Fact] public static async Task Build_With_RedirectUri_Files() { // Act From d69e67f5a83f415663df8570022083b9d59e7d66 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Thu, 6 Jul 2023 17:40:41 +0100 Subject: [PATCH 12/16] update template bundle error message --- .../TemplateProcessors/TemplateProcessor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs b/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs index a4a2162f8e5..9d6b404a9dc 100644 --- a/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs +++ b/src/Microsoft.DocAsCode.Build.Engine/TemplateProcessors/TemplateProcessor.cs @@ -37,7 +37,7 @@ public TemplateProcessor(ResourceFileReader resourceProvider, DocumentBuildConte _templateCollection = new TemplateCollection(resourceProvider, context, maxParallelism); if (_templateCollection.Count == 0) { - Logger.LogWarning("No template bundles were found, no template will be applied to the documents. 1) Check your docfx.json 2) or your working directory has the templates subfolder"); + Logger.LogWarning("No template bundles were found, no template will be applied to the documents. 1) Check your docfx.json 2) the templates subfolder exists inside your application folder or your docfx.json directory."); } Tokens = TemplateProcessorUtility.LoadTokens(resourceProvider) ?? new Dictionary(); } From c48a9323517999d65a332d62350e633e2d9384db Mon Sep 17 00:00:00 2001 From: David Vreony Date: Mon, 10 Jul 2023 20:12:14 +0100 Subject: [PATCH 13/16] split pdf docset tests --- .../{DocsetTest.cs => DocsetBuildTest.cs} | 168 +-------------- test/docfx.Tests/DocsetPdfTest.cs | 198 ++++++++++++++++++ 2 files changed, 201 insertions(+), 165 deletions(-) rename test/docfx.Tests/{DocsetTest.cs => DocsetBuildTest.cs} (58%) create mode 100644 test/docfx.Tests/DocsetPdfTest.cs diff --git a/test/docfx.Tests/DocsetTest.cs b/test/docfx.Tests/DocsetBuildTest.cs similarity index 58% rename from test/docfx.Tests/DocsetTest.cs rename to test/docfx.Tests/DocsetBuildTest.cs index acf780312f9..2c8b8944ad9 100644 --- a/test/docfx.Tests/DocsetTest.cs +++ b/test/docfx.Tests/DocsetBuildTest.cs @@ -7,17 +7,15 @@ using Microsoft.DocAsCode.Tests.Common; using Xunit; -using Xunit.Abstractions; -using Xunit.Sdk; namespace Microsoft.DocAsCode.Tests; [Collection("docfx STA")] -public class DocsetTest : TestBase +public class DocsetBuildTest : TestBase { private static async Task>> Build(Dictionary files, [CallerMemberName] string testName = null) { - var testDirectory = $"{nameof(DocsetTest)}/{testName}"; + var testDirectory = $"{nameof(DocsetBuildTest)}/{testName}"; var outputDirectory = $"{testDirectory}/_site"; if (Directory.Exists(testDirectory)) @@ -39,7 +37,7 @@ private static async Task>> Build(Dictionary>> Pdf(Dictionary files, [CallerMemberName] string testName = null) { - var testDirectory = $"{nameof(DocsetTest)}/{testName}"; + var testDirectory = $"{nameof(DocsetBuildTest)}/{testName}"; var outputDirectory = $"{testDirectory}/_pdf"; if (Directory.Exists(testDirectory)) @@ -244,164 +242,4 @@ public static async Task Build_With_RedirectUri_Files() var urls = XDocument.Parse(sitemapXml).Root.Elements(); Assert.True(urls.Count() == 0); } - - [Fact] - public static async Task Pdf_Basic() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "pdf": { - "content": [ - { - "files": [ - "**/**.md" - ] - }, - { - "files": "**/toc.yml" - } - ], - "wkhtmltopdf": { - "additionalArguments": "--enable-local-file-access" - }, - "dest": "_pdf" - } - } - """, - ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", - ["pdf/intro.md"] = "# Introduction\r\n\r\n", - ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" - }); - - Assert.True(outputs.ContainsKey("Pdf_Basic_pdf.pdf")); - } - - [Fact] - public static async Task Pdf_With_Cover_Page() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "pdf": { - "content": [ - { - "files": [ - "**/**.md" - ] - }, - { - "files": "**/toc.yml" - } - ], - "wkhtmltopdf": { - "additionalArguments": "--enable-local-file-access" - }, - "dest": "_pdf" - } - } - """, - ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", - ["pdf/cover.md"] = "# My Basic Cover Page\r\n\r\n", - ["pdf/intro.md"] = "# Introduction\r\n\r\n", - ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" - }); - - Assert.True(outputs.ContainsKey("Pdf_With_Cover_Page_pdf.pdf")); - } - - [Fact] - public static async Task Pdf_With_Global_Metadata_Files() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "pdf": { - "content": [{ "files": [ "*.md" ] },{ "files": "toc.yml" }], - "dest": "_pdf", - "exportRawModel": true, - "globalMetadataFiles": ["projectMetadata1.json", "projectMetadata2.json"], - "globalMetadata": { - "meta1": "docfx.json", - "meta3": "docfx.json" - } - } - } - """, - ["projectMetadata1.json"] = - """ - { - "meta1": "projectMetadata1.json", - "meta2": "projectMetadata2.json" - } - """, - ["projectMetadata2.json"] = - """ - { - "meta2": "projectMetadata2.json" - } - """, - ["toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", - ["cover.md"] = "# My Basic Cover Page\r\n\r\n", - ["intro.md"] = "# Introduction\r\n\r\n", - ["anotherpage.md"] = "# Another Page\r\n\r\n" - }); - - Assert.True(outputs.ContainsKey("Pdf_With_Global_Metadata_Files.pdf")); - } - - [Fact] - public static async Task Pdf_With_File_Metadata_Files() - { - var outputs = await Pdf(new() - { - ["docfx.json"] = - """ - { - "pdf": { - "content": [{ "files": [ "*.md" ] },{ "files": "toc.yml" }], - "dest": "_pdf", - "exportRawModel": true, - "fileMetadataFiles": ["fileMetadata1.json", "fileMetadata2.json"], - "fileMetadata": { - "meta1": { - "a.md": "docfx.json" - } - } - } - } - """, - ["fileMetadata1.json"] = - """ - { - "meta1": { - "a.md": "fileMetadata1.json", - "b.md": "fileMetadata1.json" - } - } - """, - ["fileMetadata2.json"] = - """ - { - "meta1": { - "b.md": "fileMetadata2.json" - } - } - """, - ["a.md"] = "", - ["b.md"] = "", - ["toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", - ["cover.md"] = "# My Basic Cover Page\r\n\r\n", - ["intro.md"] = "# Introduction\r\n\r\n", - ["anotherpage.md"] = "# Another Page\r\n\r\n" - }); - - Assert.True(outputs.ContainsKey("Pdf_With_File_Metadata_Files.pdf")); - } } diff --git a/test/docfx.Tests/DocsetPdfTest.cs b/test/docfx.Tests/DocsetPdfTest.cs new file mode 100644 index 00000000000..b40474608b3 --- /dev/null +++ b/test/docfx.Tests/DocsetPdfTest.cs @@ -0,0 +1,198 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using Microsoft.DocAsCode.Tests.Common; + +using Xunit; + +namespace Microsoft.DocAsCode.Tests; + +[Collection("docfx STA")] +public class DocsetPdfTest : TestBase +{ + private static async Task>> Pdf(Dictionary files, [CallerMemberName] string testName = null) + { + var testDirectory = $"{nameof(DocsetPdfTest)}/{testName}"; + var outputDirectory = $"{testDirectory}/_pdf"; + + if (Directory.Exists(testDirectory)) + Directory.Delete(testDirectory, recursive: true); + + Directory.CreateDirectory(testDirectory); + foreach (var (path, content) in files) + { + var targetPath = Path.Combine(testDirectory, path); + Directory.CreateDirectory(Path.GetDirectoryName(targetPath)); + + File.WriteAllText(targetPath, content); + } + + await Docset.Pdf($"{testDirectory}/docfx.json"); + + return Directory.GetFiles(outputDirectory, "*", SearchOption.AllDirectories) + .ToDictionary( + f => Path.GetRelativePath(outputDirectory, f), + f => new Func(() => File.ReadAllText(f))); + } + + [Fact] + public static async Task Pdf_Basic() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [ + { + "files": [ + "**/**.md" + ] + }, + { + "files": "**/toc.yml" + } + ], + "wkhtmltopdf": { + "additionalArguments": "--enable-local-file-access" + }, + "dest": "_pdf" + } + } + """, + ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["pdf/intro.md"] = "# Introduction\r\n\r\n", + ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_Basic_pdf.pdf")); + } + + [Fact] + public static async Task Pdf_With_Cover_Page() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [ + { + "files": [ + "**/**.md" + ] + }, + { + "files": "**/toc.yml" + } + ], + "wkhtmltopdf": { + "additionalArguments": "--enable-local-file-access" + }, + "dest": "_pdf" + } + } + """, + ["pdf/toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["pdf/cover.md"] = "# My Basic Cover Page\r\n\r\n", + ["pdf/intro.md"] = "# Introduction\r\n\r\n", + ["pdf/anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_With_Cover_Page_pdf.pdf")); + } + + [Fact] + public static async Task Pdf_With_Global_Metadata_Files() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [{ "files": [ "*.md" ] },{ "files": "toc.yml" }], + "dest": "_pdf", + "exportRawModel": true, + "globalMetadataFiles": ["projectMetadata1.json", "projectMetadata2.json"], + "globalMetadata": { + "meta1": "docfx.json", + "meta3": "docfx.json" + } + } + } + """, + ["projectMetadata1.json"] = + """ + { + "meta1": "projectMetadata1.json", + "meta2": "projectMetadata2.json" + } + """, + ["projectMetadata2.json"] = + """ + { + "meta2": "projectMetadata2.json" + } + """, + ["toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["cover.md"] = "# My Basic Cover Page\r\n\r\n", + ["intro.md"] = "# Introduction\r\n\r\n", + ["anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_With_Global_Metadata_Files.pdf")); + } + + [Fact] + public static async Task Pdf_With_File_Metadata_Files() + { + var outputs = await Pdf(new() + { + ["docfx.json"] = + """ + { + "pdf": { + "content": [{ "files": [ "*.md" ] },{ "files": "toc.yml" }], + "dest": "_pdf", + "exportRawModel": true, + "fileMetadataFiles": ["fileMetadata1.json", "fileMetadata2.json"], + "fileMetadata": { + "meta1": { + "a.md": "docfx.json" + } + } + } + } + """, + ["fileMetadata1.json"] = + """ + { + "meta1": { + "a.md": "fileMetadata1.json", + "b.md": "fileMetadata1.json" + } + } + """, + ["fileMetadata2.json"] = + """ + { + "meta1": { + "b.md": "fileMetadata2.json" + } + } + """, + ["a.md"] = "", + ["b.md"] = "", + ["toc.yml"] = "- name: Introduction\r\n href: intro.md\r\n- name: Another Page\r\n href: anotherpage.md\r\n", + ["cover.md"] = "# My Basic Cover Page\r\n\r\n", + ["intro.md"] = "# Introduction\r\n\r\n", + ["anotherpage.md"] = "# Another Page\r\n\r\n" + }); + + Assert.True(outputs.ContainsKey("Pdf_With_File_Metadata_Files.pdf")); + } +} From d9aa393a0b47e79fd28e0a45e32ad932b52b19e1 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Tue, 11 Jul 2023 19:28:03 +0100 Subject: [PATCH 14/16] limit pdf tests to windows --- .../Attributes/WindowsOnlyFactAttribute.cs | 25 +++++++++++++++++++ test/docfx.Tests/DocsetPdfTest.cs | 9 ++++--- test/docfx.Tests/PdfTest.cs | 8 ++---- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 test/docfx.Tests/Attributes/WindowsOnlyFactAttribute.cs diff --git a/test/docfx.Tests/Attributes/WindowsOnlyFactAttribute.cs b/test/docfx.Tests/Attributes/WindowsOnlyFactAttribute.cs new file mode 100644 index 00000000000..36f9f4ceed9 --- /dev/null +++ b/test/docfx.Tests/Attributes/WindowsOnlyFactAttribute.cs @@ -0,0 +1,25 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.Runtime.InteropServices; +using Xunit; + +namespace docfx.Tests.Attributes +{ + /// + /// XUnit Fact attribute that skips the test if the OS is not Windows. + /// + /// + /// Taken from https://github.com/dotnet/sdk/blob/a30e465a2e2ea4e2550f319a2dc088daaafe5649/src/Tests/Microsoft.NET.TestFramework/Attributes/WindowsOnlyFactAttribute.cs + /// + public class WindowsOnlyFactAttribute : FactAttribute + { + public WindowsOnlyFactAttribute() + { + if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + this.Skip = "This test requires Windows to run"; + } + } + } +} diff --git a/test/docfx.Tests/DocsetPdfTest.cs b/test/docfx.Tests/DocsetPdfTest.cs index b40474608b3..b620ca513de 100644 --- a/test/docfx.Tests/DocsetPdfTest.cs +++ b/test/docfx.Tests/DocsetPdfTest.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using docfx.Tests.Attributes; using Microsoft.DocAsCode.Tests.Common; using Xunit; @@ -36,7 +37,7 @@ private static async Task>> Pdf(Dictionary new Func(() => File.ReadAllText(f))); } - [Fact] + [WindowsOnlyFact] public static async Task Pdf_Basic() { var outputs = await Pdf(new() @@ -70,7 +71,7 @@ public static async Task Pdf_Basic() Assert.True(outputs.ContainsKey("Pdf_Basic_pdf.pdf")); } - [Fact] + [WindowsOnlyFact] public static async Task Pdf_With_Cover_Page() { var outputs = await Pdf(new() @@ -105,7 +106,7 @@ public static async Task Pdf_With_Cover_Page() Assert.True(outputs.ContainsKey("Pdf_With_Cover_Page_pdf.pdf")); } - [Fact] + [WindowsOnlyFact] public static async Task Pdf_With_Global_Metadata_Files() { var outputs = await Pdf(new() @@ -147,7 +148,7 @@ public static async Task Pdf_With_Global_Metadata_Files() Assert.True(outputs.ContainsKey("Pdf_With_Global_Metadata_Files.pdf")); } - [Fact] + [WindowsOnlyFact] public static async Task Pdf_With_File_Metadata_Files() { var outputs = await Pdf(new() diff --git a/test/docfx.Tests/PdfTest.cs b/test/docfx.Tests/PdfTest.cs index 5d01de78331..4243a88c345 100644 --- a/test/docfx.Tests/PdfTest.cs +++ b/test/docfx.Tests/PdfTest.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using docfx.Tests.Attributes; using Microsoft.DocAsCode.Tests.Common; using Xunit; @@ -10,11 +11,6 @@ namespace Microsoft.DocAsCode.Tests; [Collection("docfx STA")] public class PdfTest : TestBase { - class PdfFact : FactAttribute - { - public override string Skip => OperatingSystem.IsWindows() ? null : "Skip PDF test on non-windows platforms"; - } - private static async Task Build(Dictionary files, [CallerMemberName] string testName = null) { var testDirectory = $"{nameof(PdfTest)}/{testName}"; @@ -35,7 +31,7 @@ private static async Task Build(Dictionary files, [Calle return outputDirectory; } - [PdfFact] + [WindowsOnlyFact] public static async Task BuildPdf_GeneratesPdfFile() { var outputDirectory = await Build(new() From cb07551865540a51198957f71952d8b187eadfe5 Mon Sep 17 00:00:00 2001 From: dpvreony Date: Mon, 17 Jul 2023 11:01:33 +0100 Subject: [PATCH 15/16] tweak counts on a couple of tests with new log event --- .../Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs | 2 +- .../SchemaDrivenProcessorTest.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs b/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs index d239c5eb60f..0a952806461 100644 --- a/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs +++ b/test/Docfx.Build.RestApi.Tests/RestApiDocumentProcessorTest.cs @@ -294,7 +294,7 @@ public void ProcessSwaggerWithInvalidLinksOverwriteShouldSucceedWithWarning() files.Add(DocumentType.Overwrite, new[] { "TestData/overwrite/rest.overwrite.invalid.links.second.md" }); BuildDocument(files); - Assert.Equal(6, listener.Items.Count); // Additional warning for "There is no template processing document type(s): RestApi" + Assert.Equal(7, listener.Items.Count); // Additional warning for "There is no template processing document type(s): RestApi" var outputRawModelPath = GetRawModelFilePath("contacts.json"); Assert.True(File.Exists(outputRawModelPath)); diff --git a/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs b/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs index 5f1ced4b4ed..f43f31d725d 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/SchemaDrivenProcessorTest.cs @@ -321,7 +321,7 @@ public void TestValidMetadataReferenceWithIncremental() BuildDocument(files); } - Assert.Equal(3, listener.Items.Count); + Assert.Equal(4, listener.Items.Count); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): MetadataReferenceTest,Toc"))); listener.Items.Clear(); @@ -433,7 +433,7 @@ public void TestUidWithPatternedTag() }, }); - Assert.Equal(2, listener.Items.Count); + Assert.Equal(3, listener.Items.Count); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): PatternedUid"))); listener.Items.Clear(); From a33973d5aae638e4ba8f6d578dbf3b21a5dfc85e Mon Sep 17 00:00:00 2001 From: dpvreony Date: Mon, 17 Jul 2023 20:12:04 +0100 Subject: [PATCH 16/16] fix last few tests around log counts --- test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs | 2 +- .../UniversalReferenceDocumentProcessorTest.cs | 4 ++-- test/docfx.Tests/DocsetPdfTest.cs | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs b/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs index bf65f8d3e14..40e7d607214 100644 --- a/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs +++ b/test/Docfx.Build.SchemaDriven.Tests/SchemaMergerTest.cs @@ -222,7 +222,7 @@ Overwrite with content BuildDocument(files); // One plugin warning for yml and one plugin warning for overwrite file - Assert.Equal(6, listener.Items.Count); + Assert.Equal(7, listener.Items.Count); Assert.NotNull(listener.Items.FirstOrDefault(s => s.Message.StartsWith("There is no template processing document type(s): testmerger"))); Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/stringArrayValue/0\" in overwrite object fails to overwrite \"/stringArrayValue\" for \"uid1\" because it does not match any existing item."))); Assert.Equal(1, listener.Items.Count(s => s.Message.StartsWith("\"/intArrayValue/0\" in overwrite object fails to overwrite \"/intArrayValue\" for \"uid1\" because it does not match any existing item."))); diff --git a/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs b/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs index f7585c28703..ef3a119a07e 100644 --- a/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs +++ b/test/Docfx.Build.UniversalReference.Tests/UniversalReferenceDocumentProcessorTest.cs @@ -176,8 +176,8 @@ public void ProcessItemWithEmptyUidShouldFail() using var listener = new TestListenerScope(nameof(UniversalReferenceDocumentProcessorTest)); BuildDocument(files); Assert.NotNull(listener.Items); - Assert.Single(listener.Items); - Assert.Contains("Uid must not be null or empty", listener.Items[0].Message); + Assert.Equal(2, listener.Items.Count); + Assert.Contains("Uid must not be null or empty", listener.Items[1].Message); } private void BuildDocument(FileCollection files) diff --git a/test/docfx.Tests/DocsetPdfTest.cs b/test/docfx.Tests/DocsetPdfTest.cs index b620ca513de..7a48be25968 100644 --- a/test/docfx.Tests/DocsetPdfTest.cs +++ b/test/docfx.Tests/DocsetPdfTest.cs @@ -2,8 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. using System.Runtime.CompilerServices; +using Docfx; using docfx.Tests.Attributes; -using Microsoft.DocAsCode.Tests.Common; +using Docfx.Tests.Common; using Xunit;