diff --git a/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs b/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs index c55fcd29..75892b19 100644 --- a/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs +++ b/src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs @@ -648,6 +648,30 @@ public void AssertIsType_TestCodeFix(string oldAssertion, string newAssertion) public void AssertIsNotType_TestCodeFix(string oldAssertion, string newAssertion) => VerifyCSharpFix("string actual, Type expected", oldAssertion, newAssertion); + [DataTestMethod] + [DataRow("Assert.InRange(actual, low, high);")] + [Implemented] + public void AssertInRange_TestAnalyzer(string assertion) + { + VerifyCSharpDiagnostic("double actual, double low, double high", assertion); + VerifyCSharpDiagnostic("float actual, float low, float high", assertion); + VerifyCSharpDiagnostic("int actual, int low, int high", assertion); + VerifyCSharpDiagnostic("long actual, long low, long high", assertion); + } + + [DataTestMethod] + [DataRow( + /* oldAssertion: */ "Assert.InRange(actual, low, high);", + /* newAssertion: */ "actual.Should().BeInRange(low, high);")] + [Implemented] + public void AssertInRange_TestCodeFix(string oldAssertion, string newAssertion) + { + VerifyCSharpFix("double actual, double low, double high", oldAssertion, newAssertion); + VerifyCSharpFix("float actual, float low, float high", oldAssertion, newAssertion); + VerifyCSharpFix("int actual, int low, int high", oldAssertion, newAssertion); + VerifyCSharpFix("long actual, long low, long high", oldAssertion, newAssertion); + } + private void VerifyCSharpDiagnostic(string methodArguments, string assertion) { var source = GenerateCode.XunitAssertion(methodArguments, assertion); diff --git a/src/FluentAssertions.Analyzers/Tips/XunitCodeFixProvider.cs b/src/FluentAssertions.Analyzers/Tips/XunitCodeFixProvider.cs index 2b488458..67efe7b0 100644 --- a/src/FluentAssertions.Analyzers/Tips/XunitCodeFixProvider.cs +++ b/src/FluentAssertions.Analyzers/Tips/XunitCodeFixProvider.cs @@ -131,6 +131,10 @@ protected override CreateChangedDocument TryComputeFix(IInvocationOperation invo return DocumentEditorUtils.RenameMethodToSubjectShouldGenericAssertion(invocation, ImmutableArray.Create(typeOf.TypeOperand), context, "NotBeOfType", subjectIndex: 1, argumentsToRemove: [0]); } + case "InRange" when ArgumentsCount(invocation, 3): // Assert.InRange(T actual, T low, T high) + return DocumentEditorUtils.RenameMethodToSubjectShouldAssertion(invocation, context, "BeInRange", subjectIndex: 0, argumentsToRemove: []); + case "NotInRange" when ArgumentsCount(invocation, 3): // Assert.NotInRange(T actual, T low, T high) + return DocumentEditorUtils.RenameMethodToSubjectShouldAssertion(invocation, context, "NotBeInRange", subjectIndex: 0, argumentsToRemove: []); } return null; }