Skip to content

Commit

Permalink
Create reproducer for #9288 (#9297)
Browse files Browse the repository at this point in the history
  • Loading branch information
costin-zaharia-sonarsource committed May 22, 2024
1 parent dda339e commit 2e96863
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class MetricsAnalyzerTest
private const string RazorFileName = "Razor.razor";
private const string CsHtmlFileName = "Razor.cshtml";
private const string CSharp12FileName = "Metrics.CSharp12.cs";
private const string ImportsRazorFileName = "_Imports.razor";

public TestContext TestContext { get; set; }

Expand Down Expand Up @@ -79,6 +80,27 @@ public void VerifyMetrics_Razor() =>
metrics.StatementCount.Should().Be(6);
});

[TestMethod]
public void VerifyMetrics_Razor_Usings() =>
CreateBuilder(false, ImportsRazorFileName)
.VerifyUtilityAnalyzer<MetricsInfo>(messages =>
{
var orderedMessages = messages.OrderBy(x => x.FilePath, StringComparer.InvariantCulture).ToArray();
orderedMessages.Select(x => Path.GetFileName(x.FilePath)).Should().BeEquivalentTo(ImportsRazorFileName);

var metrics = messages.Single(x => x.FilePath.EndsWith(ImportsRazorFileName));

metrics.ClassCount.Should().Be(0);
metrics.CodeLine.Should().BeEquivalentTo(new[] { 1, 2, 4 }); // FN: this file has only 3 lines. See: https://github.com/SonarSource/sonar-dotnet/issues/9288
metrics.CognitiveComplexity.Should().Be(0);
metrics.Complexity.Should().Be(1);
metrics.ExecutableLines.Should().BeEquivalentTo(Array.Empty<int>());
metrics.FunctionCount.Should().Be(0);
metrics.NoSonarComment.Should().BeEmpty();
metrics.NonBlankComment.Should().BeEquivalentTo(Array.Empty<int>());
metrics.StatementCount.Should().Be(0);
});

[TestMethod]
public void VerifyMetrics_CsHtml() =>
CreateBuilder(false, CsHtmlFileName)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@using System
@using System.Collections.Generic

0 comments on commit 2e96863

Please sign in to comment.