|
5 | 5 |
|
6 | 6 | public class BooleanAssertsShouldNotBeNegatedFixerTests |
7 | 7 | { |
8 | | - const string template = /* lang=c#-test */ """ |
9 | | - using Xunit; |
10 | | -
|
11 | | - public class TestClass {{ |
12 | | - [Fact] |
13 | | - public void TestMethod() {{ |
14 | | - bool condition = true; |
15 | | -
|
16 | | - {0}; |
17 | | - }} |
18 | | - }} |
19 | | - """; |
20 | | - |
21 | | - [Theory] |
22 | | - [InlineData("False", "True")] |
23 | | - [InlineData("True", "False")] |
24 | | - public async Task ReplacesBooleanAssert( |
25 | | - string assertion, |
26 | | - string replacement) |
| 8 | + [Fact] |
| 9 | + public async Task AcceptanceTest() |
27 | 10 | { |
28 | | - var before = string.Format(template, $"[|Assert.{assertion}(!condition)|]"); |
29 | | - var after = string.Format(template, $"Assert.{replacement}(condition)"); |
| 11 | + var before = /* lang=c#-test */ """ |
| 12 | + using Xunit; |
| 13 | +
|
| 14 | + public class TestClass { |
| 15 | + [Fact] |
| 16 | + public void TestMethod() { |
| 17 | + bool condition = true; |
| 18 | +
|
| 19 | + // Not negated |
| 20 | + Assert.True(false); |
| 21 | + Assert.False(false); |
| 22 | + Assert.True(condition); |
| 23 | + Assert.False(condition); |
| 24 | +
|
| 25 | + // Negated |
| 26 | + [|Assert.True(!false)|]; |
| 27 | + [|Assert.False(!false)|]; |
| 28 | + [|Assert.True(!condition)|]; |
| 29 | + [|Assert.False(!condition)|]; |
| 30 | +
|
| 31 | + // Not negated, with message |
| 32 | + Assert.True(false, "test message"); |
| 33 | + Assert.False(false, "test message"); |
| 34 | + Assert.True(condition, "test message"); |
| 35 | + Assert.False(condition, "test message"); |
| 36 | +
|
| 37 | + // Negated, with message |
| 38 | + [|Assert.True(!false, "test message")|]; |
| 39 | + [|Assert.False(!false, "test message")|]; |
| 40 | + [|Assert.True(!condition, "test message")|]; |
| 41 | + [|Assert.False(!condition, "test message")|]; |
| 42 | +
|
| 43 | + // Not negated, with named parameter message |
| 44 | + Assert.True(false, userMessage: "test message"); |
| 45 | + Assert.False(false, userMessage: "test message"); |
| 46 | + Assert.True(condition, userMessage: "test message"); |
| 47 | + Assert.False(condition, userMessage: "test message"); |
| 48 | +
|
| 49 | + // Negated, with named parameter message |
| 50 | + [|Assert.True(!false, userMessage: "test message")|]; |
| 51 | + [|Assert.False(!false, userMessage: "test message")|]; |
| 52 | + [|Assert.True(!condition, userMessage: "test message")|]; |
| 53 | + [|Assert.False(!condition, userMessage: "test message")|]; |
| 54 | + } |
| 55 | + } |
| 56 | + """; |
| 57 | + var after = /* lang=c#-test */ """ |
| 58 | + using Xunit; |
| 59 | +
|
| 60 | + public class TestClass { |
| 61 | + [Fact] |
| 62 | + public void TestMethod() { |
| 63 | + bool condition = true; |
| 64 | +
|
| 65 | + // Not negated |
| 66 | + Assert.True(false); |
| 67 | + Assert.False(false); |
| 68 | + Assert.True(condition); |
| 69 | + Assert.False(condition); |
| 70 | +
|
| 71 | + // Negated |
| 72 | + Assert.False(false); |
| 73 | + Assert.True(false); |
| 74 | + Assert.False(condition); |
| 75 | + Assert.True(condition); |
| 76 | +
|
| 77 | + // Not negated, with message |
| 78 | + Assert.True(false, "test message"); |
| 79 | + Assert.False(false, "test message"); |
| 80 | + Assert.True(condition, "test message"); |
| 81 | + Assert.False(condition, "test message"); |
| 82 | +
|
| 83 | + // Negated, with message |
| 84 | + Assert.False(false, "test message"); |
| 85 | + Assert.True(false, "test message"); |
| 86 | + Assert.False(condition, "test message"); |
| 87 | + Assert.True(condition, "test message"); |
| 88 | +
|
| 89 | + // Not negated, with named parameter message |
| 90 | + Assert.True(false, userMessage: "test message"); |
| 91 | + Assert.False(false, userMessage: "test message"); |
| 92 | + Assert.True(condition, userMessage: "test message"); |
| 93 | + Assert.False(condition, userMessage: "test message"); |
| 94 | +
|
| 95 | + // Negated, with named parameter message |
| 96 | + Assert.False(false, userMessage: "test message"); |
| 97 | + Assert.True(false, userMessage: "test message"); |
| 98 | + Assert.False(condition, userMessage: "test message"); |
| 99 | + Assert.True(condition, userMessage: "test message"); |
| 100 | + } |
| 101 | + } |
| 102 | + """; |
30 | 103 |
|
31 | 104 | await Verify.VerifyCodeFix(before, after, BooleanAssertsShouldNotBeNegatedFixer.Key_UseSuggestedAssert); |
32 | 105 | } |
|
0 commit comments