-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
412 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using Cake.Core.IO; | ||
using Cake.DocFx.Pdf; | ||
|
||
namespace Cake.DocFx.Tests.Pdf | ||
{ | ||
internal sealed class DocFxPdfRunnerFixture : DocFxFixture<DocFxPdfSettings> | ||
{ | ||
public DocFxPdfRunnerFixture() | ||
{ | ||
} | ||
|
||
public FilePath ConfigFilePath { get; set; } | ||
|
||
protected override void RunTool() | ||
{ | ||
var tool = new DocFxPdfRunner(FileSystem, Environment, ProcessRunner, Tools); | ||
tool.Run(ConfigFilePath, Settings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
using Xunit; | ||
|
||
namespace Cake.DocFx.Tests.Pdf | ||
{ | ||
public class DocFxPdfRunnerTests | ||
{ | ||
public sealed class TheRunMethod | ||
{ | ||
[Fact] | ||
public void Should_Throw_If_Settings_Are_Null() | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture | ||
{ | ||
Settings = null | ||
}; | ||
|
||
// When | ||
var result = Record.Exception(() => fixture.Run()); | ||
|
||
// Then | ||
result.IsArgumentNullException("settings"); | ||
} | ||
|
||
|
||
[Fact] | ||
public void Should_Be_Pdf_Command() | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture | ||
{ | ||
Settings = {} | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("pdf", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_LogPath_To_Arguments_If_Set() | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture | ||
{ | ||
Settings = { LogPath = @"c:\temp\docfx.log" } | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("pdf -l \"c:/temp/docfx.log\"", result.Args); | ||
} | ||
|
||
[Theory] | ||
[InlineData(DocFxLogLevel.Error, "Error")] | ||
[InlineData(DocFxLogLevel.Warning, "Warning")] | ||
[InlineData(DocFxLogLevel.Info, "Info")] | ||
[InlineData(DocFxLogLevel.Verbose, "Verbose")] | ||
public void Should_Add_LogLevel_To_Arguments_If_Set(DocFxLogLevel logLevel, string expectedLevel) | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture | ||
{ | ||
Settings = { LogLevel = logLevel } | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("pdf --logLevel \"" + expectedLevel + "\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Not_Add_LogLevel_To_Arguments_If_Default() | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture | ||
{ | ||
Settings = { LogLevel = DocFxLogLevel.Default } | ||
}; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("pdf", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_GlobalMetadata_To_Arguments_If_Not_Empty() | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture(); | ||
fixture.Settings.GlobalMetadata.Add("foo", "bar"); | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("pdf --globalMetadata \"{\\\"foo\\\": \\\"bar\\\"}\"", result.Args); | ||
} | ||
|
||
[Fact] | ||
public void Should_Add_Name_To_Arguments_If_Not_Empty() | ||
{ | ||
// Given | ||
var fixture = new DocFxPdfRunnerFixture(); | ||
fixture.Settings.Name = "foo"; | ||
|
||
// When | ||
var result = fixture.Run(); | ||
|
||
// Then | ||
Assert.Equal("pdf --name \"foo\"", result.Args); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
using Cake.Core; | ||
using Cake.Core.Annotations; | ||
using Cake.Core.IO; | ||
using Cake.DocFx.Helper; | ||
using Cake.DocFx.Pdf; | ||
|
||
namespace Cake.DocFx | ||
{ | ||
/// <summary> | ||
/// Contains functionality related to creating PDF files using <see href="http://dotnet.github.io/docfx">DocFx</see>. | ||
/// </summary> | ||
[CakeAliasCategory("DocFx")] | ||
[CakeNamespaceImport("Cake.DocFx.Pdf")] | ||
public static class DocFxPdfAliases | ||
{ | ||
/// <summary> | ||
/// Generates a PDF document for the <c>docfx.json</c> file in the current working directory. | ||
/// </summary> | ||
/// <param name="context">The Cake context.</param> | ||
/// <example> | ||
/// <code> | ||
/// DocFxPdf(); | ||
/// </code> | ||
/// </example> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Pdf")] | ||
public static void DocFxPdf(this ICakeContext context) | ||
=> context.DocFxPdf(null, null); | ||
|
||
/// <summary> | ||
/// Generates a PDF document for a specific <c>docfx.json</c> file. | ||
/// </summary> | ||
/// <param name="context">The Cake context.</param> | ||
/// <param name="configFile">The optional path to a DocFx config file. | ||
/// If no value is passed the docfx.json file in the current working directory will be used.</param> | ||
/// <example> | ||
/// <code> | ||
/// DocFxPdf("./docs/docfx.json"); | ||
/// </code> | ||
/// </example> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Pdf")] | ||
public static void DocFxPdf(this ICakeContext context, FilePath configFile) | ||
=> context.DocFxPdf(configFile, null); | ||
|
||
/// <summary> | ||
/// Generates a PDF document for the <c>docfx.json</c> file in the current working directory | ||
/// using the specified settings. | ||
/// </summary> | ||
/// <param name="context">The Cake context.</param> | ||
/// <param name="settings">The optional DocFx settings. | ||
/// If no settings are passed default settings are used.</param> | ||
/// <example> | ||
/// <code> | ||
/// DocFxPdf(new DocFxPdfSettings() | ||
/// { | ||
/// OutputPath = "./artifacts/docs", | ||
/// TemplateFolder = "default" | ||
/// }); | ||
/// </code> | ||
/// </example> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Pdf")] | ||
public static void DocFxPdf(this ICakeContext context, DocFxPdfSettings settings) | ||
=> context.DocFxPdf(null, settings); | ||
|
||
/// <summary> | ||
/// Generates a PDF document for a specific <c>docfx.json</c> file using the specified settings. | ||
/// </summary> | ||
/// <param name="context">The Cake context.</param> | ||
/// <param name="configFile">The optional path to a DocFx config file. | ||
/// If no value is passed the docfx.json file in the current working directory will be used.</param> | ||
/// <param name="settings">The optional DocFx settings. | ||
/// If no settings are passed default settings are used.</param> | ||
/// <example> | ||
/// <code> | ||
/// DocFxPdf("./docs/docfx.json", new DocFxPdfSettings() | ||
/// { | ||
/// OutputPath = "./artifacts/docs", | ||
/// TemplateFolder = "default" | ||
/// }); | ||
/// </code> | ||
/// </example> | ||
[CakeMethodAlias] | ||
[CakeAliasCategory("Pdf")] | ||
public static void DocFxPdf(this ICakeContext context, FilePath configFile, DocFxPdfSettings settings) | ||
{ | ||
Contract.NotNull(context, nameof(context)); | ||
|
||
settings = settings ?? new DocFxPdfSettings(); | ||
|
||
var runner = new DocFxPdfRunner(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); | ||
runner.Run(configFile, settings); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.