Skip to content

Commit

Permalink
Change .Verify to fail when no issues are reported (#9250)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim-Pohlmann committed May 14, 2024
1 parent e4055d3 commit 2081bf4
Show file tree
Hide file tree
Showing 126 changed files with 3,050 additions and 2,928 deletions.
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();

#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();

[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();

[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

0 comments on commit 2081bf4

Please sign in to comment.