Skip to content

Commit

Permalink
Fix generic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jairbubbles committed Dec 5, 2023
1 parent 4a3c6ce commit 405dfd7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 15 deletions.
8 changes: 0 additions & 8 deletions src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -576,11 +576,9 @@ public void AssertIsAssignableFrom_TestAnalyzer(string assertion) =>
[DataRow(
/* oldAssertion: */ "Assert.IsAssignableFrom(typeof(string), actual);",
/* newAssertion: */ "actual.Should().BeAssignableTo<string>();")]
#if TO_BE_FIXED
[DataRow(
/* oldAssertion: */ "Assert.IsAssignableFrom<string>(actual);",
/* newAssertion: */ "actual.Should().BeAssignableTo<string>();")]
#endif
[Implemented]
public void AssertIsAssignableFrom_TestCodeFix(string oldAssertion, string newAssertion)
=> VerifyCSharpFix<AssertIsAssignableFromCodeFix, AssertIsAssignableFromAnalyzer>("string actual, Type expected", oldAssertion, newAssertion);
Expand All @@ -600,11 +598,9 @@ public void AssertIsNotAssignableFrom_TestAnalyzer(string assertion) =>
[DataRow(
/* oldAssertion: */ "Assert.IsNotAssignableFrom(typeof(string), actual);",
/* newAssertion: */ "actual.Should().NotBeAssignableTo<string>();")]
#if TO_BE_FIXED
[DataRow(
/* oldAssertion: */ "Assert.IsNotAssignableFrom<string>(actual);",
/* newAssertion: */ "actual.Should().NotBeAssignableTo<string>();")]
#endif
[Implemented]
public void AssertIsNotAssignableFrom_TestCodeFix(string oldAssertion, string newAssertion)
=> VerifyCSharpFix<AssertIsNotAssignableFromCodeFix, AssertIsNotAssignableFromAnalyzer>("string actual, Type expected", oldAssertion, newAssertion);
Expand All @@ -624,11 +620,9 @@ public void AssertIsType_TestAnalyzer(string assertion) =>
[DataRow(
/* oldAssertion: */ "Assert.IsType(typeof(string), actual);",
/* newAssertion: */ "actual.Should().BeOfType<string>();")]
#if TO_BE_FIXED
[DataRow(
/* oldAssertion: */ "Assert.IsType<string>(actual);",
/* newAssertion: */ "actual.Should().BeOfType<string>();")]
#endif
[Implemented]
public void AssertIsType_TestCodeFix(string oldAssertion, string newAssertion)
=> VerifyCSharpFix<AssertIsTypeCodeFix, AssertIsTypeAnalyzer>("string actual, Type expected", oldAssertion, newAssertion);
Expand All @@ -648,11 +642,9 @@ public void AssertIsNotType_TestAnalyzer(string assertion) =>
[DataRow(
/* oldAssertion: */ "Assert.IsNotType(typeof(string), actual);",
/* newAssertion: */ "actual.Should().NotBeOfType<string>();")]
#if TO_BE_FIXED
[DataRow(
/* oldAssertion: */ "Assert.IsNotType<string>(actual);",
/* newAssertion: */ "actual.Should().NotBeOfType<string>();")]
#endif
[Implemented]
public void AssertIsNotType_TestCodeFix(string oldAssertion, string newAssertion)
=> VerifyCSharpFix<AssertIsNotTypeCodeFix, AssertIsNotTypeAnalyzer>("string actual, Type expected", oldAssertion, newAssertion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override ExpressionSyntax GetNewExpression(
switch (properties.VisitorName)
{
case nameof(AssertIsAssignableFromAnalyzer.AssertIsAssignableFromGenericTypeSyntaxVisitor):
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsAssignableFrom", "BeAssignableTo");
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsAssignableFrom", "BeAssignableTo", argumentIndex: 0);
case nameof(AssertIsAssignableFromAnalyzer.AssertIsAssignableFromTypeSyntaxVisitor):
var newExpression = RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsAssignableFrom", "BeAssignableTo");
return ReplaceTypeOfArgumentWithGenericTypeIfExists(newExpression, "BeAssignableTo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override ExpressionSyntax GetNewExpression(
switch (properties.VisitorName)
{
case nameof(AssertIsNotAssignableFromAnalyzer.AssertIsNotAssignableFromGenericTypeSyntaxVisitor):
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsNotAssignableFrom", "NotBeAssignableTo");
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsNotAssignableFrom", "NotBeAssignableTo", argumentIndex: 0);
case nameof(AssertIsNotAssignableFromAnalyzer.AssertIsNotAssignableFromTypeSyntaxVisitor):
var newExpression = RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsNotAssignableFrom", "NotBeAssignableTo");
return ReplaceTypeOfArgumentWithGenericTypeIfExists(newExpression, "NotBeAssignableTo");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override ExpressionSyntax GetNewExpression(
switch (properties.VisitorName)
{
case nameof(AssertIsNotTypeAnalyzer.AssertIsNotTypeGenericTypeSyntaxVisitor):
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsNotType", "NotBeOfType");
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsNotType", "NotBeOfType", argumentIndex: 0);
case nameof(AssertIsNotTypeAnalyzer.AssertIsNotTypeTypeSyntaxVisitor):
var newExpression = RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsNotType", "NotBeOfType");
return ReplaceTypeOfArgumentWithGenericTypeIfExists(newExpression, "NotBeOfType");
Expand Down
2 changes: 1 addition & 1 deletion src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected override ExpressionSyntax GetNewExpression(
switch (properties.VisitorName)
{
case nameof(AssertIsTypeAnalyzer.AssertIsTypeGenericTypeSyntaxVisitor):
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsType", "BeOfType");
return RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsType", "BeOfType", argumentIndex: 0);
case nameof(AssertIsTypeAnalyzer.AssertIsTypeTypeSyntaxVisitor):
var newExpression = RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(expression, "IsType", "BeOfType");
return ReplaceTypeOfArgumentWithGenericTypeIfExists(newExpression, "BeOfType");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ protected ExpressionSyntax RenameMethodAndReplaceWithSubjectShould(ExpressionSyn
return ReplaceIdentifier(newExpression, AssertClassName, Expressions.SubjectShould(rename.Argument.Expression));
}

protected ExpressionSyntax RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(ExpressionSyntax expression, string oldName, string newName)
protected ExpressionSyntax RenameMethodAndReorderActualExpectedAndReplaceWithSubjectShould(ExpressionSyntax expression, string oldName, string newName, int argumentIndex = 1)
{
var rename = NodeReplacement.RenameAndExtractArguments(oldName, newName);
var newExpression = GetNewExpression(expression, rename);

var actual = rename.Arguments[1];
var actual = rename.Arguments[argumentIndex];

newExpression = ReplaceIdentifier(newExpression, AssertClassName, Expressions.SubjectShould(actual.Expression));

return GetNewExpression(newExpression, NodeReplacement.WithArguments(newName, rename.Arguments.RemoveAt(1)));
return GetNewExpression(newExpression, NodeReplacement.WithArguments(newName, rename.Arguments.RemoveAt(argumentIndex)));
}

protected ExpressionSyntax ReplaceTypeOfArgumentWithGenericTypeIfExists(ExpressionSyntax expression, string method)
Expand Down

0 comments on commit 405dfd7

Please sign in to comment.