Skip to content

Commit 2e96863

Browse files
Create reproducer for #9288 (#9297)
1 parent dda339e commit 2e96863

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

analyzers/tests/SonarAnalyzer.Test/Rules/Utilities/MetricsAnalyzerTest.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class MetricsAnalyzerTest
3434
private const string RazorFileName = "Razor.razor";
3535
private const string CsHtmlFileName = "Razor.cshtml";
3636
private const string CSharp12FileName = "Metrics.CSharp12.cs";
37+
private const string ImportsRazorFileName = "_Imports.razor";
3738

3839
public TestContext TestContext { get; set; }
3940

@@ -79,6 +80,27 @@ public void VerifyMetrics_Razor() =>
7980
metrics.StatementCount.Should().Be(6);
8081
});
8182

83+
[TestMethod]
84+
public void VerifyMetrics_Razor_Usings() =>
85+
CreateBuilder(false, ImportsRazorFileName)
86+
.VerifyUtilityAnalyzer<MetricsInfo>(messages =>
87+
{
88+
var orderedMessages = messages.OrderBy(x => x.FilePath, StringComparer.InvariantCulture).ToArray();
89+
orderedMessages.Select(x => Path.GetFileName(x.FilePath)).Should().BeEquivalentTo(ImportsRazorFileName);
90+
91+
var metrics = messages.Single(x => x.FilePath.EndsWith(ImportsRazorFileName));
92+
93+
metrics.ClassCount.Should().Be(0);
94+
metrics.CodeLine.Should().BeEquivalentTo(new[] { 1, 2, 4 }); // FN: this file has only 3 lines. See: https://github.com/SonarSource/sonar-dotnet/issues/9288
95+
metrics.CognitiveComplexity.Should().Be(0);
96+
metrics.Complexity.Should().Be(1);
97+
metrics.ExecutableLines.Should().BeEquivalentTo(Array.Empty<int>());
98+
metrics.FunctionCount.Should().Be(0);
99+
metrics.NoSonarComment.Should().BeEmpty();
100+
metrics.NonBlankComment.Should().BeEquivalentTo(Array.Empty<int>());
101+
metrics.StatementCount.Should().Be(0);
102+
});
103+
82104
[TestMethod]
83105
public void VerifyMetrics_CsHtml() =>
84106
CreateBuilder(false, CsHtmlFileName)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@using System
2+
@using System.Collections.Generic

0 commit comments

Comments
 (0)