-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create analyzer/fixer for Assert.NotEmpty (#185)
- Loading branch information
Showing
6 changed files
with
144 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
...zers.tests/Fixes/X2000/AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
using Xunit.Analyzers.Fixes; | ||
using Verify = CSharpVerifier<Xunit.Analyzers.AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecks>; | ||
|
||
public class AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixerTests | ||
{ | ||
const string template = /* lang=c#-test */ """ | ||
using System.Linq; | ||
using Xunit; | ||
|
||
public class TestClass {{ | ||
[Fact] | ||
public void TestMethod() {{ | ||
var list = new[] {{ -1, 0, 1, 2 }}; | ||
|
||
{0}; | ||
}} | ||
|
||
public bool IsEven(int num) => num % 2 == 0; | ||
}} | ||
"""; | ||
|
||
[Theory] | ||
[InlineData( | ||
/* lang=c#-test */ "{|xUnit2029:Assert.Empty(list.Where(f => f > 0))|}", | ||
/* lang=c#-test */ "Assert.DoesNotContain(list, f => f > 0)")] | ||
[InlineData( | ||
/* lang=c#-test */ "{|xUnit2029:Assert.Empty(list.Where(n => n == 1))|}", | ||
/* lang=c#-test */ "Assert.DoesNotContain(list, n => n == 1)")] | ||
[InlineData( | ||
/* lang=c#-test */ "{|xUnit2029:Assert.Empty(list.Where(IsEven))|}", | ||
/* lang=c#-test */ "Assert.DoesNotContain(list, IsEven)")] | ||
public async Task FixerReplacesAssertEmptyWithAssertDoesNotContain( | ||
string beforeAssert, | ||
string afterAssert) | ||
{ | ||
var before = string.Format(template, beforeAssert); | ||
var after = string.Format(template, afterAssert); | ||
|
||
await Verify.VerifyCodeFix(before, after, AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixer.Key_UseDoesNotContain); | ||
} | ||
|
||
[Theory] | ||
[InlineData( | ||
/* lang=c#-test */ "{|xUnit2030:Assert.NotEmpty(list.Where(f => f > 0))|}", | ||
/* lang=c#-test */ "Assert.Contains(list, f => f > 0)")] | ||
[InlineData( | ||
/* lang=c#-test */ "{|xUnit2030:Assert.NotEmpty(list.Where(n => n == 1))|}", | ||
/* lang=c#-test */ "Assert.Contains(list, n => n == 1)")] | ||
[InlineData( | ||
/* lang=c#-test */ "{|xUnit2030:Assert.NotEmpty(list.Where(IsEven))|}", | ||
/* lang=c#-test */ "Assert.Contains(list, IsEven)")] | ||
|
||
public async Task FixerReplacesAssertNotEmptyWithAssertContains( | ||
string beforeAssert, | ||
string afterAssert) | ||
{ | ||
var before = string.Format(template, beforeAssert); | ||
var after = string.Format(template, afterAssert); | ||
|
||
await Verify.VerifyCodeFix(before, after, AssertEmptyOrNotEmptyShouldNotBeUsedForContainsChecksFixer.Key_UseContains); | ||
} | ||
} |
43 changes: 0 additions & 43 deletions
43
...tests/Fixes/X2000/AssertEmptyShouldNotBeUsedForCollectionDoesNotContainCheckFixerTests.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters