Skip to content

Commit d1e5142

Browse files
authored
feat: add xunit Assert.InRange (#281)
1 parent a34ac27 commit d1e5142

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/FluentAssertions.Analyzers.Tests/Tips/XunitTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,30 @@ public void AssertIsNotType_TestAnalyzer(string assertion) =>
648648
public void AssertIsNotType_TestCodeFix(string oldAssertion, string newAssertion)
649649
=> VerifyCSharpFix("string actual, Type expected", oldAssertion, newAssertion);
650650

651+
[DataTestMethod]
652+
[DataRow("Assert.InRange(actual, low, high);")]
653+
[Implemented]
654+
public void AssertInRange_TestAnalyzer(string assertion)
655+
{
656+
VerifyCSharpDiagnostic("double actual, double low, double high", assertion);
657+
VerifyCSharpDiagnostic("float actual, float low, float high", assertion);
658+
VerifyCSharpDiagnostic("int actual, int low, int high", assertion);
659+
VerifyCSharpDiagnostic("long actual, long low, long high", assertion);
660+
}
661+
662+
[DataTestMethod]
663+
[DataRow(
664+
/* oldAssertion: */ "Assert.InRange(actual, low, high);",
665+
/* newAssertion: */ "actual.Should().BeInRange(low, high);")]
666+
[Implemented]
667+
public void AssertInRange_TestCodeFix(string oldAssertion, string newAssertion)
668+
{
669+
VerifyCSharpFix("double actual, double low, double high", oldAssertion, newAssertion);
670+
VerifyCSharpFix("float actual, float low, float high", oldAssertion, newAssertion);
671+
VerifyCSharpFix("int actual, int low, int high", oldAssertion, newAssertion);
672+
VerifyCSharpFix("long actual, long low, long high", oldAssertion, newAssertion);
673+
}
674+
651675
private void VerifyCSharpDiagnostic(string methodArguments, string assertion)
652676
{
653677
var source = GenerateCode.XunitAssertion(methodArguments, assertion);

src/FluentAssertions.Analyzers/Tips/XunitCodeFixProvider.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,10 @@ protected override CreateChangedDocument TryComputeFix(IInvocationOperation invo
131131

132132
return DocumentEditorUtils.RenameMethodToSubjectShouldGenericAssertion(invocation, ImmutableArray.Create(typeOf.TypeOperand), context, "NotBeOfType", subjectIndex: 1, argumentsToRemove: [0]);
133133
}
134+
case "InRange" when ArgumentsCount(invocation, 3): // Assert.InRange<T>(T actual, T low, T high)
135+
return DocumentEditorUtils.RenameMethodToSubjectShouldAssertion(invocation, context, "BeInRange", subjectIndex: 0, argumentsToRemove: []);
136+
case "NotInRange" when ArgumentsCount(invocation, 3): // Assert.NotInRange<T>(T actual, T low, T high)
137+
return DocumentEditorUtils.RenameMethodToSubjectShouldAssertion(invocation, context, "NotBeInRange", subjectIndex: 0, argumentsToRemove: []);
134138
}
135139
return null;
136140
}

0 commit comments

Comments
 (0)