Skip to content

feat: add nunit Assert.That Is.AtMost & Is.AtLeast #365

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions docs/Nunit3Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ var number = 2;
// old assertion:
Assert.GreaterOrEqual(number, 1);
Assert.That(number, Is.GreaterThanOrEqualTo(1));
Assert.That(number, Is.AtLeast(1));

// new assertion:
number.Should().BeGreaterOrEqualTo(1);
Expand All @@ -447,6 +448,9 @@ Assert.GreaterOrEqual(number, 2); /* fail message: Expected: greater than or e
Assert.That(number, Is.GreaterThanOrEqualTo(2)); /* fail message: Expected: greater than or equal to 2
But was: 1
*/
Assert.That(number, Is.AtLeast(2)); /* fail message: Expected: greater than or equal to 2
But was: 1
*/

// new assertion:
number.Should().BeGreaterOrEqualTo(2); /* fail message: Expected number to be greater than or equal to 2, but found 1. */
Expand Down Expand Up @@ -492,6 +496,7 @@ var number = 1;
// old assertion:
Assert.LessOrEqual(number, 2);
Assert.That(number, Is.LessThanOrEqualTo(2));
Assert.That(number, Is.AtMost(2));

// new assertion:
number.Should().BeLessOrEqualTo(2);
Expand All @@ -509,6 +514,9 @@ Assert.LessOrEqual(number, 1); /* fail message: Expected: less than or equal t
Assert.That(number, Is.LessThanOrEqualTo(1)); /* fail message: Expected: less than or equal to 1
But was: 2
*/
Assert.That(number, Is.AtMost(1)); /* fail message: Expected: less than or equal to 1
But was: 2
*/

// new assertion:
number.Should().BeLessOrEqualTo(1); /* fail message: Expected number to be less than or equal to 1, but found 2. */
Expand Down
10 changes: 10 additions & 0 deletions docs/Nunit4Analyzer.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,7 @@ var number = 2;
// old assertion:
ClassicAssert.GreaterOrEqual(number, 1);
Assert.That(number, Is.GreaterThanOrEqualTo(1));
Assert.That(number, Is.AtLeast(1));

// new assertion:
number.Should().BeGreaterOrEqualTo(1);
Expand All @@ -482,6 +483,10 @@ Assert.That(number, Is.GreaterThanOrEqualTo(2)); /* fail message: Assert.That(
Expected: greater than or equal to 2
But was: 1
*/
Assert.That(number, Is.AtLeast(2)); /* fail message: Assert.That(number, Is.AtLeast(2))
Expected: greater than or equal to 2
But was: 1
*/

// new assertion:
number.Should().BeGreaterOrEqualTo(2); /* fail message: Expected number to be greater than or equal to 2, but found 1. */
Expand Down Expand Up @@ -529,6 +534,7 @@ var number = 1;
// old assertion:
ClassicAssert.LessOrEqual(number, 2);
Assert.That(number, Is.LessThanOrEqualTo(2));
Assert.That(number, Is.AtMost(2));

// new assertion:
number.Should().BeLessOrEqualTo(2);
Expand All @@ -548,6 +554,10 @@ Assert.That(number, Is.LessThanOrEqualTo(1)); /* fail message: Assert.That(num
Expected: less than or equal to 1
But was: 2
*/
Assert.That(number, Is.AtMost(1)); /* fail message: Assert.That(number, Is.AtMost(1))
Expected: less than or equal to 1
But was: 2
*/

// new assertion:
number.Should().BeLessOrEqualTo(1); /* fail message: Expected number to be less than or equal to 1, but found 2. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@
var obj2 = obj1;

// old assertion:
Assert.AreSame(obj1, obj2);

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 513 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

// new assertion:
obj1.Should().BeSameAs(obj2);
Expand All @@ -524,7 +524,7 @@
object obj2 = "foo";

// old assertion:
Assert.AreSame(obj1, obj2);

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)

Check warning on line 527 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.SameAs(expected)), instead of the classic model, Assert.AreSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2015.md)
}

[Test, ExpectedAssertionException]
Expand All @@ -546,7 +546,7 @@
object obj2 = "foo";

// old assertion:
Assert.AreNotSame(obj1, obj2);

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 549 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

// new assertion:
obj1.Should().NotBeSameAs(obj2);
Expand All @@ -560,7 +560,7 @@
var obj2 = "foo";

// old assertion:
Assert.AreNotSame(obj1, obj2);

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)

Check warning on line 563 in src/FluentAssertions.Analyzers.FluentAssertionAnalyzerDocs.Nunit3/Nunit3AnalyzerTests.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Consider using the constraint model, Assert.That(actual, Is.Not.SameAs(expected)), instead of the classic model, Assert.AreNotSame(expected, actual) (https://github.com/nunit/nunit.analyzers/tree/master/documentation/NUnit2031.md)
}

[Test, ExpectedAssertionException]
Expand Down Expand Up @@ -627,6 +627,7 @@
// old assertion:
Assert.GreaterOrEqual(number, 1);
Assert.That(number, Is.GreaterThanOrEqualTo(1));
Assert.That(number, Is.AtLeast(1));

// new assertion:
number.Should().BeGreaterOrEqualTo(1);
Expand All @@ -651,6 +652,16 @@
// old assertion:
Assert.That(number, Is.GreaterThanOrEqualTo(2));
}

[Test, ExpectedAssertionException]
public void AssertGreaterOrEqual_Failure_OldAssertion_2()
{
// arrange
var number = 1;

// old assertion:
Assert.That(number, Is.AtLeast(2));
}

[Test, ExpectedAssertionException]
public void AssertGreaterOrEqual_Failure_NewAssertion()
Expand Down Expand Up @@ -715,6 +726,7 @@
// old assertion:
Assert.LessOrEqual(number, 2);
Assert.That(number, Is.LessThanOrEqualTo(2));
Assert.That(number, Is.AtMost(2));

// new assertion:
number.Should().BeLessOrEqualTo(2);
Expand All @@ -740,6 +752,16 @@
Assert.That(number, Is.LessThanOrEqualTo(1));
}

[Test, ExpectedAssertionException]
public void AssertLessOrEqual_Failure_OldAssertion_2()
{
// arrange
var number = 2;

// old assertion:
Assert.That(number, Is.AtMost(1));
}

[Test, ExpectedAssertionException]
public void AssertLessOrEqual_Failure_NewAssertion()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ public void AssertGreaterOrEqual()
// old assertion:
ClassicAssert.GreaterOrEqual(number, 1);
Assert.That(number, Is.GreaterThanOrEqualTo(1));
Assert.That(number, Is.AtLeast(1));

// new assertion:
number.Should().BeGreaterOrEqualTo(1);
Expand All @@ -662,6 +663,16 @@ public void AssertGreaterOrEqual_Failure_OldAssertion_1()
// old assertion:
Assert.That(number, Is.GreaterThanOrEqualTo(2));
}

[Test, ExpectedAssertionException]
public void AssertGreaterOrEqual_Failure_OldAssertion_2()
{
// arrange
var number = 1;

// old assertion:
Assert.That(number, Is.AtLeast(2));
}

[Test, ExpectedAssertionException]
public void AssertGreaterOrEqual_Failure_NewAssertion()
Expand Down Expand Up @@ -726,6 +737,7 @@ public void AssertLessOrEqual()
// old assertion:
ClassicAssert.LessOrEqual(number, 2);
Assert.That(number, Is.LessThanOrEqualTo(2));
Assert.That(number, Is.AtMost(2));

// new assertion:
number.Should().BeLessOrEqualTo(2);
Expand All @@ -751,6 +763,16 @@ public void AssertLessOrEqual_Failure_OldAssertion_1()
Assert.That(number, Is.LessThanOrEqualTo(1));
}

[Test, ExpectedAssertionException]
public void AssertLessOrEqual_Failure_OldAssertion_2()
{
// arrange
var number = 2;

// old assertion:
Assert.That(number, Is.AtMost(1));
}

[Test, ExpectedAssertionException]
public void AssertLessOrEqual_Failure_NewAssertion()
{
Expand Down
16 changes: 16 additions & 0 deletions src/FluentAssertions.Analyzers.Tests/Tips/NunitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,7 @@ public void Nunit4_AssertGreater_TestCodeFix(string oldAssertion, string newAsse
[DataTestMethod]
[AssertionDiagnostic("Assert.GreaterOrEqual(arg1, arg2{0});")]
[AssertionDiagnostic("Assert.That(arg1, Is.GreaterThanOrEqualTo(arg2){0});")]
[AssertionDiagnostic("Assert.That(arg1, Is.AtLeast(arg2){0});")]
[Implemented]
public void Nunit3_AssertGreaterOrEqual_TestAnalyzer(string assertion)
{
Expand All @@ -742,6 +743,7 @@ public void Nunit3_AssertGreaterOrEqual_TestAnalyzer(string assertion)
[DataTestMethod]
[AssertionDiagnostic("ClassicAssert.GreaterOrEqual(arg1, arg2{0});")]
[AssertionDiagnostic("Assert.That(arg1, Is.GreaterThanOrEqualTo(arg2));")]
[AssertionDiagnostic("Assert.That(arg1, Is.AtLeast(arg2));")]
[Implemented]
public void Nunit4_AssertGreaterOrEqual_TestAnalyzer(string assertion)
{
Expand All @@ -758,6 +760,9 @@ public void Nunit4_AssertGreaterOrEqual_TestAnalyzer(string assertion)
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.GreaterThanOrEqualTo(arg2){0});",
newAssertion: "arg1.Should().BeGreaterOrEqualTo(arg2{0});")]
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.AtLeast(arg2){0});",
newAssertion: "arg1.Should().BeGreaterOrEqualTo(arg2{0});")]
[Implemented]
public void Nunit3_AssertGreaterOrEqual_TestCodeFix(string oldAssertion, string newAssertion)
{
Expand All @@ -774,6 +779,9 @@ public void Nunit3_AssertGreaterOrEqual_TestCodeFix(string oldAssertion, string
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.GreaterThanOrEqualTo(arg2));",
newAssertion: "arg1.Should().BeGreaterOrEqualTo(arg2);")]
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.AtLeast(arg2));",
newAssertion: "arg1.Should().BeGreaterOrEqualTo(arg2);")]
[Implemented]
public void Nunit4_AssertGreaterOrEqual_TestCodeFix(string oldAssertion, string newAssertion)
{
Expand Down Expand Up @@ -842,6 +850,7 @@ public void Nunit4_AssertLess_TestCodeFix(string oldAssertion, string newAsserti
[DataTestMethod]
[AssertionDiagnostic("Assert.LessOrEqual(arg1, arg2{0});")]
[AssertionDiagnostic("Assert.That(arg1, Is.LessThanOrEqualTo(arg2){0});")]
[AssertionDiagnostic("Assert.That(arg1, Is.AtMost(arg2){0});")]
[Implemented]
public void Nunit3_AssertLessOrEqual_TestAnalyzer(string assertion)
{
Expand All @@ -854,6 +863,7 @@ public void Nunit3_AssertLessOrEqual_TestAnalyzer(string assertion)
[DataTestMethod]
[AssertionDiagnostic("ClassicAssert.LessOrEqual(arg1, arg2{0});")]
[AssertionDiagnostic("Assert.That(arg1, Is.LessThanOrEqualTo(arg2));")]
[AssertionDiagnostic("Assert.That(arg1, Is.AtMost(arg2));")]
[Implemented]
public void Nunit4_AssertLessOrEqual_TestAnalyzer(string assertion)
{
Expand All @@ -870,6 +880,9 @@ public void Nunit4_AssertLessOrEqual_TestAnalyzer(string assertion)
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.LessThanOrEqualTo(arg2){0});",
newAssertion: "arg1.Should().BeLessOrEqualTo(arg2{0});")]
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.AtMost(arg2){0});",
newAssertion: "arg1.Should().BeLessOrEqualTo(arg2{0});")]
[Implemented]
public void Nunit3_AssertLessOrEqual_TestCodeFix(string oldAssertion, string newAssertion)
{
Expand All @@ -886,6 +899,9 @@ public void Nunit3_AssertLessOrEqual_TestCodeFix(string oldAssertion, string new
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.LessThanOrEqualTo(arg2));",
newAssertion: "arg1.Should().BeLessOrEqualTo(arg2);")]
[AssertionCodeFix(
oldAssertion: "Assert.That(arg1, Is.AtMost(arg2));",
newAssertion: "arg1.Should().BeLessOrEqualTo(arg2);")]
[Implemented]
public void Nunit4_AssertLessOrEqual_TestCodeFix(string oldAssertion, string newAssertion)
{
Expand Down
6 changes: 4 additions & 2 deletions src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,13 @@
return rewriter.Should("NotBe", g => g.LiteralExpression(0));
else if (matcher.Is(Method("GreaterThan"), out var argument))
return rewriter.Should("BeGreaterThan", argument);
else if (matcher.Is(Method("GreaterThanOrEqualTo"), out argument))
else if (matcher.Is(Method("GreaterThanOrEqualTo"), out argument)
|| matcher.Is(Method("AtLeast"), out argument))
return rewriter.Should("BeGreaterOrEqualTo", argument);
else if (matcher.Is(Method("LessThan"), out argument))
return rewriter.Should("BeLessThan", argument);
else if (matcher.Is(Method("LessThanOrEqualTo"), out argument))
else if (matcher.Is(Method("LessThanOrEqualTo"), out argument)
|| matcher.Is(Method("AtMost"), out argument))
return rewriter.Should("BeLessOrEqualTo", argument);
else if (matcher.Has(Method("Member"), out argument)
|| matcher.Does(Method("Contain"), out argument)
Expand Down Expand Up @@ -667,7 +669,7 @@
return false;
}
}
public class AssertThatRewriter(IInvocationOperation invocation, CodeFixContext context, IOperation constraint)

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / Performance regression check

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Debug)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (ubuntu-latest, Release)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Release)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (macos-latest, Debug)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Debug)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Parameter 'constraint' is unread.

Check warning on line 672 in src/FluentAssertions.Analyzers/Tips/NunitCodeFixProvider.cs

View workflow job for this annotation

GitHub Actions / build (windows-latest, Release)

Parameter 'constraint' is unread.
{
public CreateChangedDocument Should(string assertion)
{
Expand Down
Loading