1- using NUnit . Framework ;
1+ using Microsoft . ClearScript . V8 ;
2+ using NUnit . Framework ;
23using Assert = NUnit . Framework . Assert ;
34
45namespace MermaidGraph . Tests ;
56
6- [ TestFixture ( ) ]
7+ [ TestFixture ]
78public 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
0 commit comments