Skip to content

Commit

Permalink
Fix UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
CristianAmbrosini committed May 2, 2024
1 parent 60eb092 commit 723b37e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

<p>The solution to all problems is: @(RaiseHere(21))</p>
@* ^^^^^^^^^ *@
@* ^^ Secondary@-1 *@

@code
{
private int magicNumber = RaiseHere(42);
// ^^^^^^^^^
// ^^ Secondary@-1
private static int RaiseHere(int nb)
{
return nb;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<p>Explicit expression: @(RaiseHere())</p> @* Noncompliant *@
@* ^^^^^^^^^ *@

<p>Implicit expression: @RaiseHere()</p> @* Noncompliant *@
@* ^^^^^^^^^ *@

<p>Multi-statement block: @{ var result = RaiseHere(); }</p>
@* ^^^^^^^^^ *@

<p>Control structures: @if(RaiseHere() == 42) { <text>42</text> }</p>
@* ^^^^^^^^^ *@

<p>Loops: @for(var i = 0; i < RaiseHere(); i++) { <text>@i</text> }</p>
@* ^^^^^^^^^ *@

<p>Code blocks: @{ RaiseHere(); }</p>
@* ^^^^^^^^^ *@

<p>Lambda expression: @((Func<int>)(() => RaiseHere()))()</p> @* Noncompliant *@
@* ^^^^^^^^^ *@

<p>Nested multi-statement block: @{ var result2 = RaiseHere(); var result3 = RaiseHere(); }</p>
@* ^^^^^^^^^ *@
@* ^^^^^^^^^@-1 *@

<p>Nested control structures: @if(RaiseHere() == 42) { <text>@(RaiseHere() + 1)</text> }</p>
@* ^^^^^^^^^ *@
@* ^^^^^^^^^@-1 *@

@code
{
private static int RaiseHere() { return 42; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,23 @@ public class Sample
[DataRow("Dummy.SecondaryLocation.cshtml")]
public void Verify_RazorWithAdditionalLocation(string path) =>
DummyWithLocation.AddPaths(path)
.WithOptions(ParseOptionsHelper.BeforeCSharp10)
.WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product))
.Verify();

#if NET

[DataTestMethod]
[DataRow("Dummy.SecondaryLocation_CSharp10.razor")]
[DataRow("Dummy.SecondaryLocation.cshtml")]
public void Verify_RazorWithAdditionalLocation_CSharp10(string path) =>
DummyWithLocation.AddPaths(path)
.WithOptions(ParseOptionsHelper.FromCSharp10)
.WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product))
.Verify();

#endif

[TestMethod]
[DataRow("Dummy.razor")]
[DataRow("Dummy.cshtml")]
Expand All @@ -180,6 +194,20 @@ public class Sample
.WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product))
.Verify();

#if NET

[TestMethod]
[DataRow("DummyExpressions_CSharp10.razor")]
[DataRow("DummyExpressions.cshtml")]
public void Verify_RazorExpressions_Locations_CSharp10(string path) =>
DummyWithLocation
.AddPaths(path)
.WithOptions(ParseOptionsHelper.FromCSharp10)
.WithAdditionalFilePath(AnalysisScaffolding.CreateSonarProjectConfig(TestContext, ProjectType.Product))
.Verify();

#endif

[DataTestMethod]
[DataRow("Dummy.razor")]
[DataRow("Dummy.cshtml")]
Expand Down

0 comments on commit 723b37e

Please sign in to comment.