Skip to content

Commit

Permalink
fix snapshot tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVollmers committed May 6, 2024
1 parent 5ec6c34 commit 224b618
Show file tree
Hide file tree
Showing 16 changed files with 15 additions and 12 deletions.
4 changes: 0 additions & 4 deletions tests/Doki.Tests.Snapshots/Doki.Tests.Snapshots.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@
<ProjectReference Include="..\assemblies\Doki.TestAssembly.InheritanceChain\Doki.TestAssembly.InheritanceChain.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="__snapshots__\" />
</ItemGroup>

</Project>
10 changes: 5 additions & 5 deletions tests/Doki.Tests.Snapshots/Snapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class Snapshot

public string Name { get; init; }

public OutputContext Context { get; init; } =
new(new DirectoryInfo(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"))), null);
public DirectoryInfo OutputDirectory { get; init; } =
new(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));

private Snapshot(string name)
{
Expand All @@ -33,7 +33,7 @@ public Snapshot SaveIfNotExists()

_snapshotDirectory.Create();

var sourcePath = Context.WorkingDirectory.FullName;
var sourcePath = OutputDirectory.FullName;
var targetPath = _snapshotDirectory.FullName;

foreach (var dirPath in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
Expand All @@ -58,13 +58,13 @@ public async Task MatchSnapshotAsync(ITestOutputHelper testOutputHelper)
}

testOutputHelper.WriteLine($"Verifying snapshot '{Name}'");
testOutputHelper.WriteLine($"Generated snapshot directory: {Context.WorkingDirectory.FullName}");
testOutputHelper.WriteLine($"Generated snapshot directory: {OutputDirectory.FullName}");

var snapshotFiles = _snapshotDirectory.GetFiles("*.*", SearchOption.AllDirectories);
foreach (var snapshotFile in snapshotFiles)
{
var relativePath = snapshotFile.FullName.Replace(_snapshotDirectory.FullName, "");
var sourceFile = new FileInfo(Context.WorkingDirectory.FullName + relativePath);
var sourceFile = new FileInfo(OutputDirectory.FullName + relativePath);

if (!sourceFile.Exists)
{
Expand Down
13 changes: 10 additions & 3 deletions tests/Doki.Tests.Snapshots/SnapshotTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Xml.XPath;
using Doki.Output;
using Doki.Output.Markdown;
using Doki.TestAssembly;
using Doki.TestAssembly.InheritanceChain;
Expand All @@ -21,13 +22,16 @@ public async Task Test_RootNamespaceIsParentNamespace()

generator.AddAssembly(typeof(TestParentRootNamespaceClass).Assembly, emptyDocumentation);

generator.AddOutput(new MarkdownOutput(snapshot.Context));
generator.AddOutput(new MarkdownOutput(new OutputOptions<MarkdownOutput>
{
OutputDirectory = snapshot.OutputDirectory
}));

await generator.GenerateAsync(NullLogger.Instance);

await snapshot.SaveIfNotExists().MatchSnapshotAsync(testOutputHelper);
}

[Fact]
public async Task Test_InheritanceChain()
{
Expand All @@ -40,7 +44,10 @@ public async Task Test_InheritanceChain()
generator.AddAssembly(typeof(AbstractClass).Assembly, emptyDocumentation);
generator.AddAssembly(typeof(SimpleClass).Assembly, emptyDocumentation);

generator.AddOutput(new MarkdownOutput(snapshot.Context));
generator.AddOutput(new MarkdownOutput(new OutputOptions<MarkdownOutput>
{
OutputDirectory = snapshot.OutputDirectory
}));

await generator.GenerateAsync(NullLogger.Instance);

Expand Down

0 comments on commit 224b618

Please sign in to comment.