Skip to content

Commit 40785ac

Browse files
committed
feat: add graph initialization and refactor graph generation methods in DependencyGraphGenerator
1 parent 2463188 commit 40785ac

2 files changed

Lines changed: 16 additions & 22 deletions

File tree

CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,18 @@ public void enclose_string_in_quotes_returns_quoted_null_for_null_input()
111111
Assert.Equal(string.Empty, result);
112112
}
113113

114+
// Setting graph properties after initialization
115+
[Fact]
116+
public void initialize_graph_should_set_correct_graph_properties()
117+
{
118+
DotGraph graph;
119+
120+
DependencyGraphGenerator.InitializeGraph(out graph);
121+
122+
Assert.Equal("DependencyGraph", graph.Label.Value);
123+
Assert.Equal("DependencyGraph", graph.Identifier.Value);
124+
}
125+
114126

115127
}
116128
}

CodeLineCounter/Services/DependencyGraphGenerator.cs

Lines changed: 4 additions & 22 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, EncloseNotEmptyOrNullStringInQuotes(vertex));
39+
DotNode node = CreateNode(vertexInfo, 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(EncloseNotEmptyOrNullStringInQuotes(sourceLabel));
64-
var dotIdentifierTo = new DotIdentifier(EncloseNotEmptyOrNullStringInQuotes(targetLabel));
63+
var dotIdentifierFrom = new DotIdentifier(sourceLabel);
64+
var dotIdentifierTo = new DotIdentifier(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[RemoveQuotes(vertex) ?? vertex];
85+
var info = vertexInfo[vertex];
8686
var node = new DotNode();
8787
node.WithIdentifier(vertex, true);
8888
node.Label = $"{vertex}" + Environment.NewLine + $"\nIn: {info.incoming}, Out: {info.outgoing}";
@@ -183,23 +183,5 @@ 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-
204186
}
205187
}

0 commit comments

Comments
 (0)