diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml
index e8308b2..2752677 100644
--- a/.github/workflows/publish.yml
+++ b/.github/workflows/publish.yml
@@ -1,6 +1,10 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: publish
+permissions:
+ contents: read
+ pull-requests: write
+
on:
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
push:
diff --git a/Directory.Build.props b/Directory.Build.props
new file mode 100644
index 0000000..e638e40
--- /dev/null
+++ b/Directory.Build.props
@@ -0,0 +1,9 @@
+
+
+
+
+ all
+ 3.7.115
+
+
+
\ No newline at end of file
diff --git a/MermaidGraph.NET.md b/MermaidGraph.NET.md
index 39c755c..1f4031c 100644
--- a/MermaidGraph.NET.md
+++ b/MermaidGraph.NET.md
@@ -16,17 +16,17 @@ classDiagram
}
class Microsoft.Build{
type NuGet
- version 17.12.6
+ version 17.13.9
}
mermaid-graph ..> Microsoft.Build
class Microsoft.Build.Locator{
type NuGet
- version 1.7.8
+ version 1.9.1
}
mermaid-graph ..> Microsoft.Build.Locator
class Microsoft.Build.Utilities.Core{
type NuGet
- version 17.12.6
+ version 17.13.9
}
mermaid-graph ..> Microsoft.Build.Utilities.Core
class System.CommandLine.DragonFruit{
@@ -50,6 +50,16 @@ classDiagram
version 6.0.4
}
MermaidGraphTests ..> coverlet.msbuild
+ class Microsoft.ClearScript.V8{
+ type NuGet
+ version 7.5.0
+ }
+ MermaidGraphTests ..> Microsoft.ClearScript.V8
+ class Microsoft.ClearScript.V8.Native.win-x64{
+ type NuGet
+ version 7.5.0
+ }
+ MermaidGraphTests ..> Microsoft.ClearScript.V8.Native.win-x64
class Microsoft.NET.Test.Sdk{
type NuGet
version 17.13.0
@@ -57,12 +67,12 @@ classDiagram
MermaidGraphTests ..> Microsoft.NET.Test.Sdk
class MSTest.TestAdapter{
type NuGet
- version 3.7.3
+ version 3.8.3
}
MermaidGraphTests ..> MSTest.TestAdapter
class MSTest.TestFramework{
type NuGet
- version 3.7.3
+ version 3.8.3
}
MermaidGraphTests ..> MSTest.TestFramework
class NUnit{
@@ -72,12 +82,13 @@ classDiagram
MermaidGraphTests ..> NUnit
class NUnit.Analyzers{
type NuGet
- version 4.6.0
+ version 4.7.0
}
MermaidGraphTests ..> NUnit.Analyzers
class NUnit3TestAdapter{
type NuGet
- version 4.3.2
+ version 5.0.0
}
MermaidGraphTests ..> NUnit3TestAdapter
```
+
diff --git a/MermaidGraph.NET.sln b/MermaidGraph.NET.sln
index 6b48d6c..987ece0 100644
--- a/MermaidGraph.NET.sln
+++ b/MermaidGraph.NET.sln
@@ -8,7 +8,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{C33AF3DC-C3F9-45B6-828C-57CB2B60EC96}"
ProjectSection(SolutionItems) = preProject
MermaidGraph.NET.md = MermaidGraph.NET.md
+ .github\workflows\publish.yml = .github\workflows\publish.yml
README.md = README.md
+ version.json = version.json
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MermaidGraphTests", "mermaid-graphTests\MermaidGraphTests.csproj", "{FADD9D23-431E-4C1B-B2D4-D4FDF0674FCA}"
diff --git a/README.md b/README.md
index 4afac30..97ec980 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@
Create a mermaid graph of the dependency diagram for a project, or whole solution.
-## Dotnet tool [](https://www.nuget.org/packages/mermaid-graph/)
+## Dotnet tool [](https://www.nuget.org/packages/mermaid-graph/)
You can install as a dotnet tool so you can easily map all of your software projects:
@@ -21,6 +21,8 @@ Usage:
Options:
--path Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.
--type The type of diagram to generate (e.g., Graph or Class). [default: Graph]
+ --filter Exclude projects whose name matches the filter. (e.g., Test). []
+ --no-nuget Do not include NuGet packages in the graph. [default: False]
--version Show version information
-?, -h, --help Show help and usage information
```
@@ -53,17 +55,17 @@ classDiagram
}
class Microsoft.Build{
type NuGet
- version 17.12.6
+ version 17.13.9
}
mermaid-graph ..> Microsoft.Build
class Microsoft.Build.Locator{
type NuGet
- version 1.7.8
+ version 1.9.1
}
mermaid-graph ..> Microsoft.Build.Locator
class Microsoft.Build.Utilities.Core{
type NuGet
- version 17.12.6
+ version 17.13.9
}
mermaid-graph ..> Microsoft.Build.Utilities.Core
class System.CommandLine.DragonFruit{
@@ -89,12 +91,12 @@ classDiagram
MermaidGraphTests ..> coverlet.msbuild
class Microsoft.ClearScript.V8{
type NuGet
- version 7.4.5
+ version 7.5.0
}
MermaidGraphTests ..> Microsoft.ClearScript.V8
class Microsoft.ClearScript.V8.Native.win-x64{
type NuGet
- version 7.4.5
+ version 7.5.0
}
MermaidGraphTests ..> Microsoft.ClearScript.V8.Native.win-x64
class Microsoft.NET.Test.Sdk{
@@ -104,12 +106,12 @@ classDiagram
MermaidGraphTests ..> Microsoft.NET.Test.Sdk
class MSTest.TestAdapter{
type NuGet
- version 3.7.3
+ version 3.8.3
}
MermaidGraphTests ..> MSTest.TestAdapter
class MSTest.TestFramework{
type NuGet
- version 3.7.3
+ version 3.8.3
}
MermaidGraphTests ..> MSTest.TestFramework
class NUnit{
@@ -119,12 +121,12 @@ classDiagram
MermaidGraphTests ..> NUnit
class NUnit.Analyzers{
type NuGet
- version 4.6.0
+ version 4.7.0
}
MermaidGraphTests ..> NUnit.Analyzers
class NUnit3TestAdapter{
type NuGet
- version 4.3.2
+ version 5.0.0
}
MermaidGraphTests ..> NUnit3TestAdapter
```
diff --git a/mermaid-graph/Commands.cs b/mermaid-graph/Commands.cs
index 32e3547..911812d 100644
--- a/mermaid-graph/Commands.cs
+++ b/mermaid-graph/Commands.cs
@@ -1,4 +1,4 @@
-using MermaidGraph.Diagrams;
+using MermaidGraph.Diagrams.Base;
namespace MermaidGraph;
@@ -10,31 +10,20 @@ public class Commands
///
/// Generate the dependency graph of a Visual Studio Project.
///
- /// `.csproj` file.
- ///
- public static string Project(FileInfo file, DiagramType diagramType = DiagramType.Graph)
+ public static string Project(FileInfo file, DiagramType diagramType = DiagramType.Graph, string? filter = null, bool excludeNuget = false)
{
- var graph = GetGraphType(diagramType);
+ var graph = MermaidDiagram.GetDiagramType(diagramType);
- return graph.Project(file);
+ return graph.Project(file, filter, excludeNuget);
}
///
/// Generate the dependency graph of a Visual Studio Solution.
///
- /// `.sln` file.
- ///
- public static string Solution(FileInfo file, DiagramType diagramType = DiagramType.Graph)
+ public static string Solution(FileInfo file, DiagramType diagramType = DiagramType.Graph, string? filter = null, bool excludeNuget = false)
{
- var graph = GetGraphType(diagramType);
+ var graph = MermaidDiagram.GetDiagramType(diagramType);
- return graph.Solution(file);
+ return graph.Solution(file, filter, excludeNuget);
}
-
- private static IMermaidDiagram GetGraphType(DiagramType diagramType) => diagramType switch
- {
- DiagramType.Class => new ClassDiagram(),
- DiagramType.Graph => new GraphDiagram(),
- _ => throw new NotImplementedException($"Option not supported: {diagramType}"),
- };
}
\ No newline at end of file
diff --git a/mermaid-graph/Diagrams/DiagramType.cs b/mermaid-graph/Diagrams/Base/DiagramType.cs
similarity index 87%
rename from mermaid-graph/Diagrams/DiagramType.cs
rename to mermaid-graph/Diagrams/Base/DiagramType.cs
index d580ec6..d422c57 100644
--- a/mermaid-graph/Diagrams/DiagramType.cs
+++ b/mermaid-graph/Diagrams/Base/DiagramType.cs
@@ -1,4 +1,4 @@
-namespace MermaidGraph.Diagrams;
+namespace MermaidGraph.Diagrams.Base;
///
/// Specifies the type of mermaid diagram to generate.
diff --git a/mermaid-graph/Diagrams/IMermaidDiagram.cs b/mermaid-graph/Diagrams/Base/IMermaidDiagram.cs
similarity index 54%
rename from mermaid-graph/Diagrams/IMermaidDiagram.cs
rename to mermaid-graph/Diagrams/Base/IMermaidDiagram.cs
index d9c6221..5bf2f6f 100644
--- a/mermaid-graph/Diagrams/IMermaidDiagram.cs
+++ b/mermaid-graph/Diagrams/Base/IMermaidDiagram.cs
@@ -1,4 +1,4 @@
-namespace MermaidGraph.Diagrams;
+namespace MermaidGraph.Diagrams.Base;
///
/// This file defines the IMermaidDiagram interface and the MermaidDiagram abstract class.
@@ -11,13 +11,17 @@ public interface IMermaidDiagram
/// Generate the diagram from a visual studio project file (*.csproj)
///
/// The project file
+ /// Exclude projects whose name matches the filter. (e.g., Test)
+ /// Do not include NuGet packages in the graph
/// Mermaid Markdown
- public string Project(FileInfo file);
+ public string Project(FileInfo file, string? filter = null, bool excludeNuget = false);
///
/// Generate the diagram from a visual studio solution file (*.sln)
///
/// The solution file.
+ /// Exclude projects whose name matches the filter. (e.g., Test)
+ /// Do not include NuGet packages in the graph
/// Mermaid Markdown
- public string Solution(FileInfo file);
+ public string Solution(FileInfo file, string? filter = null, bool excludeNuget = false);
}
\ No newline at end of file
diff --git a/mermaid-graph/Diagrams/Base/MermaidDiagram.cs b/mermaid-graph/Diagrams/Base/MermaidDiagram.cs
new file mode 100644
index 0000000..2ba3073
--- /dev/null
+++ b/mermaid-graph/Diagrams/Base/MermaidDiagram.cs
@@ -0,0 +1,96 @@
+using System.Text;
+using Microsoft.Build.Evaluation;
+using Microsoft.Build.Locator;
+
+namespace MermaidGraph.Diagrams.Base;
+
+///
+/// The MermaidDiagram abstract class implements shared functionality for Mermaid diagram generation,
+/// including initializing the graph output and managing the graph buffer.
+///
+public abstract class MermaidDiagram : IMermaidDiagram
+{
+ ///
+ /// Code block fence.
+ ///
+ public const string Fence = "```";
+
+ ///
+ /// Mermaid code block.
+ ///
+ public const string MermaidBegin = Fence + "mermaid";
+
+ internal StringBuilder Graph { get; } = new(256);
+
+ ///
+ /// Initialize the MermaidDiagram class and ensure MSBuild is registered.
+ ///
+ protected MermaidDiagram()
+ {
+ if (!MSBuildLocator.IsRegistered)
+ {
+ MSBuildLocator.RegisterDefaults();
+ }
+ }
+
+ ///
+ /// Factory method to get the appropriate graph type based on the provided DiagramType enum value.
+ ///
+ /// The type of graph to generate.
+ /// The appropriate methods for generating a diagram of that type.
+ /// If an enum type is added without corresponding diagram class.
+ public static IMermaidDiagram GetDiagramType(DiagramType diagramType) => diagramType switch
+ {
+ DiagramType.Class => new ClassDiagram(),
+ DiagramType.Graph => new GraphDiagram(),
+ _ => throw new NotImplementedException($"Option not supported: {diagramType}"),
+ };
+
+ ///
+ /// Initialize the graph output.
+ ///
+ public virtual void Header(string title)
+ {
+ Graph.Clear();
+ Graph.AppendLine($"""
+ {MermaidBegin}
+ ---
+ title: {title}
+ config:
+ class:
+ hideEmptyMembersBox: true
+ ---
+ """);
+ }
+
+ ///
+ /// Get the mermaid diagram Markdown text.
+ ///
+ /// The contents of the graph buffer.
+ public override string ToString() => Graph.ToString();
+
+ ///
+ public virtual string Project(FileInfo file, string? filter = null, bool excludeNuget = false)
+ {
+ Header(file.Name);
+ using var projectCollection = new ProjectCollection();
+ var project = projectCollection.LoadProject(file.FullName);
+ GraphProject(project, filter, excludeNuget);
+ Graph.AppendLine(Fence);
+
+ projectCollection.UnloadAllProjects();
+
+ return Graph.ToString();
+ }
+
+ ///
+ public abstract string Solution(FileInfo file, string? filter = null, bool excludeNuget = false);
+
+ ///
+ /// This method must be implemented in all derived classes to generate the graph for a project.
+ ///
+ /// A project to graph.
+ /// Exclude projects whose name matches the filter. (e.g., Test)
+ /// Do not include NuGet packages in the graph
+ internal abstract void GraphProject(Project project, string? filter = null, bool excludeNuget = false);
+}
diff --git a/mermaid-graph/Diagrams/ClassDiagram.cs b/mermaid-graph/Diagrams/ClassDiagram.cs
index f69e09f..70b5645 100644
--- a/mermaid-graph/Diagrams/ClassDiagram.cs
+++ b/mermaid-graph/Diagrams/ClassDiagram.cs
@@ -1,9 +1,13 @@
-using Microsoft.Build.Construction;
+using MermaidGraph.Diagrams.Base;
+using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
namespace MermaidGraph.Diagrams;
-internal class ClassDiagram : MermaidDiagram
+///
+/// Generates a Mermaid class diagram.
+///
+public sealed class ClassDiagram : MermaidDiagram
{
///
public override void Header(string title)
@@ -12,28 +16,8 @@ public override void Header(string title)
Graph.AppendLine("classDiagram");
}
- ///
- /// Generate the dependency graph of a Visual Studio Project.
- ///
- /// `.csproj` file.
- public override string Project(FileInfo file)
- {
- Header(file.Name);
- using var projectCollection = new ProjectCollection();
- var project = projectCollection.LoadProject(file.FullName);
- GraphProject(project);
- Graph.AppendLine(Fence);
-
- projectCollection.UnloadAllProjects();
-
- return Graph.ToString();
- }
-
- ///
- /// Generate the dependency graph of a Visual Studio Solution.
- ///
- /// `.sln` file.
- public override string Solution(FileInfo file)
+ ///
+ public override string Solution(FileInfo file, string? filter = null, bool excludeNuget = false)
{
Header(file.Name);
var solutionFile = SolutionFile.Parse(file.FullName);
@@ -50,15 +34,19 @@ type solution
foreach (var project in solutionFile.ProjectsInOrder)
{
if (project.ProjectType != SolutionProjectType.KnownToBeMSBuildFormat) continue;
-
+
var projectPath = project.AbsolutePath;
var projectName = Path.GetFileNameWithoutExtension(projectPath);
+ if (!string.IsNullOrEmpty(filter) &&
+ projectName.Contains(filter, StringComparison.Ordinal))
+ continue;
+
Graph.AppendLine($" {solutionId} --> {projectName}");
var projectFile = new FileInfo(projectPath);
if (projectFile.Exists)
{
var referenceProject = projectCollection.LoadProject(projectFile.FullName);
- GraphProject(referenceProject);
+ GraphProject(referenceProject, filter, excludeNuget);
}
}
@@ -69,11 +57,13 @@ type solution
return Graph.ToString();
}
- private void GraphProject(Project project)
+ internal override void GraphProject(Project project, string? filter = null, bool excludeNuget = false)
{
var projectName = Path.GetFileNameWithoutExtension(project.FullPath);
var type = project.GetPropertyValue("OutputType");
- var targetFramework = project.GetPropertyValue("TargetFramework") ?? project.GetPropertyValue("TargetFrameworks");
+ var targetFramework = project.GetPropertyValue("TargetFramework") ??
+ project.GetPropertyValue("TargetFrameworks");
+
Graph.AppendLine($$"""
class {{projectName}}{
type {{type}}
@@ -85,9 +75,14 @@ class {{projectName}}{
{
var refPath = item.EvaluatedInclude;
var refName = Path.GetFileNameWithoutExtension(refPath);
+ if (!string.IsNullOrEmpty(filter) &&
+ projectName.Contains(filter, StringComparison.Ordinal))
+ continue;
+
Graph.AppendLine($" {projectName} ..> {refName}");
}
+ if (excludeNuget) return;
foreach (var item in project.GetItems("PackageReference"))
{
var packageName = item.EvaluatedInclude;
diff --git a/mermaid-graph/Diagrams/GraphDiagram.cs b/mermaid-graph/Diagrams/GraphDiagram.cs
index 809a36a..df91674 100644
--- a/mermaid-graph/Diagrams/GraphDiagram.cs
+++ b/mermaid-graph/Diagrams/GraphDiagram.cs
@@ -1,9 +1,13 @@
-using Microsoft.Build.Construction;
+using MermaidGraph.Diagrams.Base;
+using Microsoft.Build.Construction;
using Microsoft.Build.Evaluation;
namespace MermaidGraph.Diagrams;
-internal class GraphDiagram : MermaidDiagram
+///
+/// Generates a Mermaid dependency graph for Visual Studio projects and solutions.
+///
+public sealed class GraphDiagram : MermaidDiagram
{
///
public override void Header(string title)
@@ -12,28 +16,8 @@ public override void Header(string title)
Graph.AppendLine("graph TD");
}
- ///
- /// Generate the dependency graph of a Visual Studio Project.
- ///
- /// `.csproj` file.
- public override string Project(FileInfo file)
- {
- Header(file.Name);
- using var projectCollection = new ProjectCollection();
- var project = projectCollection.LoadProject(file.FullName);
- GraphProject(project);
- Graph.AppendLine(Fence);
-
- projectCollection.UnloadAllProjects();
-
- return Graph.ToString();
- }
-
- ///
- /// Generate the dependency graph of a Visual Studio Solution.
- ///
- /// `.sln` file.
- public override string Solution(FileInfo file)
+ ///
+ public override string Solution(FileInfo file, string? filter = null, bool excludeNuget = false)
{
Header(file.Name);
var solutionFile = SolutionFile.Parse(file.FullName);
@@ -48,12 +32,16 @@ public override string Solution(FileInfo file)
var projectPath = project.AbsolutePath;
var projectName = Path.GetFileNameWithoutExtension(projectPath);
+ if (!string.IsNullOrEmpty(filter) &&
+ projectName.Contains(filter, StringComparison.Ordinal))
+ continue;
+
Graph.AppendLine($" {solutionId} --> {projectName}");
var projectFile = new FileInfo(projectPath);
if (projectFile.Exists)
{
var referenceProject = projectCollection.LoadProject(projectFile.FullName);
- GraphProject(referenceProject);
+ GraphProject(referenceProject, filter, excludeNuget);
}
}
@@ -64,7 +52,7 @@ public override string Solution(FileInfo file)
return Graph.ToString();
}
- private void GraphProject(Project project)
+ internal override void GraphProject(Project project, string? filter = null, bool excludeNuget = false)
{
var projectName = Path.GetFileNameWithoutExtension(project.FullPath);
@@ -72,9 +60,14 @@ private void GraphProject(Project project)
{
var refPath = item.EvaluatedInclude;
var refName = Path.GetFileNameWithoutExtension(refPath);
+ if (!string.IsNullOrEmpty(filter) &&
+ projectName.Contains(filter, StringComparison.Ordinal))
+ continue;
+
Graph.AppendLine($" {projectName} --> {refName}");
}
+ if (excludeNuget) return;
foreach (var item in project.GetItems("PackageReference"))
{
var packageName = item.EvaluatedInclude;
diff --git a/mermaid-graph/Diagrams/MermaidDiagram.cs b/mermaid-graph/Diagrams/MermaidDiagram.cs
deleted file mode 100644
index 8aeebdc..0000000
--- a/mermaid-graph/Diagrams/MermaidDiagram.cs
+++ /dev/null
@@ -1,63 +0,0 @@
-using System.Text;
-using Microsoft.Build.Locator;
-
-namespace MermaidGraph.Diagrams;
-
-///
-/// The MermaidDiagram abstract class implements shared functionality for Mermaid diagram generation,
-/// including initializing the graph output and managing the graph buffer.
-///
-public abstract class MermaidDiagram : IMermaidDiagram
-{
- ///
- /// Code block fence.
- ///
- public const string Fence = "```";
-
- ///
- /// Mermaid code block.
- ///
- public const string MermaidBegin = Fence + "mermaid";
-
- internal readonly StringBuilder Graph = new();
-
- ///
- /// Initialize the MermaidDiagram class and ensure MSBuild is registered.
- ///
- protected MermaidDiagram()
- {
- if (!MSBuildLocator.IsRegistered)
- {
- MSBuildLocator.RegisterDefaults();
- }
- }
-
- ///
- /// Initialize the graph output.
- ///
- public virtual void Header(string title)
- {
- Graph.Clear();
- Graph.AppendLine(MermaidBegin);
- Graph.AppendLine($"""
- ---
- title: {title}
- config:
- class:
- hideEmptyMembersBox: true
- ---
- """);
- }
-
- ///
- /// Get the mermaid diagram Markdown text.
- ///
- /// The contents of the graph buffer.
- public override string ToString() => Graph.ToString();
-
- ///
- public abstract string Project(FileInfo file);
-
- ///
- public abstract string Solution(FileInfo file);
-}
diff --git a/mermaid-graph/Program.cs b/mermaid-graph/Program.cs
index 4a52f4d..3c014b6 100644
--- a/mermaid-graph/Program.cs
+++ b/mermaid-graph/Program.cs
@@ -1,4 +1,4 @@
-using MermaidGraph.Diagrams;
+using MermaidGraph.Diagrams.Base;
namespace MermaidGraph;
@@ -12,8 +12,10 @@ public sealed class Program
///
/// Full path to the solution (*.sln) or project (*.csproj) file that will be mapped.
/// The type of diagram to generate (e.g., Graph or Class).
+ /// Exclude projects whose name matches the filter. (e.g., Test).
+ /// Do not include NuGet packages in the graph.
/// HResult
- public static int Main(string? path, DiagramType type = DiagramType.Graph)
+ public static int Main(string? path, DiagramType type = DiagramType.Graph, string? filter = null, bool noNuget = false)
{
if (path is null)
{
@@ -34,13 +36,13 @@ public static int Main(string? path, DiagramType type = DiagramType.Graph)
{
if (path.EndsWith(".csproj"))
{
- Console.WriteLine(Commands.Project(file, type));
+ Console.WriteLine(Commands.Project(file, type, filter, noNuget));
return 0;
}
if (path.EndsWith(".sln"))
{
- Console.WriteLine(Commands.Solution(file, type));
+ Console.WriteLine(Commands.Solution(file, type, filter, noNuget));
return 0;
}
}
diff --git a/mermaid-graph/mermaid-graph.csproj b/mermaid-graph/mermaid-graph.csproj
index aead51d..69c7706 100644
--- a/mermaid-graph/mermaid-graph.csproj
+++ b/mermaid-graph/mermaid-graph.csproj
@@ -22,16 +22,15 @@
https://github.com/A9G-Data-Droid/MermaidGraph.NET.git
mermaid.js
en
- $(AssemblyVersion)
+ $(Version)
True
mermaid-graph.png
mermaid-graph.ico
- 1.0.0
+ 1.1.0
LICENSE
true
-
-
-
+ 1.0.0
+ $(Version)
@@ -64,9 +63,8 @@
-
-
-
+
+
diff --git a/mermaid-graphTests/CommandsTests.cs b/mermaid-graphTests/CommandsTests.cs
index 1ec7da0..1252a0c 100644
--- a/mermaid-graphTests/CommandsTests.cs
+++ b/mermaid-graphTests/CommandsTests.cs
@@ -1,4 +1,7 @@
-using MermaidGraph.Diagrams;
+using System;
+using System.IO;
+using System.Linq;
+using MermaidGraph.Diagrams.Base;
using Microsoft.ClearScript.V8;
using NUnit.Framework;
using Assert = NUnit.Framework.Assert;
@@ -29,6 +32,12 @@ private V8ScriptEngine Js {
new object[] { DiagramType.Graph, "flowchart" }
];
+ internal static readonly object[] FilterTestCases =
+ [
+ new object[] { DiagramType.Class, "Test" },
+ new object[] { DiagramType.Graph, "Test" }
+ ];
+
[OneTimeTearDown]
public void Disposal()
{
@@ -46,10 +55,13 @@ public void DogFoodSolutionTest(DiagramType type, string typeName)
var graph = Commands.Solution(info, type);
Console.WriteLine(graph);
-
+ Assert.That(graph, Is.Not.Null.Or.Empty, "Graph should not be null or empty.");
+ Assert.That(graph, Does.Contain("mermaid-graph"));
+ Assert.That(graph, Does.Contain("MermaidGraphTests"));
var graphType = DetectType(ExtractMermaid(graph));
+ Console.WriteLine($"Detected type: {graphType}");
+
Assert.That(graphType, Is.EqualTo(typeName));
- Console.WriteLine(graphType);
}
[Test]
@@ -61,7 +73,9 @@ public void DogFoodProjectTest(DiagramType type, string typeName)
var info = new FileInfo(filePath!);
Assert.That(info.Exists);
var graph = Commands.Project(info, type);
-
+ Assert.That(graph, Is.Not.Null.Or.Empty, "Graph should not be null or empty.");
+ Assert.That(graph, Does.Contain("mermaid-graph"));
+ Assert.That(graph, Does.Contain("MermaidGraphTests"));
Console.WriteLine(graph);
var graphType = DetectType(ExtractMermaid(graph));
@@ -97,6 +111,81 @@ public void CommandLineFailTests(string? file, int hResult)
Assert.That(Program.Main(file), Is.EqualTo(hResult));
}
+ [Test]
+ [TestCaseSource(nameof(FilterTestCases))]
+ public void DiagramsShouldNotContainFilteredContent(DiagramType type, string filter)
+ {
+ var solutionPath = FindFileDownTree("*.sln");
+ Assert.That(solutionPath, Is.Not.Null);
+ var info = new FileInfo(solutionPath!);
+ Assert.That(info.Exists);
+ var graph = Commands.Solution(info, type);
+ Assert.That(graph, Does.Contain(filter),
+ $"Original Graph should contain filtered content: {filter}");
+
+ graph = Commands.Solution(info, type, filter);
+ Console.WriteLine(graph);
+ Assert.That(graph, Does.Not.Contain(filter),
+ $"Graph should not contain filtered content: {filter}");
+ }
+
+ [Test]
+ [TestCase(DiagramType.Graph)]
+ [TestCase(DiagramType.Class)]
+ public void Project_ShouldExcludeNuget_WhenExcludeNugetIsTrue(DiagramType type)
+ {
+ var filePath = FindFileDownTree("*.csproj");
+ Assert.That(filePath, Is.Not.Null);
+ var info = new FileInfo(filePath!);
+ Assert.That(info.Exists);
+
+ var graph = Commands.Project(info, type, excludeNuget: true);
+ Assert.That(graph, Does.Not.Contain("NuGet"), "Graph should not contain NuGet references when noNuget is true.");
+ }
+
+ [Test]
+ [TestCase(DiagramType.Graph)]
+ [TestCase(DiagramType.Class)]
+ public void Solution_ShouldExcludeNuget_WhenExcludeNugetIsTrue(DiagramType type)
+ {
+ var solutionPath = FindFileDownTree("*.sln");
+ Assert.That(solutionPath, Is.Not.Null);
+ var info = new FileInfo(solutionPath!);
+ Assert.That(info.Exists);
+
+ var graph = Commands.Solution(info, type, excludeNuget: true);
+ Assert.That(graph, Does.Not.Contain("NuGet"), "Graph should not contain NuGet references when noNuget is true.");
+ }
+
+ [Test]
+ [TestCase(DiagramType.Graph)]
+ [TestCase(DiagramType.Class)]
+ public void Project_ShouldIncludeNuget_WhenExcludeNugetIsFalse(DiagramType type)
+ {
+ var filePath = FindFileDownTree("*.csproj");
+ Assert.That(filePath, Is.Not.Null);
+ var info = new FileInfo(filePath!);
+ Assert.That(info.Exists);
+
+ var graph = Commands.Project(info, type, excludeNuget: false);
+ Assert.That(graph, Does.Contain("NuGet"), "Graph should contain NuGet references when noNuget is false.");
+ }
+
+ [Test]
+ [TestCase(DiagramType.Graph)]
+ [TestCase(DiagramType.Class)]
+ public void Solution_ShouldIncludeNuget_WhenExcludeNugetIsFalse(DiagramType type)
+ {
+ var solutionPath = FindFileDownTree("*.sln");
+ Assert.That(solutionPath, Is.Not.Null);
+ var info = new FileInfo(solutionPath!);
+ Assert.That(info.Exists);
+
+ var graph = Commands.Solution(info, type, excludeNuget: false);
+ Assert.That(graph, Does.Contain("NuGet"), "Graph should contain NuGet references when noNuget is false.");
+ }
+
+
private static string ExtractMermaid(string? markup)
{
Assert.That(markup, Does.StartWith(MermaidDiagram.MermaidBegin));
diff --git a/mermaid-graphTests/MermaidDiagramTests.cs b/mermaid-graphTests/MermaidDiagramTests.cs
new file mode 100644
index 0000000..90ea00a
--- /dev/null
+++ b/mermaid-graphTests/MermaidDiagramTests.cs
@@ -0,0 +1,49 @@
+using System;
+using MermaidGraph.Diagrams;
+using MermaidGraph.Diagrams.Base;
+using NUnit.Framework;
+using Assert = NUnit.Framework.Assert;
+
+namespace MermaidGraph.Tests;
+
+[TestFixture]
+public class MermaidDiagramTests
+{
+ [Test]
+ public void GetDiagramType_ShouldReturnCorrectInstance()
+ {
+ // Arrange & Act
+ var classDiagram = MermaidDiagram.GetDiagramType(DiagramType.Class);
+ var graphDiagram = MermaidDiagram.GetDiagramType(DiagramType.Graph);
+
+ // Assert
+ Assert.That(classDiagram, Is.TypeOf());
+ Assert.That(graphDiagram, Is.TypeOf());
+ }
+
+ [Test]
+ public void GetDiagramType_ShouldThrowForUnsupportedType()
+ {
+ // Arrange & Act
+ Assert.Throws(()=>
+ MermaidDiagram.GetDiagramType((DiagramType)999));
+ }
+
+ [Test]
+ [TestCase(DiagramType.Class)]
+ [TestCase(DiagramType.Graph)]
+ public void Header_ShouldInitializeGraphWithTitle(DiagramType type)
+ {
+ var diagram = (MermaidDiagram)MermaidDiagram.GetDiagramType(type);
+
+ // Arrange
+ const string title = "Test Diagram";
+
+ // Act
+ diagram.Header(title);
+
+ // Assert
+ Assert.That(diagram.ToString(), Does.Contain($"title: {title}"));
+ }
+}
+
diff --git a/mermaid-graphTests/MermaidGraphTests.csproj b/mermaid-graphTests/MermaidGraphTests.csproj
index 4d3de3d..e11d4ec 100644
--- a/mermaid-graphTests/MermaidGraphTests.csproj
+++ b/mermaid-graphTests/MermaidGraphTests.csproj
@@ -4,8 +4,19 @@
net9.0
MermaidGraph.Tests
latest
- enable
+ disable
enable
+ True
+
+
+
+ 8
+ True
+
+
+
+ 8
+ True
@@ -17,17 +28,17 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
-
+
+
-
-
+
+
-
+
all
runtime; build; native; contentfiles; analyzers; buildtransitive
-
+
diff --git a/version.json b/version.json
new file mode 100644
index 0000000..255fb87
--- /dev/null
+++ b/version.json
@@ -0,0 +1,13 @@
+{
+ "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/main/src/NerdBank.GitVersioning/version.schema.json",
+ "version": "1.1",
+ "publicReleaseRefSpec": [
+ "^refs/heads/master$",
+ "^refs/heads/v\\d+(?:\\.\\d+)?$"
+ ],
+ "cloudBuild": {
+ "buildNumber": {
+ "enabled": true
+ }
+ }
+}
\ No newline at end of file