Skip to content

Commit

Permalink
Test fixture for the API pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
daveaglick committed Dec 22, 2023
1 parent 547b93d commit 7de0707
Showing 1 changed file with 231 additions and 0 deletions.
231 changes: 231 additions & 0 deletions tests/Statiq.Docs.Tests/Pipelines/ApiFixture.cs
Original file line number Diff line number Diff line change
@@ -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<string>());
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<string>());
TestFileProvider fileProvider = new TestFileProvider
{
{
"/input/index.md",
"Index"
},
{
"/src/code.cs",
@"
using System.Text;
namespace Foo
{
public class Blue<Fizz>
{
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<string>());
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<string>());
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<string>());
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");
}
}
}
}

0 comments on commit 7de0707

Please sign in to comment.