Skip to content

Commit

Permalink
Update UTs
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann committed May 8, 2024
1 parent 4e569c4 commit fd4d546
Show file tree
Hide file tree
Showing 129 changed files with 2,293 additions and 1,951 deletions.
6 changes: 6 additions & 0 deletions analyzers/SonarAnalyzer.lutconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<LUTConfig Version="1.0">
<Repository>..\</Repository>
<ParallelBuilds>true</ParallelBuilds>
<ParallelTestRuns>true</ParallelTestRuns>
<TestCaseTimeout>180000</TestCaseTimeout>
</LUTConfig>
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class AbstractTypesShouldNotHaveConstructorsTest
public void AbstractTypesShouldNotHaveConstructors_CSharp12() =>
builder.AddPaths("AbstractTypesShouldNotHaveConstructors.CSharp12.cs")
.WithOptions(ParseOptionsHelper.FromCSharp12)
.Verify();
.VerifyNoIssues(); // primary constructors are compliant

#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,36 +64,32 @@ public class ApiControllersShouldNotDeriveDirectlyFromControllerTest
[DataRow("""TempData["foo"]""")]
[DataTestMethod]
public void ApiControllersShouldNotDeriveDirectlyFromController_DoesNotRaiseWithViewFunctionality(string invocation) =>
builder
.AddSnippet($$"""
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
builder.AddSnippet($$"""
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

[ApiController]
public class Invocations : Controller // Compliant
{
object model = null;
public object Foo() => {{invocation}};
}
""")
.Verify();
[ApiController]
public class Invocations : Controller // Compliant
{
object model = null;
public object Foo() => {{invocation}};
}
""").VerifyNoIssues();

[DataRow("""OnActionExecuted(default(ActionExecutedContext))""")]
[DataRow("""OnActionExecuting(default(ActionExecutingContext))""")]
[DataTestMethod]
public void ApiControllersShouldNotDeriveDirectlyFromController_DoesNotRaiseWithVoidInvocations(string assignment) =>
builder
.AddSnippet($$"""
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
builder.AddSnippet($$"""
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;

[ApiController]
public class VoidInvocations : Controller // Compliant
{
public void Foo() => {{assignment}};
}
""")
.Verify();
[ApiController]
public class VoidInvocations : Controller // Compliant
{
public void Foo() => {{assignment}};
}
""").VerifyNoIssues();

[DataRow("public Test() => foo = View();", DisplayName = "Constructor")]
[DataRow("~Test() => foo = View();", DisplayName = "Destructor")]
Expand All @@ -102,18 +98,16 @@ public class VoidInvocations : Controller // Compliant
[DataRow("object this[int index] => View();", DisplayName = "Indexer")]
[DataTestMethod]
public void ApiControllersShouldNotDeriveDirectlyFromController_DoesNotRaiseInDifferentConstructs(string code) =>
builder
.AddSnippet($$"""
using Microsoft.AspNetCore.Mvc;
builder.AddSnippet($$"""
using Microsoft.AspNetCore.Mvc;

[ApiController]
public class Test : Controller // Compliant
{
object foo;
{{code}}
}
""")
.Verify();
[ApiController]
public class Test : Controller // Compliant
{
object foo;
{{code}}
}
""").VerifyNoIssues();

[TestMethod]
public void ApiControllersShouldNotDeriveDirectlyFromController_CodeFix() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public class ControllerWithApiAttributeAtTheAssemblyLevel : ControllerBase
return "Hello!";
}
}
""").Verify();
""").VerifyNoIssues();

[TestMethod]
public void CallModelStateIsValid_FluentValidation_CS() =>
Expand Down Expand Up @@ -134,7 +134,7 @@ public class NonValidatingMovieController : ControllerBase
return "Hello!";
}
}
""").AddReferences(NuGetMetadataReference.FluentValidation()).Verify();
""").AddReferences(NuGetMetadataReference.FluentValidation()).VerifyNoIssues();

[DataTestMethod]
[DataRow("!ModelState.IsValid")]
Expand Down Expand Up @@ -173,7 +173,7 @@ public class MovieController : ControllerBase
return Ok();
}
}
""").WithOptions(ParseOptionsHelper.FromCSharp10).Verify();
""").WithOptions(ParseOptionsHelper.FromCSharp10).VerifyNoIssues();
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public class BasicsController : Controller {{(compliant ? string.Empty : " // No
builderVB
.AddPaths("RouteTemplateShouldNotStartWithSlash.AspNetCore.vb")
.AddReferences(AspNetCoreReferences)
.Verify();
.VerifyNoIssues(); // FN

[TestMethod]
public void RouteTemplateShouldNotStartWithSlash_CSharp12() =>
Expand Down Expand Up @@ -194,7 +194,7 @@ public class BasicsController : Controller {{(compliant ? string.Empty : " // No
builderVB
.AddPaths("RouteTemplateShouldNotStartWithSlash.AspNet4x.vb")
.AddReferences(AspNet4xReferences(aspNetMvcVersion))
.Verify();
.VerifyNoIssues(); // FN VB is not supported

[DataRow("/Index2", false)]
[DataRow(@"\Index2", true)]
Expand Down Expand Up @@ -231,8 +231,9 @@ public class BasicsController : Controller {{(compliant ? string.Empty : " // No
[DataRow("""[System.Web.Mvc.RouteAttribute(@"/[action]")]""", false)]
[DataRow("""[method:Route(@"/[action]")]""", false)]
[DataTestMethod]
public void RouteTemplateShouldNotStartWithSlash_WithAttributeSyntaxVariations(string attribute, bool compliant) =>
builderCS.AddReferences(AspNet4xReferences("5.2.7"))
public void RouteTemplateShouldNotStartWithSlash_WithAttributeSyntaxVariations(string attribute, bool compliant)
{
var builder = builderCS.AddReferences(AspNet4xReferences("5.2.7"))
.WithOptions(ParseOptionsHelper.FromCSharp11)
.AddSnippet($$"""
using System.Web.Mvc;
Expand All @@ -243,8 +244,16 @@ public class BasicsController : Controller {{(compliant ? string.Empty : " // No
{{attribute}} {{(compliant ? string.Empty : " // Secondary")}}
public ActionResult SomeAction() => View();
}
""")
.Verify();
""");
if (compliant)
{
builder.VerifyNoIssues();
}
else
{
builder.Verify();
}
}

[DataRow("""(@"/[action]")""", false)]
[DataRow("""("/[action]")""", false)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,18 @@ public AssertionsShouldBeCompleteTest()
[TestMethod]
public void AssertionsShouldBeComplete_FluentAssertions_MissingParen() =>
fluentAssertions
.AddSnippet("""
using FluentAssertions;
public class Test
{
public void MissingParen()
.AddSnippet("""
using FluentAssertions;
public class Test
{
var s = "Test";
s.Should(; // Error [CS1026]
public void MissingParen()
{
var s = "Test";
s.Should(; // Error [CS1026]
}
}
}
""")
.Verify();
""")
.Verify();

[TestMethod]
public void AssertionsShouldBeComplete_FluentAssertions_CSharp8() =>
Expand Down
Loading

0 comments on commit fd4d546

Please sign in to comment.