diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs index 0ef20264..059a0e4c 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs @@ -576,11 +576,9 @@ public void AssertIsAssignableFrom_TestAnalyzer(string assertion) => [DataRow( /* oldAssertion: */ "Assert.IsAssignableFrom(typeof(string), actual);", /* newAssertion: */ "actual.Should().BeAssignableTo();")] -#if TO_BE_FIXED [DataRow( /* oldAssertion: */ "Assert.IsAssignableFrom(actual);", /* newAssertion: */ "actual.Should().BeAssignableTo();")] -#endif [Implemented] public void AssertIsAssignableFrom_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("string actual, Type expected", oldAssertion, newAssertion); @@ -600,11 +598,9 @@ public void AssertIsNotAssignableFrom_TestAnalyzer(string assertion) => [DataRow( /* oldAssertion: */ "Assert.IsNotAssignableFrom(typeof(string), actual);", /* newAssertion: */ "actual.Should().NotBeAssignableTo();")] -#if TO_BE_FIXED [DataRow( /* oldAssertion: */ "Assert.IsNotAssignableFrom(actual);", /* newAssertion: */ "actual.Should().NotBeAssignableTo();")] -#endif [Implemented] public void AssertIsNotAssignableFrom_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("string actual, Type expected", oldAssertion, newAssertion); @@ -624,11 +620,9 @@ public void AssertIsType_TestAnalyzer(string assertion) => [DataRow( /* oldAssertion: */ "Assert.IsType(typeof(string), actual);", /* newAssertion: */ "actual.Should().BeOfType();")] -#if TO_BE_FIXED [DataRow( /* oldAssertion: */ "Assert.IsType(actual);", /* newAssertion: */ "actual.Should().BeOfType();")] -#endif [Implemented] public void AssertIsType_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("string actual, Type expected", oldAssertion, newAssertion); @@ -648,11 +642,9 @@ public void AssertIsNotType_TestAnalyzer(string assertion) => [DataRow( /* oldAssertion: */ "Assert.IsNotType(typeof(string), actual);", /* newAssertion: */ "actual.Should().NotBeOfType();")] -#if TO_BE_FIXED [DataRow( /* oldAssertion: */ "Assert.IsNotType(actual);", /* newAssertion: */ "actual.Should().NotBeOfType();")] -#endif [Implemented] public void AssertIsNotType_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("string actual, Type expected", oldAssertion, newAssertion); diff --git a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsAssignableFrom.cs b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsAssignableFrom.cs index c136e28c..524beb41 100644 --- a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsAssignableFrom.cs +++ b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsAssignableFrom.cs @@ -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"); diff --git a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotAssignableFrom.cs b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotAssignableFrom.cs index 425fbeff..28c64f35 100644 --- a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotAssignableFrom.cs +++ b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotAssignableFrom.cs @@ -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"); diff --git a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotType.cs b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotType.cs index 9f53f592..177a2571 100644 --- a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotType.cs +++ b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsNotType.cs @@ -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"); diff --git a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsType.cs b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsType.cs index 6d50c364..90a5805d 100644 --- a/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsType.cs +++ b/src/FluentAssertions.Analyzers/Tips/Xunit/AssertIsType.cs @@ -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"); diff --git a/src/FluentAssertions.Analyzers/Utilities/TestingLibraryCodeFixBase.cs b/src/FluentAssertions.Analyzers/Utilities/TestingLibraryCodeFixBase.cs index eb2fec11..d0a8047b 100644 --- a/src/FluentAssertions.Analyzers/Utilities/TestingLibraryCodeFixBase.cs +++ b/src/FluentAssertions.Analyzers/Utilities/TestingLibraryCodeFixBase.cs @@ -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)