From 7de07079dc4d52ca8e8515610b8e78a403bfa016 Mon Sep 17 00:00:00 2001 From: Dave Glick Date: Fri, 22 Dec 2023 09:17:04 -0500 Subject: [PATCH] Test fixture for the API pipeline --- .../Statiq.Docs.Tests/Pipelines/ApiFixture.cs | 231 ++++++++++++++++++ 1 file changed, 231 insertions(+) create mode 100644 tests/Statiq.Docs.Tests/Pipelines/ApiFixture.cs diff --git a/tests/Statiq.Docs.Tests/Pipelines/ApiFixture.cs b/tests/Statiq.Docs.Tests/Pipelines/ApiFixture.cs new file mode 100644 index 0000000..9425e64 --- /dev/null +++ b/tests/Statiq.Docs.Tests/Pipelines/ApiFixture.cs @@ -0,0 +1,231 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using NUnit.Framework; +using Shouldly; +using Statiq.App; +using Statiq.CodeAnalysis; +using Statiq.Common; +using Statiq.Testing; +using Statiq.Web; + +namespace Statiq.Docs.Tests.Pipelines +{ + [TestFixture] + public class ApiFixture : BaseFixture + { + public class ExecuteTests : ApiFixture + { + [Test] + public async Task ShouldCreateXrefForClass() + { + // Given + App.Bootstrapper bootstrapper = App.Bootstrapper + .Factory + .CreateDocs(Array.Empty()); + TestFileProvider fileProvider = new TestFileProvider + { + { + "/input/index.md", + "Index" + }, + { + "/src/code.cs", + @" + using System.Text; + namespace Foo + { + public class Blue + { + public Red Green() => default; + } + public class Red + { + } + } + " + } + }; + + // When + BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider); + + // Then + result.ExitCode.ShouldBe((int)ExitCode.Normal); + IDocument document = result + .Outputs[nameof(Statiq.Docs.Pipelines.Api)][Phase.Process] + .Single(x => x[CodeAnalysisKeys.Name].Equals("Blue")); + document.GetString(WebKeys.Xref).ShouldBe("api-Foo.Blue"); + } + + [Test] + public async Task ShouldCreateXrefForGenericClass() + { + // Given + App.Bootstrapper bootstrapper = App.Bootstrapper + .Factory + .CreateDocs(Array.Empty()); + TestFileProvider fileProvider = new TestFileProvider + { + { + "/input/index.md", + "Index" + }, + { + "/src/code.cs", + @" + using System.Text; + namespace Foo + { + public class Blue + { + public Red Green() => default; + } + public class Red + { + } + } + " + } + }; + + // When + BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider); + + // Then + result.ExitCode.ShouldBe((int)ExitCode.Normal); + IDocument document = result + .Outputs[nameof(Statiq.Docs.Pipelines.Api)][Phase.Process] + .Single(x => x[CodeAnalysisKeys.Name].Equals("Blue")); + document.GetString(WebKeys.Xref).ShouldBe("api-Foo.Blue-Fizz-"); + } + + [Test] + public async Task ShouldCreateXrefForMethod() + { + // Given + App.Bootstrapper bootstrapper = App.Bootstrapper + .Factory + .CreateDocs(Array.Empty()); + TestFileProvider fileProvider = new TestFileProvider + { + { + "/input/index.md", + "Index" + }, + { + "/src/code.cs", + @" + using System.Text; + namespace Foo + { + public class Blue + { + public Red Green() { return null }; + } + public class Red + { + } + } + " + } + }; + + // When + BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider); + + // Then + result.ExitCode.ShouldBe((int)ExitCode.Normal); + IDocument document = result + .Outputs[nameof(Statiq.Docs.Pipelines.Api)][Phase.Process] + .Single(x => x[CodeAnalysisKeys.Name].Equals("Green")); + document.GetString(WebKeys.Xref).ShouldBe("api-Foo.Blue.Green()"); + } + + [Test] + public async Task ShouldCreateXrefForProperty() + { + // Given + App.Bootstrapper bootstrapper = App.Bootstrapper + .Factory + .CreateDocs(Array.Empty()); + TestFileProvider fileProvider = new TestFileProvider + { + { + "/input/index.md", + "Index" + }, + { + "/src/code.cs", + @" + using System.Text; + namespace Foo + { + public class Blue + { + public Red Green => default; + } + public class Red + { + } + } + " + } + }; + + // When + BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider); + + // Then + result.ExitCode.ShouldBe((int)ExitCode.Normal); + IDocument document = result + .Outputs[nameof(Statiq.Docs.Pipelines.Api)][Phase.Process] + .Single(x => x[CodeAnalysisKeys.Name].Equals("Green")); + document.GetString(WebKeys.Xref).ShouldBe("api-Foo.Blue.Green"); + } + + [Test] + public async Task ShouldCreateXrefForField() + { + // Given + App.Bootstrapper bootstrapper = App.Bootstrapper + .Factory + .CreateDocs(Array.Empty()); + TestFileProvider fileProvider = new TestFileProvider + { + { + "/input/index.md", + "Index" + }, + { + "/src/code.cs", + @" + using System.Text; + namespace Foo + { + public class Blue + { + public Red Green = default; + } + public class Red + { + } + } + " + } + }; + + // When + BootstrapperTestResult result = await bootstrapper.RunTestAsync(fileProvider); + + // Then + result.ExitCode.ShouldBe((int)ExitCode.Normal); + IDocument document = result + .Outputs[nameof(Statiq.Docs.Pipelines.Api)][Phase.Process] + .Single(x => x[CodeAnalysisKeys.Name].Equals("Green")); + document.GetString(WebKeys.Xref).ShouldBe("api-Foo.Blue.Green"); + } + } + } +} \ No newline at end of file