Skip to content

Commit 2463188

Browse files
authored
Merge pull request #26 from magic5644:feat_Update_DependencyGraphGenerator_and_add_async_in_write
Add EncloseNotEmptyOrNullStringInQuotes method and update DependencyGraphGenerator to use async in dot file generation
2 parents a24cc6d + 272b37b commit 2463188

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,34 @@ public void create_node_sets_correct_fillcolor_and_style_incoming_lower()
8383
Assert.Equal(DotNodeStyle.Filled.FlagsToString(), node.Style.Value);
8484
}
8585

86+
// Returns empty quoted string '""' for non-empty input string
87+
[Fact]
88+
public void enclose_string_in_quotes_returns_empty_quoted_string_for_nonempty_input()
89+
{
90+
// Arrange
91+
var input = "test string";
92+
93+
// Act
94+
var result = DependencyGraphGenerator.EncloseNotEmptyOrNullStringInQuotes(input);
95+
96+
// Assert
97+
Assert.Equal("\"test string\"", result);
98+
}
99+
100+
// Returns quoted string with null value for null input
101+
[Fact]
102+
public void enclose_string_in_quotes_returns_quoted_null_for_null_input()
103+
{
104+
// Arrange
105+
string? input = null;
106+
107+
// Act
108+
var result = DependencyGraphGenerator.EncloseNotEmptyOrNullStringInQuotes(input);
109+
110+
// Assert
111+
Assert.Equal(string.Empty, result);
112+
}
113+
86114

87115
}
88116
}

CodeLineCounter/Services/DependencyGraphGenerator.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public static DotGraph GenerateGraphOnly(List<DependencyRelation> dependencies,
3636

3737
foreach (var vertex in nsGroup.Value)
3838
{
39-
DotNode node = CreateNode(vertexInfo, vertex);
39+
DotNode node = CreateNode(vertexInfo, EncloseNotEmptyOrNullStringInQuotes(vertex));
4040

4141
cluster.Elements.Add(node);
4242
}
@@ -60,8 +60,8 @@ private static DotEdge CreateEdge(DependencyRelation dep)
6060
var targetLabel = dep.TargetClass;
6161

6262
var edge = new DotEdge();
63-
var dotIdentifierFrom = new DotIdentifier(sourceLabel);
64-
var dotIdentifierTo = new DotIdentifier(targetLabel);
63+
var dotIdentifierFrom = new DotIdentifier(EncloseNotEmptyOrNullStringInQuotes(sourceLabel));
64+
var dotIdentifierTo = new DotIdentifier(EncloseNotEmptyOrNullStringInQuotes(targetLabel));
6565

6666
edge.From = dotIdentifierFrom;
6767
edge.To = dotIdentifierTo;
@@ -82,7 +82,7 @@ private static DotSubgraph CreateCluster(KeyValuePair<string, List<string>> nsGr
8282

8383
public static DotNode CreateNode(Dictionary<string, (int incoming, int outgoing)> vertexInfo, string vertex)
8484
{
85-
var info = vertexInfo[vertex];
85+
var info = vertexInfo[RemoveQuotes(vertex) ?? vertex];
8686
var node = new DotNode();
8787
node.WithIdentifier(vertex, true);
8888
node.Label = $"{vertex}" + Environment.NewLine + $"\nIn: {info.incoming}, Out: {info.outgoing}";
@@ -183,5 +183,23 @@ private static List<DependencyRelation> FilterNamespaceFromDependencies(List<Dep
183183
return filteredDependencies;
184184
}
185185

186+
public static string EncloseNotEmptyOrNullStringInQuotes(string? str)
187+
{
188+
if (!string.IsNullOrEmpty(str))
189+
{
190+
return $"\"{str}\"";
191+
}
192+
else
193+
{
194+
return string.Empty;
195+
}
196+
197+
}
198+
199+
public static string RemoveQuotes(string str)
200+
{
201+
return str.Replace("\"", "");
202+
}
203+
186204
}
187205
}

0 commit comments

Comments
 (0)