@@ -14,7 +14,15 @@ public class NunitTests
1414 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
1515 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
1616 [ Implemented ]
17- public void AssertTrue_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic ( "bool actual" , assertion ) ;
17+ public void Nunit3_AssertTrue_TestAnalyzer ( string assertion ) => Nunit3VerifyDiagnostic ( "bool actual" , assertion ) ;
18+
19+ [ DataTestMethod ]
20+ [ AssertionDiagnostic ( "ClassicAssert.True(actual{0});" ) ]
21+ [ AssertionDiagnostic ( "ClassicAssert.True(bool.Parse(\" true\" ){0});" ) ]
22+ [ AssertionDiagnostic ( "ClassicAssert.IsTrue(actual{0});" ) ]
23+ [ AssertionDiagnostic ( "ClassicAssert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
24+ [ Implemented ]
25+ public void Nunit4_AssertTrue_TestAnalyzer ( string assertion ) => Nunit4VerifyDiagnostic ( "bool actual" , assertion ) ;
1826
1927 [ DataTestMethod ]
2028 [ AssertionCodeFix (
@@ -42,16 +50,51 @@ public class NunitTests
4250 oldAssertion : "Assert.IsTrue(actual == false{0});" ,
4351 newAssertion : "(actual == false).Should().BeTrue({0});" ) ]
4452 [ Implemented ]
45- public void AssertTrue_TestCodeFix ( string oldAssertion , string newAssertion )
46- => VerifyCSharpFix ( "bool actual" , oldAssertion , newAssertion ) ;
53+ public void Nunit3_AssertTrue_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit3VerifyFix ( "bool actual" , oldAssertion , newAssertion ) ;
54+
55+ [ DataTestMethod ]
56+ [ AssertionCodeFix (
57+ oldAssertion : "ClassicAssert.True(actual{0});" ,
58+ newAssertion : "actual.Should().BeTrue({0});" ) ]
59+ [ AssertionCodeFix (
60+ oldAssertion : "ClassicAssert.True(bool.Parse(\" true\" ){0});" ,
61+ newAssertion : "bool.Parse(\" true\" ).Should().BeTrue({0});" ) ]
62+ [ AssertionCodeFix (
63+ oldAssertion : "ClassicAssert.True(!actual{0});" ,
64+ newAssertion : "(!actual).Should().BeTrue({0});" ) ]
65+ [ AssertionCodeFix (
66+ oldAssertion : "ClassicAssert.True(actual == false{0});" ,
67+ newAssertion : "(actual == false).Should().BeTrue({0});" ) ]
68+ [ AssertionCodeFix (
69+ oldAssertion : "ClassicAssert.IsTrue(actual{0});" ,
70+ newAssertion : "actual.Should().BeTrue({0});" ) ]
71+ [ AssertionCodeFix (
72+ oldAssertion : "ClassicAssert.IsTrue(bool.Parse(\" true\" ){0});" ,
73+ newAssertion : "bool.Parse(\" true\" ).Should().BeTrue({0});" ) ]
74+ [ AssertionCodeFix (
75+ oldAssertion : "ClassicAssert.IsTrue(!actual{0});" ,
76+ newAssertion : "(!actual).Should().BeTrue({0});" ) ]
77+ [ AssertionCodeFix (
78+ oldAssertion : "ClassicAssert.IsTrue(actual == false{0});" ,
79+ newAssertion : "(actual == false).Should().BeTrue({0});" ) ]
80+ [ Implemented ]
81+ public void Nunit4_AssertTrue_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit4VerifyFix ( "bool actual" , oldAssertion , newAssertion ) ;
4782
4883 [ DataTestMethod ]
4984 [ AssertionDiagnostic ( "Assert.False(actual{0});" ) ]
5085 [ AssertionDiagnostic ( "Assert.False(bool.Parse(\" false\" ){0});" ) ]
5186 [ AssertionDiagnostic ( "Assert.IsFalse(actual{0});" ) ]
5287 [ AssertionDiagnostic ( "Assert.IsFalse(bool.Parse(\" false\" ){0});" ) ]
5388 [ Implemented ]
54- public void AssertFalse_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic ( "bool actual" , assertion ) ;
89+ public void Nunit3_AssertFalse_TestAnalyzer ( string assertion ) => Nunit3VerifyDiagnostic ( "bool actual" , assertion ) ;
90+
91+ [ DataTestMethod ]
92+ [ AssertionDiagnostic ( "ClassicAssert.False(actual{0});" ) ]
93+ [ AssertionDiagnostic ( "ClassicAssert.False(bool.Parse(\" false\" ){0});" ) ]
94+ [ AssertionDiagnostic ( "ClassicAssert.IsFalse(actual{0});" ) ]
95+ [ AssertionDiagnostic ( "ClassicAssert.IsFalse(bool.Parse(\" false\" ){0});" ) ]
96+ [ Implemented ]
97+ public void Nunit4_AssertFalse_TestAnalyzer ( string assertion ) => Nunit4VerifyDiagnostic ( "bool actual" , assertion ) ;
5598
5699 [ DataTestMethod ]
57100 [ AssertionCodeFix (
@@ -67,16 +110,104 @@ public void AssertTrue_TestCodeFix(string oldAssertion, string newAssertion)
67110 oldAssertion : "Assert.IsFalse(bool.Parse(\" false\" ){0});" ,
68111 newAssertion : "bool.Parse(\" false\" ).Should().BeFalse({0});" ) ]
69112 [ Implemented ]
70- public void AssertFalse_TestCodeFix ( string oldAssertion , string newAssertion )
71- => VerifyCSharpFix ( "bool actual" , oldAssertion , newAssertion ) ;
113+ public void Nunit3_AssertFalse_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit3VerifyFix ( "bool actual" , oldAssertion , newAssertion ) ;
114+
115+ [ DataTestMethod ]
116+ [ AssertionCodeFix (
117+ oldAssertion : "ClassicAssert.False(actual{0});" ,
118+ newAssertion : "actual.Should().BeFalse({0});" ) ]
119+ [ AssertionCodeFix (
120+ oldAssertion : "ClassicAssert.False(bool.Parse(\" false\" ){0});" ,
121+ newAssertion : "bool.Parse(\" false\" ).Should().BeFalse({0});" ) ]
122+ [ AssertionCodeFix (
123+ oldAssertion : "ClassicAssert.IsFalse(actual{0});" ,
124+ newAssertion : "actual.Should().BeFalse({0});" ) ]
125+ [ AssertionCodeFix (
126+ oldAssertion : "ClassicAssert.IsFalse(bool.Parse(\" false\" ){0});" ,
127+ newAssertion : "bool.Parse(\" false\" ).Should().BeFalse({0});" ) ]
128+ [ Implemented ]
129+ public void Nunit4_AssertFalse_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit4VerifyFix ( "bool actual" , oldAssertion , newAssertion ) ;
72130
73- private void VerifyCSharpDiagnostic ( string methodArguments , string assertion )
131+ [ DataTestMethod ]
132+ [ AssertionDiagnostic ( "Assert.Null(actual{0});" ) ]
133+ [ AssertionDiagnostic ( "Assert.IsNull(actual{0});" ) ]
134+ [ Implemented ]
135+ public void Nunit3_AssertNull_TestAnalyzer ( string assertion ) => Nunit3VerifyDiagnostic ( "object actual" , assertion ) ;
136+
137+ [ DataTestMethod ]
138+ [ AssertionDiagnostic ( "ClassicAssert.Null(actual{0});" ) ]
139+ [ AssertionDiagnostic ( "ClassicAssert.IsNull(actual{0});" ) ]
140+ [ Implemented ]
141+ public void Nunit4_AssertNull_TestAnalyzer ( string assertion ) => Nunit4VerifyDiagnostic ( "object actual" , assertion ) ;
142+
143+ [ DataTestMethod ]
144+ [ AssertionCodeFix (
145+ oldAssertion : "Assert.Null(actual{0});" ,
146+ newAssertion : "actual.Should().BeNull({0});" ) ]
147+ [ AssertionCodeFix (
148+ oldAssertion : "Assert.IsNull(actual{0});" ,
149+ newAssertion : "actual.Should().BeNull({0});" ) ]
150+ [ Implemented ]
151+ public void Nunit3_AssertNull_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit3VerifyFix ( "object actual" , oldAssertion , newAssertion ) ;
152+
153+ [ DataTestMethod ]
154+ [ AssertionCodeFix (
155+ oldAssertion : "ClassicAssert.Null(actual{0});" ,
156+ newAssertion : "actual.Should().BeNull({0});" ) ]
157+ [ AssertionCodeFix (
158+ oldAssertion : "ClassicAssert.IsNull(actual{0});" ,
159+ newAssertion : "actual.Should().BeNull({0});" ) ]
160+ [ Implemented ]
161+ public void Nunit4_AssertNull_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit4VerifyFix ( "object actual" , oldAssertion , newAssertion ) ;
162+
163+ [ DataTestMethod ]
164+ [ AssertionDiagnostic ( "Assert.NotNull(actual{0});" ) ]
165+ [ AssertionDiagnostic ( "Assert.IsNotNull(actual{0});" ) ]
166+ [ Implemented ]
167+ public void Nunit3_AssertNotNull_TestAnalyzer ( string assertion ) => Nunit3VerifyDiagnostic ( "object actual" , assertion ) ;
168+
169+ [ DataTestMethod ]
170+ [ AssertionDiagnostic ( "ClassicAssert.NotNull(actual{0});" ) ]
171+ [ AssertionDiagnostic ( "ClassicAssert.IsNotNull(actual{0});" ) ]
172+ [ Implemented ]
173+ public void Nunit4_AssertNotNull_TestAnalyzer ( string assertion ) => Nunit4VerifyDiagnostic ( "object actual" , assertion ) ;
174+
175+ [ DataTestMethod ]
176+ [ AssertionCodeFix (
177+ oldAssertion : "Assert.NotNull(actual{0});" ,
178+ newAssertion : "actual.Should().NotBeNull({0});" ) ]
179+ [ AssertionCodeFix (
180+ oldAssertion : "Assert.IsNotNull(actual{0});" ,
181+ newAssertion : "actual.Should().NotBeNull({0});" ) ]
182+ [ Implemented ]
183+ public void Nunit3_AssertNotNull_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit3VerifyFix ( "object actual" , oldAssertion , newAssertion ) ;
184+
185+ [ DataTestMethod ]
186+ [ AssertionCodeFix (
187+ oldAssertion : "ClassicAssert.NotNull(actual{0});" ,
188+ newAssertion : "actual.Should().NotBeNull({0});" ) ]
189+ [ AssertionCodeFix (
190+ oldAssertion : "ClassicAssert.IsNotNull(actual{0});" ,
191+ newAssertion : "actual.Should().NotBeNull({0});" ) ]
192+ [ Implemented ]
193+ public void Nunit4_AssertNotNull_TestCodeFix ( string oldAssertion , string newAssertion ) => Nunit4VerifyFix ( "object actual" , oldAssertion , newAssertion ) ;
194+
195+ private void Nunit3VerifyDiagnostic ( string methodArguments , string assertion )
196+ => VerifyDiagnostic ( GenerateCode . Nunit3Assertion ( methodArguments , assertion ) , PackageReference . Nunit_3_14_0 ) ;
197+ private void Nunit3VerifyFix ( string methodArguments , string oldAssertion , string newAssertion )
198+ => VerifyFix ( GenerateCode . Nunit3Assertion ( methodArguments , oldAssertion ) , GenerateCode . Nunit3Assertion ( methodArguments , newAssertion ) , PackageReference . Nunit_3_14_0 ) ;
199+
200+ private void Nunit4VerifyDiagnostic ( string methodArguments , string assertion )
201+ => VerifyDiagnostic ( GenerateCode . Nunit4Assertion ( methodArguments , assertion ) , PackageReference . Nunit_4_0_1 ) ;
202+ private void Nunit4VerifyFix ( string methodArguments , string oldAssertion , string newAssertion )
203+ => VerifyFix ( GenerateCode . Nunit4Assertion ( methodArguments , oldAssertion ) , GenerateCode . Nunit4Assertion ( methodArguments , newAssertion ) , PackageReference . Nunit_4_0_1 ) ;
204+
205+ private void VerifyDiagnostic ( string source , PackageReference nunit )
74206 {
75- var source = GenerateCode . Nunit3Assertion ( methodArguments , assertion ) ;
76207 DiagnosticVerifier . VerifyDiagnostic ( new DiagnosticVerifierArguments ( )
77208 . WithAllAnalyzers ( )
78209 . WithSources ( source )
79- . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 , PackageReference . Nunit_3_14_0 )
210+ . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 , nunit )
80211 . WithExpectedDiagnostics ( new DiagnosticResult
81212 {
82213 Id = AssertAnalyzer . NUnitRule . Id ,
@@ -90,17 +221,14 @@ private void VerifyCSharpDiagnostic(string methodArguments, string assertion)
90221 ) ;
91222 }
92223
93- private void VerifyCSharpFix ( string methodArguments , string oldAssertion , string newAssertion )
224+ private void VerifyFix ( string oldSource , string newSource , PackageReference nunit )
94225 {
95- var oldSource = GenerateCode . Nunit3Assertion ( methodArguments , oldAssertion ) ;
96- var newSource = GenerateCode . Nunit3Assertion ( methodArguments , newAssertion ) ;
97-
98226 DiagnosticVerifier . VerifyFix ( new CodeFixVerifierArguments ( )
99227 . WithDiagnosticAnalyzer < AssertAnalyzer > ( )
100228 . WithCodeFixProvider < NunitCodeFixProvider > ( )
101229 . WithSources ( oldSource )
102230 . WithFixedSources ( newSource )
103- . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 , PackageReference . Nunit_3_14_0 )
231+ . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 , nunit )
104232 ) ;
105233 }
106234}
0 commit comments