@@ -84,6 +84,233 @@ public void AssertSame_TestCodeFix(string oldAssertion, string newAssertion)
8484 public void AssertNotSame_TestCodeFix ( string oldAssertion , string newAssertion )
8585 => VerifyCSharpFix < AssertNotSameCodeFix , AssertNotSameAnalyzer > ( "object actual, object expected" , oldAssertion , newAssertion ) ;
8686
87+ [ DataTestMethod ]
88+ [ DataRow ( "Assert.Equal(expected, actual, tolerance);" ) ]
89+ [ DataRow ( "Assert.Equal(expected, actual, 0.6f);" ) ]
90+ [ Implemented ]
91+ public void AssertFloatEqualWithTolerance_TestAnalyzer ( string assertion ) =>
92+ VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "float actual, float expected, float tolerance" , assertion ) ;
93+
94+ [ DataTestMethod ]
95+ [ DataRow (
96+ /* oldAssertion: */ "Assert.Equal(expected, actual, tolerance);" ,
97+ /* newAssertion: */ "actual.Should().BeApproximately(expected, tolerance);" ) ]
98+ [ DataRow (
99+ /* oldAssertion: */ "Assert.Equal(expected, actual, 0.6f);" ,
100+ /* newAssertion: */ "actual.Should().BeApproximately(expected, 0.6f);" ) ]
101+ [ Implemented ]
102+ public void AssertFloatEqualWithTolerance_TestCodeFix ( string oldAssertion , string newAssertion )
103+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "float actual, float expected, float tolerance" , oldAssertion , newAssertion ) ;
104+
105+ [ DataTestMethod ]
106+ [ DataRow ( "Assert.Equal(expected, actual, tolerance);" ) ]
107+ [ DataRow ( "Assert.Equal(expected, actual, 0.6);" ) ]
108+ [ Implemented ]
109+ public void AssertDoubleEqualWithTolerance_TestAnalyzer ( string assertion ) =>
110+ VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "double actual, double expected, double tolerance" , assertion ) ;
111+
112+ [ DataTestMethod ]
113+ [ DataRow (
114+ /* oldAssertion: */ "Assert.Equal(expected, actual, tolerance);" ,
115+ /* newAssertion: */ "actual.Should().BeApproximately(expected, tolerance);" ) ]
116+ [ DataRow (
117+ /* oldAssertion: */ "Assert.Equal(expected, actual, 0.6);" ,
118+ /* newAssertion: */ "actual.Should().BeApproximately(expected, 0.6);" ) ]
119+ [ Implemented ]
120+ public void AssertDoubleEqualWithTolerance_TestCodeFix ( string oldAssertion , string newAssertion )
121+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "double actual, double expected, double tolerance" , oldAssertion , newAssertion ) ;
122+
123+ [ DataTestMethod ]
124+ [ DataRow ( "Assert.Equal(expected, actual, precision);" ) ]
125+ [ DataRow ( "Assert.Equal(expected, actual, 5);" ) ]
126+ [ Implemented ]
127+ public void AssertDoubleEqualWithPrecision_TestAnalyzer ( string assertion ) =>
128+ VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "double actual, double expected, int precision" , assertion ) ;
129+
130+ // There is no corresponding API in FluentAssertions
131+ [ DataTestMethod ]
132+ [ DataRow (
133+ /* oldAssertion: */ "Assert.Equal(expected, actual, precision);" ,
134+ /* newAssertion: */ "Assert.Equal(expected, actual, precision);" ) ]
135+ [ DataRow (
136+ /* oldAssertion: */ "Assert.Equal(expected, actual, 5);" ,
137+ /* newAssertion: */ "Assert.Equal(expected, actual, 5);" ) ]
138+ [ DataRow (
139+ /* oldAssertion: */ "Assert.Equal(expected, actual, precision, rounding);" ,
140+ /* newAssertion: */ "Assert.Equal(expected, actual, precision, rounding);" ) ]
141+ [ DataRow (
142+ /* oldAssertion: */ "Assert.Equal(expected, actual, 5, MidpointRounding.ToEven);" ,
143+ /* newAssertion: */ "Assert.Equal(expected, actual, 5, MidpointRounding.ToEven);" ) ]
144+ [ Implemented ]
145+ public void AssertDoubleEqualWithPrecision_TestCodeFix ( string oldAssertion , string newAssertion )
146+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "double actual, double expected, int precision, MidpointRounding rounding" , oldAssertion , newAssertion ) ;
147+
148+ [ DataTestMethod ]
149+ [ DataRow ( "Assert.Equal(expected, actual, precision);" ) ]
150+ [ DataRow ( "Assert.Equal(expected, actual, 5);" ) ]
151+ [ Implemented ]
152+ public void AssertDecimalEqualWithPrecision_TestAnalyzer ( string assertion ) =>
153+ VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "decimal actual, decimal expected, int precision" , assertion ) ;
154+
155+ // There is no corresponding API in FluentAssertions
156+ [ DataTestMethod ]
157+ [ DataRow (
158+ /* oldAssertion: */ "Assert.Equal(expected, actual, precision);" ,
159+ /* newAssertion: */ "Assert.Equal(expected, actual, precision);" ) ]
160+ [ DataRow (
161+ /* oldAssertion: */ "Assert.Equal(expected, actual, 5);" ,
162+ /* newAssertion: */ "Assert.Equal(expected, actual, 5);" ) ]
163+ [ Implemented ]
164+ public void AssertDecimalEqualWithPrecision_TestCodeFix ( string oldAssertion , string newAssertion )
165+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "decimal actual, decimal expected, int precision" , oldAssertion , newAssertion ) ;
166+
167+ [ DataTestMethod ]
168+ [ DataRow ( "Assert.Equal(expected, actual, precision);" ) ]
169+ [ DataRow ( "Assert.Equal(expected, actual, TimeSpan.FromSeconds(1));" ) ]
170+ [ Implemented ]
171+ public void AssertDateTimeEqual_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "DateTime actual, DateTime expected, TimeSpan precision" , assertion ) ;
172+
173+ [ DataTestMethod ]
174+ [ DataRow (
175+ /* oldAssertion: */ "Assert.Equal(expected, actual, precision);" ,
176+ /* newAssertion: */ "actual.Should().BeCloseTo(expected, precision);" ) ]
177+ [ DataRow (
178+ /* oldAssertion: */ "Assert.Equal(expected, actual, TimeSpan.FromSeconds(1));" ,
179+ /* newAssertion: */ "actual.Should().BeCloseTo(expected, TimeSpan.FromSeconds(1));" ) ]
180+ [ Implemented ]
181+ public void AssertDateTimeEqual_TestCodeFix ( string oldAssertion , string newAssertion )
182+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "DateTime actual, DateTime expected, TimeSpan precision" , oldAssertion , newAssertion ) ;
183+
184+ [ DataTestMethod ]
185+ [ DataRow ( "Assert.Equal(expected, actual, comparer);" ) ]
186+ [ DataRow ( "Assert.Equal(expected, actual, ReferenceEqualityComparer.Instance);" ) ]
187+ [ Implemented ]
188+ public void AssertObjectEqualWithComparer_TestAnalyzer ( string assertion ) =>
189+ VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "object actual, object expected, IEqualityComparer<object> comparer" , assertion ) ;
190+
191+ [ DataTestMethod ]
192+ [ DataRow (
193+ /* oldAssertion: */ "Assert.Equal(expected, actual, comparer);" ,
194+ /* newAssertion: */ "actual.Should().BeEquivalentTo(expected, options => options.Using(comparer));" ) ]
195+ [ DataRow (
196+ /* oldAssertion: */ "Assert.Equal(expected, actual, ReferenceEqualityComparer.Instance);" ,
197+ /* newAssertion: */ "actual.Should().BeEquivalentTo(expected, options => options.Using(ReferenceEqualityComparer.Instance));" ) ]
198+ [ Implemented ]
199+ public void AssertObjectEqualWithComparer_TestCodeFix ( string oldAssertion , string newAssertion )
200+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "object actual, object expected, IEqualityComparer<object> comparer" , oldAssertion , newAssertion ) ;
201+
202+ [ DataTestMethod ]
203+ [ DataRow ( "Assert.Equal(expected, actual);" ) ]
204+ [ Implemented ]
205+ public void AssertObjectEqual_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic < AssertEqualAnalyzer > ( "object actual, object expected" , assertion ) ;
206+
207+ [ DataTestMethod ]
208+ [ DataRow (
209+ /* oldAssertion: */ "Assert.Equal(expected, actual);" ,
210+ /* newAssertion: */ "actual.Should().Be(expected);" ) ]
211+ [ Implemented ]
212+ public void AssertObjectEqual_TestCodeFix ( string oldAssertion , string newAssertion )
213+ => VerifyCSharpFix < AssertEqualCodeFix , AssertEqualAnalyzer > ( "object actual, object expected" , oldAssertion , newAssertion ) ;
214+
215+ [ DataTestMethod ]
216+ [ DataRow ( "Assert.StrictEqual(expected, actual);" ) ]
217+ [ Implemented ]
218+ public void AssertStrictEqual_TestAnalyzer ( string assertion ) =>
219+ VerifyCSharpDiagnostic < AssertStrictEqualAnalyzer > ( "object actual, object expected" , assertion ) ;
220+
221+ [ DataTestMethod ]
222+ [ DataRow (
223+ /* oldAssertion: */ "Assert.StrictEqual(expected, actual);" ,
224+ /* newAssertion: */ "actual.Should().Be(expected);" ) ]
225+ [ Implemented ]
226+ public void AssertStrictEqual_TestCodeFix ( string oldAssertion , string newAssertion )
227+ => VerifyCSharpFix < AssertStrictEqualCodeFix , AssertStrictEqualAnalyzer > ( "object actual, object expected" , oldAssertion , newAssertion ) ;
228+
229+ [ DataTestMethod ]
230+ [ DataRow ( "Assert.NotEqual(expected, actual, precision);" ) ]
231+ [ DataRow ( "Assert.NotEqual(expected, actual, 5);" ) ]
232+ [ Implemented ]
233+ public void AssertDoubleNotEqualWithPrecision_TestAnalyzer ( string assertion ) =>
234+ VerifyCSharpDiagnostic < AssertNotEqualAnalyzer > ( "double actual, double expected, int precision" , assertion ) ;
235+
236+ // There is no corresponding API in FluentAssertions
237+ [ DataTestMethod ]
238+ [ DataRow (
239+ /* oldAssertion: */ "Assert.NotEqual(expected, actual, precision);" ,
240+ /* newAssertion: */ "Assert.NotEqual(expected, actual, precision);" ) ]
241+ [ DataRow (
242+ /* oldAssertion: */ "Assert.NotEqual(expected, actual, 5);" ,
243+ /* newAssertion: */ "Assert.NotEqual(expected, actual, 5);" ) ]
244+ [ Implemented ]
245+ public void AssertDoubleNotEqualWithPrecision_TestCodeFix ( string oldAssertion , string newAssertion )
246+ => VerifyCSharpFix < AssertNotEqualCodeFix , AssertNotEqualAnalyzer > ( "double actual, double expected, int precision" , oldAssertion , newAssertion ) ;
247+
248+ [ DataTestMethod ]
249+ [ DataRow ( "Assert.NotEqual(expected, actual, precision);" ) ]
250+ [ DataRow ( "Assert.NotEqual(expected, actual, 5);" ) ]
251+ [ Implemented ]
252+ public void AssertDecimalNotEqualWithPrecision_TestAnalyzer ( string assertion ) =>
253+ VerifyCSharpDiagnostic < AssertNotEqualAnalyzer > ( "decimal actual, decimal expected, int precision" , assertion ) ;
254+
255+ // There is no corresponding API in FluentAssertions
256+ [ DataTestMethod ]
257+ [ DataRow (
258+ /* oldAssertion: */ "Assert.NotEqual(expected, actual, precision);" ,
259+ /* newAssertion: */ "Assert.NotEqual(expected, actual, precision);" ) ]
260+ [ DataRow (
261+ /* oldAssertion: */ "Assert.NotEqual(expected, actual, 5);" ,
262+ /* newAssertion: */ "Assert.NotEqual(expected, actual, 5);" ) ]
263+ [ Implemented ]
264+ public void AssertDecimalNotEqualWithPrecision_TestCodeFix ( string oldAssertion , string newAssertion )
265+ => VerifyCSharpFix < AssertNotEqualCodeFix , AssertNotEqualAnalyzer > ( "decimal actual, decimal expected, int precision" , oldAssertion , newAssertion ) ;
266+
267+ [ DataTestMethod ]
268+ [ DataRow ( "Assert.NotEqual(expected, actual, comparer);" ) ]
269+ [ DataRow ( "Assert.NotEqual(expected, actual, ReferenceEqualityComparer.Instance);" ) ]
270+ [ Implemented ]
271+ public void AssertObjectNotEqualWithComparer_TestAnalyzer ( string assertion ) =>
272+ VerifyCSharpDiagnostic < AssertNotEqualAnalyzer > ( "object actual, object expected, IEqualityComparer<object> comparer" , assertion ) ;
273+
274+ [ DataTestMethod ]
275+ [ DataRow (
276+ /* oldAssertion: */ "Assert.NotEqual(expected, actual, comparer);" ,
277+ /* newAssertion: */ "actual.Should().NotBeEquivalentTo(expected, options => options.Using(comparer));" ) ]
278+ [ DataRow (
279+ /* oldAssertion: */ "Assert.NotEqual(expected, actual, ReferenceEqualityComparer.Instance);" ,
280+ /* newAssertion: */ "actual.Should().NotBeEquivalentTo(expected, options => options.Using(ReferenceEqualityComparer.Instance));" ) ]
281+ [ Implemented ]
282+ public void AssertObjectNotEqualWithComparer_TestCodeFix ( string oldAssertion , string newAssertion )
283+ => VerifyCSharpFix < AssertNotEqualCodeFix , AssertNotEqualAnalyzer > ( "object actual, object expected, IEqualityComparer<object> comparer" , oldAssertion , newAssertion ) ;
284+
285+ [ DataTestMethod ]
286+ [ DataRow ( "Assert.NotEqual(expected, actual);" ) ]
287+ [ Implemented ]
288+ public void AssertObjectNotEqual_TestAnalyzer ( string assertion ) =>
289+ VerifyCSharpDiagnostic < AssertNotEqualAnalyzer > ( "object actual, object expected" , assertion ) ;
290+
291+ [ DataTestMethod ]
292+ [ DataRow (
293+ /* oldAssertion: */ "Assert.NotEqual(expected, actual);" ,
294+ /* newAssertion: */ "actual.Should().NotBe(expected);" ) ]
295+ [ Implemented ]
296+ public void AssertObjectNotEqual_TestCodeFix ( string oldAssertion , string newAssertion )
297+ => VerifyCSharpFix < AssertNotEqualCodeFix , AssertNotEqualAnalyzer > ( "object actual, object expected" , oldAssertion , newAssertion ) ;
298+
299+ [ DataTestMethod ]
300+ [ DataRow ( "Assert.NotStrictEqual(expected, actual);" ) ]
301+ [ Implemented ]
302+ public void AssertObjectNotStrictEqual_TestAnalyzer ( string assertion ) =>
303+ VerifyCSharpDiagnostic < AssertNotStrictEqualAnalyzer > ( "object actual, object expected" , assertion ) ;
304+
305+ [ DataTestMethod ]
306+ [ DataRow (
307+ /* oldAssertion: */ "Assert.NotStrictEqual(expected, actual);" ,
308+ /* newAssertion: */ "actual.Should().NotBe(expected);" ) ]
309+ [ Implemented ]
310+ public void AssertObjectNotStrictEqual_TestCodeFix ( string oldAssertion , string newAssertion )
311+ => VerifyCSharpFix < AssertNotStrictEqualCodeFix , AssertNotStrictEqualAnalyzer > ( "object actual, object expected" , oldAssertion , newAssertion ) ;
312+
313+
87314 private void VerifyCSharpDiagnostic < TDiagnosticAnalyzer > ( string methodArguments , string assertion ) where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
88315 {
89316 var source = GenerateCode . XunitAssertion ( methodArguments , assertion ) ;
@@ -98,7 +325,7 @@ public void AssertNotSame_TestCodeFix(string oldAssertion, string newAssertion)
98325 Message = message ,
99326 Locations = new DiagnosticResultLocation [ ]
100327 {
101- new DiagnosticResultLocation ( "Test0.cs" , 12 , 13 )
328+ new ( "Test0.cs" , 13 , 13 )
102329 } ,
103330 Severity = DiagnosticSeverity . Info
104331 } ) ;
0 commit comments