From 272b37bed462b4fc25367f67b44c78a57f8c40d4 Mon Sep 17 00:00:00 2001 From: magic56 Date: Wed, 15 Jan 2025 13:16:50 +0100 Subject: [PATCH] feat: add EncloseNotEmptyOrNullStringInQuotes method and update DependencyGraphGenerator to use it. Add async in file generation --- .../DependencyGraphGeneratorTests.cs | 28 +++++++++++++++++++ .../Services/DependencyGraphGenerator.cs | 26 ++++++++++++++--- 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs b/CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs index b78f1bd..39287ac 100644 --- a/CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs +++ b/CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs @@ -83,6 +83,34 @@ public void create_node_sets_correct_fillcolor_and_style_incoming_lower() Assert.Equal(DotNodeStyle.Filled.FlagsToString(), node.Style.Value); } + // Returns empty quoted string '""' for non-empty input string + [Fact] + public void enclose_string_in_quotes_returns_empty_quoted_string_for_nonempty_input() + { + // Arrange + var input = "test string"; + + // Act + var result = DependencyGraphGenerator.EncloseNotEmptyOrNullStringInQuotes(input); + + // Assert + Assert.Equal("\"test string\"", result); + } + + // Returns quoted string with null value for null input + [Fact] + public void enclose_string_in_quotes_returns_quoted_null_for_null_input() + { + // Arrange + string? input = null; + + // Act + var result = DependencyGraphGenerator.EncloseNotEmptyOrNullStringInQuotes(input); + + // Assert + Assert.Equal(string.Empty, result); + } + } } diff --git a/CodeLineCounter/Services/DependencyGraphGenerator.cs b/CodeLineCounter/Services/DependencyGraphGenerator.cs index d2c56b0..57f250e 100644 --- a/CodeLineCounter/Services/DependencyGraphGenerator.cs +++ b/CodeLineCounter/Services/DependencyGraphGenerator.cs @@ -36,7 +36,7 @@ public static DotGraph GenerateGraphOnly(List dependencies, foreach (var vertex in nsGroup.Value) { - DotNode node = CreateNode(vertexInfo, vertex); + DotNode node = CreateNode(vertexInfo, EncloseNotEmptyOrNullStringInQuotes(vertex)); cluster.Elements.Add(node); } @@ -60,8 +60,8 @@ private static DotEdge CreateEdge(DependencyRelation dep) var targetLabel = dep.TargetClass; var edge = new DotEdge(); - var dotIdentifierFrom = new DotIdentifier(sourceLabel); - var dotIdentifierTo = new DotIdentifier(targetLabel); + var dotIdentifierFrom = new DotIdentifier(EncloseNotEmptyOrNullStringInQuotes(sourceLabel)); + var dotIdentifierTo = new DotIdentifier(EncloseNotEmptyOrNullStringInQuotes(targetLabel)); edge.From = dotIdentifierFrom; edge.To = dotIdentifierTo; @@ -82,7 +82,7 @@ private static DotSubgraph CreateCluster(KeyValuePair> nsGr public static DotNode CreateNode(Dictionary vertexInfo, string vertex) { - var info = vertexInfo[vertex]; + var info = vertexInfo[RemoveQuotes(vertex) ?? vertex]; var node = new DotNode(); node.WithIdentifier(vertex, true); node.Label = $"{vertex}" + Environment.NewLine + $"\nIn: {info.incoming}, Out: {info.outgoing}"; @@ -183,5 +183,23 @@ private static List FilterNamespaceFromDependencies(List