Skip to content

Commit 7712503

Browse files
Merge pull request #2 from A9G-Data-Droid/RenderTests
Render tests
2 parents 6fafc4e + 3249c62 commit 7712503

File tree

4 files changed

+2672
-15
lines changed

4 files changed

+2672
-15
lines changed

mermaid-graph/Commands.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ namespace MermaidGraph;
1010
/// </summary>
1111
public class Commands
1212
{
13-
private readonly StringBuilder _graph;
13+
public const string MermaidBegin = Fence + "mermaid";
14+
public const string Fence = "```";
1415

15-
private const string Fence = "```";
16+
private readonly StringBuilder _graph;
1617

1718
/// <summary>
1819
/// Initialize the graph output
@@ -93,7 +94,7 @@ type solution
9394

9495
private void Header(string title)
9596
{
96-
_graph.AppendLine(Fence + "mermaid");
97+
_graph.AppendLine(MermaidBegin);
9798
_graph.AppendLine($"""
9899
---
99100
title: {title}

mermaid-graphTests/CommandsTests.cs

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,34 @@
1-
using NUnit.Framework;
1+
using Microsoft.ClearScript.V8;
2+
using NUnit.Framework;
23
using Assert = NUnit.Framework.Assert;
34

45
namespace MermaidGraph.Tests;
56

6-
[TestFixture()]
7+
[TestFixture]
78
public class CommandsTests
89
{
9-
[Test()]
10+
private V8ScriptEngine? _engine;
11+
private V8ScriptEngine Js {
12+
get
13+
{
14+
if (_engine is null)
15+
{
16+
_engine ??= new V8ScriptEngine();
17+
_engine.Execute(File.ReadAllText("js\\mermaid.min.js"));
18+
_engine.Script.mermaid.initialize();
19+
}
20+
21+
return _engine;
22+
}
23+
}
24+
25+
[OneTimeTearDown]
26+
public void Disposal()
27+
{
28+
_engine?.Dispose();
29+
}
30+
31+
[Test]
1032
public void DogFoodSolutionTest()
1133
{
1234
var solutionPath = FindFileDownTree("*.sln");
@@ -16,10 +38,14 @@ public void DogFoodSolutionTest()
1638
var graph = new Commands().Solution(info);
1739

1840
Console.WriteLine(graph);
41+
42+
var graphType = DetectType(ExtractMermaid(graph));
43+
Assert.That(graphType, Is.EqualTo("class"));
44+
Console.WriteLine(graphType);
1945
}
2046

21-
[Test()]
22-
public void DogFoodProjectTest()
47+
[Test]
48+
public void DogFoodProjectTestAsync()
2349
{
2450
var filePath = FindFileDownTree("*.csproj");
2551
Assert.That(filePath, Is.Not.Null);
@@ -28,27 +54,29 @@ public void DogFoodProjectTest()
2854
var graph = new Commands().Project(info);
2955

3056
Console.WriteLine(graph);
57+
58+
var graphType = DetectType(ExtractMermaid(graph));
59+
Assert.That(graphType, Is.EqualTo("class"));
60+
Console.WriteLine(graphType);
3161
}
3262

33-
[Test()]
63+
[Test]
3464
public void CommandLineProjectTest()
3565
{
3666
var filePath = FindFileDownTree("*.csproj");
3767
Assert.That(filePath, Is.Not.Null);
38-
3968
Assert.That(Program.Main(filePath), Is.EqualTo(0));
4069
}
4170

42-
[Test()]
71+
[Test]
4372
public void CommandLineSolutionTest()
4473
{
4574
var filePath = FindFileDownTree("*.sln");
4675
Assert.That(filePath, Is.Not.Null);
47-
4876
Assert.That(Program.Main(filePath), Is.EqualTo(0));
4977
}
5078

51-
[Test()]
79+
[Test]
5280
[TestCase(null, 1)]
5381
[TestCase("File Not Found", 2)]
5482
[TestCase("mermaid-graph.dll", 3)]
@@ -57,11 +85,24 @@ public void CommandLineFailTests(string? file, int hResult)
5785
{
5886
var filePath = FindFileDownTree("*.csproj");
5987
Assert.That(filePath, Is.Not.Null);
60-
6188
Assert.That(Program.Main(file), Is.EqualTo(hResult));
6289
}
6390

64-
public static string? FindFileDownTree(string searchPattern)
91+
private static string ExtractMermaid(string markup)
92+
{
93+
Assert.That(markup, Does.StartWith(Commands.MermaidBegin));
94+
markup = markup.Substring(Commands.MermaidBegin.Length + Environment.NewLine.Length);
95+
96+
Assert.That(markup, Does.EndWith(Commands.Fence + Environment.NewLine));
97+
return markup.Substring(0, markup.Length - Commands.MermaidBegin.Length + Environment.NewLine.Length);
98+
}
99+
100+
private string? DetectType(string markup)
101+
{
102+
return Js.Script.mermaid.detectType(markup);
103+
}
104+
105+
private static string? FindFileDownTree(string searchPattern)
65106
{
66107
var currentDir = Directory.GetCurrentDirectory();
67108

mermaid-graphTests/MermaidGraphTests.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<PrivateAssets>all</PrivateAssets>
1818
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1919
</PackageReference>
20+
<PackageReference Include="Microsoft.ClearScript.V8" Version="7.4.5" />
21+
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.4.5" />
2022
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
2123
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
2224
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
@@ -36,4 +38,10 @@
3638
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
3739
</ItemGroup>
3840

41+
<ItemGroup>
42+
<None Update="js\mermaid.min.js">
43+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
44+
</None>
45+
</ItemGroup>
46+
3947
</Project>

0 commit comments

Comments
 (0)