@@ -247,6 +247,34 @@ public class CollectionTests
247247 [ Implemented ]
248248 public void CollectionShouldContainItem_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnosticCodeBlock ( assertion , DiagnosticMetadata . CollectionShouldContainItem_ContainsShouldBeTrue ) ;
249249
250+ [ TestMethod ]
251+ [ AssertionDiagnostic ( "actual.Contains(expectedItem).Should().BeTrue({0});" , "double" , "string" ) ]
252+ [ AssertionDiagnostic ( "actual.Contains(expectedItem).Should().BeTrue({0});" , "object" , "int" ) ]
253+ [ Implemented ]
254+ public void CollectionShouldContainItem_ContainsArgumentIsOfOtherTypeThanCollectionArgument_TestNoAnalyzer ( string assertion , string genericType , string containsType )
255+ {
256+ string source = $$ """
257+ using System;
258+ using System.Collections;
259+ using System.Collections.Generic;
260+
261+ using AwesomeAssertions;
262+ using AwesomeAssertions.Extensions;
263+
264+ namespace TestNamespace
265+ {
266+ {{ GenerateCode . ClassImplementsIList ( genericType , $ "public bool Contains({ containsType } item) => true;") }}
267+ public sealed class TestClass
268+ {
269+ public void TestMethod(RandomClass actual, {{ containsType }} expectedItem) =>
270+ {{ assertion }}
271+ }
272+ }
273+ """ ;
274+
275+ DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( source ) ;
276+ }
277+
250278 [ TestMethod ]
251279 [ AssertionCodeFix (
252280 oldAssertion : "actual.Contains(expectedItem).Should().BeTrue({0});" ,
@@ -271,6 +299,34 @@ public class CollectionTests
271299 [ Implemented ]
272300 public void CollectionShouldNotContainItem_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnosticCodeBlock ( assertion , DiagnosticMetadata . CollectionShouldNotContainItem_ContainsShouldBeFalse ) ;
273301
302+ [ TestMethod ]
303+ [ AssertionDiagnostic ( "actual.Contains(expectedItem).Should().BeFalse({0});" , "double" , "string" ) ]
304+ [ AssertionDiagnostic ( "actual.Contains(expectedItem).Should().BeFalse({0});" , "object" , "int" ) ]
305+ [ Implemented ]
306+ public void CollectionShouldNotContainItem_ContainsArgumentIsOfOtherTypeThanCollectionArgument_TestNoAnalyzer ( string assertion , string genericType , string containsType )
307+ {
308+ string source = $$ """
309+ using System;
310+ using System.Collections;
311+ using System.Collections.Generic;
312+
313+ using AwesomeAssertions;
314+ using AwesomeAssertions.Extensions;
315+
316+ namespace TestNamespace
317+ {
318+ {{ GenerateCode . ClassImplementsIList ( genericType , $ "public bool Contains({ containsType } item) => true;") }}
319+ public sealed class TestClass
320+ {
321+ public void TestMethod(RandomClass actual, {{ containsType }} expectedItem) =>
322+ {{ assertion }}
323+ }
324+ }
325+ """ ;
326+
327+ DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( source ) ;
328+ }
329+
274330 [ TestMethod ]
275331 [ AssertionCodeFix (
276332 oldAssertion : "actual.Contains(unexpectedItem).Should().BeFalse({0});" ,
@@ -337,23 +393,23 @@ public class CollectionTests
337393 [ AssertionDiagnostic ( "(list.Count + 1).Should().Be(1{0}).And.ToString();" ) ]
338394 [ AssertionDiagnostic ( "(list.Count + 1).Should().Be(expectedSize{0}).And.ToString();" ) ]
339395 [ Implemented ]
340- public void CollectionShouldHaveCount_CountShouldBe_TestNoAnalyzer ( string assertion ) => DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( new StringBuilder ( )
341- . AppendLine ( " using System;" )
342- . AppendLine ( " using System.Collections.Generic;" )
343- . AppendLine ( " using System.Linq;" )
344- . AppendLine ( " using AwesomeAssertions;" )
345- . AppendLine ( " using AwesomeAssertions.Extensions;" )
346- . AppendLine ( " namespace TestNamespace" )
347- . AppendLine ( "{" )
348- . AppendLine ( " public class TestClass" )
349- . AppendLine ( " {" )
350- . AppendLine ( " public void TestMethod(string[] array, List<string> list, int expectedSize)" )
351- . AppendLine ( " {" )
352- . AppendLine ( assertion )
353- . AppendLine ( " }" )
354- . AppendLine ( " }" )
355- . AppendLine ( "}" )
356- . ToString ( ) ) ;
396+ public void CollectionShouldHaveCount_CountShouldBe_TestNoAnalyzer ( string assertion ) => DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( $$ """
397+ using System;
398+ using System.Collections.Generic;
399+ using System.Linq;
400+ using AwesomeAssertions;
401+ using AwesomeAssertions.Extensions;
402+ namespace TestNamespace
403+ {
404+ public class TestClass
405+ {
406+ public void TestMethod(string[] array, List<string> list, int expectedSize)
407+ {
408+ {{ assertion }}
409+ }
410+ }
411+ }
412+ """ ) ;
357413
358414 [ TestMethod ]
359415 [ AssertionDiagnostic ( @"var array = new string[0, 0]; array.Length.Should().Be(0{0});" ) ]
@@ -364,21 +420,21 @@ public void CollectionShouldHaveCount_CountShouldBe_TestNoAnalyzer(string assert
364420 [ AssertionDiagnostic ( @"var array = new string[3, 3, 3]; array.Length.Should().Be(0{0});" ) ]
365421 [ AssertionDiagnostic ( @"int[] array1 = new[] {{ 1, 2, 3 }}; int[] array2 = new[] {{ 4, 5, 6 }}; int[] both = new int[] {{ 1, 2, 3, 4, 5, 6 }}; (array1.Length + array2.Length).Should().Be(both.Length{0});" ) ]
366422 [ Implemented ( Reason = "https://github.com/fluentassertions/fluentassertions.analyzers/issues/309" ) ]
367- public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer ( string assertion ) => DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( new StringBuilder ( )
368- . AppendLine ( " using System;" )
369- . AppendLine ( " using AwesomeAssertions;" )
370- . AppendLine ( " using AwesomeAssertions.Extensions;" )
371- . AppendLine ( " namespace TestNamespace" )
372- . AppendLine ( "{" )
373- . AppendLine ( " public class TestClass" )
374- . AppendLine ( " {" )
375- . AppendLine ( " public void TestMethod()" )
376- . AppendLine ( " {" )
377- . AppendLine ( assertion )
378- . AppendLine ( " }" )
379- . AppendLine ( " }" )
380- . AppendLine ( "}" )
381- . ToString ( ) ) ;
423+ public void CollectionShouldHaveCount_LengthShouldBe_TestNoAnalyzer ( string assertion ) => DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( $$ """
424+ using System;
425+ using AwesomeAssertions;
426+ using AwesomeAssertions.Extensions;
427+ namespace TestNamespace
428+ {
429+ public class TestClass
430+ {
431+ public void TestMethod()
432+ {
433+ {{ assertion }}
434+ }
435+ }
436+ }
437+ """ ) ;
382438
383439 [ TestMethod ]
384440 [ AssertionDiagnostic ( "actual.Should().HaveCount(expected.Count() + 1{0});" ) ]
@@ -988,7 +1044,7 @@ public void CollectionShouldHaveElementAt_ClassImplementsIList_TestAnalyzer(stri
9881044 VisitorName = metadata . Name ,
9891045 Locations =
9901046 [
991- new DiagnosticResultLocation ( "Test0.cs" , 33 , 13 )
1047+ new DiagnosticResultLocation ( "Test0.cs" , 34 , 13 )
9921048 ] ,
9931049 Severity = DiagnosticSeverity . Info
9941050 } ) ;
0 commit comments