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
28 changes: 28 additions & 0 deletions CodeLineCounter.Tests/DependencyGraphGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


}
}
26 changes: 22 additions & 4 deletions CodeLineCounter/Services/DependencyGraphGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

foreach (var vertex in nsGroup.Value)
{
DotNode node = CreateNode(vertexInfo, vertex);
DotNode node = CreateNode(vertexInfo, EncloseNotEmptyOrNullStringInQuotes(vertex));

cluster.Elements.Add(node);
}
Expand All @@ -60,8 +60,8 @@
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;
Expand All @@ -82,7 +82,7 @@

public static DotNode CreateNode(Dictionary<string, (int incoming, int outgoing)> 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}";
Expand Down Expand Up @@ -156,7 +156,7 @@
await graph.CompileAsync(context);
var result = writer.GetStringBuilder().ToString();
//using sync write for reliability with async we got some issues
File.WriteAllText(outputPath, result);

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Linux .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / Windows .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)

Check warning on line 159 in CodeLineCounter/Services/DependencyGraphGenerator.cs

View workflow job for this annotation

GitHub Actions / macOS .NET 9

Await WriteAllTextAsync instead. (https://rules.sonarsource.com/csharp/RSPEC-6966)
}

private static List<DependencyRelation> FilterAssemblyFromDependencies(string? filterAssembly, List<DependencyRelation> filteredDependencies)
Expand All @@ -183,5 +183,23 @@
return filteredDependencies;
}

public static string EncloseNotEmptyOrNullStringInQuotes(string? str)
{
if (!string.IsNullOrEmpty(str))
{
return $"\"{str}\"";
}
else
{
return string.Empty;
}

}

public static string RemoveQuotes(string str)
{
return str.Replace("\"", "");
}

}
}
Loading