Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions mermaid-graph/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
/// </summary>
public class Commands
{
private readonly StringBuilder _graph;
public const string MermaidBegin = Fence + "mermaid";

Check warning on line 13 in mermaid-graph/Commands.cs

View workflow job for this annotation

GitHub Actions / pack

Missing XML comment for publicly visible type or member 'Commands.MermaidBegin'

Check warning on line 13 in mermaid-graph/Commands.cs

View workflow job for this annotation

GitHub Actions / pack

Missing XML comment for publicly visible type or member 'Commands.MermaidBegin'
public const string Fence = "```";

Check warning on line 14 in mermaid-graph/Commands.cs

View workflow job for this annotation

GitHub Actions / pack

Missing XML comment for publicly visible type or member 'Commands.Fence'

Check warning on line 14 in mermaid-graph/Commands.cs

View workflow job for this annotation

GitHub Actions / pack

Missing XML comment for publicly visible type or member 'Commands.Fence'

private const string Fence = "```";
private readonly StringBuilder _graph;

/// <summary>
/// Initialize the graph output
Expand Down Expand Up @@ -93,7 +94,7 @@

private void Header(string title)
{
_graph.AppendLine(Fence + "mermaid");
_graph.AppendLine(MermaidBegin);
_graph.AppendLine($"""
---
title: {title}
Expand Down
65 changes: 53 additions & 12 deletions mermaid-graphTests/CommandsTests.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
using NUnit.Framework;
using Microsoft.ClearScript.V8;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;

namespace MermaidGraph.Tests;

[TestFixture()]
[TestFixture]
public class CommandsTests
{
[Test()]
private V8ScriptEngine? _engine;
private V8ScriptEngine Js {
get
{
if (_engine is null)
{
_engine ??= new V8ScriptEngine();
_engine.Execute(File.ReadAllText("js\\mermaid.min.js"));
_engine.Script.mermaid.initialize();
}

return _engine;
}
}

[OneTimeTearDown]
public void Disposal()
{
_engine?.Dispose();
}

[Test]
public void DogFoodSolutionTest()
{
var solutionPath = FindFileDownTree("*.sln");
Expand All @@ -16,10 +38,14 @@ public void DogFoodSolutionTest()
var graph = new Commands().Solution(info);

Console.WriteLine(graph);

var graphType = DetectType(ExtractMermaid(graph));
Assert.That(graphType, Is.EqualTo("class"));
Console.WriteLine(graphType);
}

[Test()]
public void DogFoodProjectTest()
[Test]
public void DogFoodProjectTestAsync()
{
var filePath = FindFileDownTree("*.csproj");
Assert.That(filePath, Is.Not.Null);
Expand All @@ -28,27 +54,29 @@ public void DogFoodProjectTest()
var graph = new Commands().Project(info);

Console.WriteLine(graph);

var graphType = DetectType(ExtractMermaid(graph));
Assert.That(graphType, Is.EqualTo("class"));
Console.WriteLine(graphType);
}

[Test()]
[Test]
public void CommandLineProjectTest()
{
var filePath = FindFileDownTree("*.csproj");
Assert.That(filePath, Is.Not.Null);

Assert.That(Program.Main(filePath), Is.EqualTo(0));
}

[Test()]
[Test]
public void CommandLineSolutionTest()
{
var filePath = FindFileDownTree("*.sln");
Assert.That(filePath, Is.Not.Null);

Assert.That(Program.Main(filePath), Is.EqualTo(0));
}

[Test()]
[Test]
[TestCase(null, 1)]
[TestCase("File Not Found", 2)]
[TestCase("mermaid-graph.dll", 3)]
Expand All @@ -57,11 +85,24 @@ public void CommandLineFailTests(string? file, int hResult)
{
var filePath = FindFileDownTree("*.csproj");
Assert.That(filePath, Is.Not.Null);

Assert.That(Program.Main(file), Is.EqualTo(hResult));
}

public static string? FindFileDownTree(string searchPattern)
private static string ExtractMermaid(string markup)
{
Assert.That(markup, Does.StartWith(Commands.MermaidBegin));
markup = markup.Substring(Commands.MermaidBegin.Length + Environment.NewLine.Length);

Assert.That(markup, Does.EndWith(Commands.Fence + Environment.NewLine));
return markup.Substring(0, markup.Length - Commands.MermaidBegin.Length + Environment.NewLine.Length);
}

private string? DetectType(string markup)
{
return Js.Script.mermaid.detectType(markup);
}

private static string? FindFileDownTree(string searchPattern)
{
var currentDir = Directory.GetCurrentDirectory();

Expand Down
8 changes: 8 additions & 0 deletions mermaid-graphTests/MermaidGraphTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.ClearScript.V8" Version="7.4.5" />
<PackageReference Include="Microsoft.ClearScript.V8.Native.win-x64" Version="7.4.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.7.3" />
<PackageReference Include="MSTest.TestFramework" Version="3.7.3" />
Expand All @@ -36,4 +38,10 @@
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>

<ItemGroup>
<None Update="js\mermaid.min.js">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Loading
Loading