@@ -38,6 +38,22 @@ public class CollectionTests
38
38
[ Implemented ]
39
39
public void CollectionsShouldNotBeEmpty_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFixCodeBlock < CollectionShouldNotBeEmptyCodeFix , CollectionShouldNotBeEmptyAnalyzer > ( oldAssertion , newAssertion ) ;
40
40
41
+ [ AssertionDataTestMethod ]
42
+ [ AssertionDiagnostic ( "actual.Any().Should().BeTrue({0});" ) ]
43
+ [ AssertionDiagnostic ( "actual.AsEnumerable().Any().Should().BeTrue({0}).And.ToString();" ) ]
44
+ [ Implemented ]
45
+ public void CollectionsShouldNotBeEmpty_Array_TestAnalyzer ( string assertion ) => VerifyArrayCSharpDiagnosticCodeBlock < CollectionShouldNotBeEmptyAnalyzer > ( assertion ) ;
46
+
47
+ [ AssertionDataTestMethod ]
48
+ [ AssertionCodeFix (
49
+ oldAssertion : "actual.Any().Should().BeTrue({0});" ,
50
+ newAssertion : "actual.Should().NotBeEmpty({0});" ) ]
51
+ [ AssertionCodeFix (
52
+ oldAssertion : "actual.AsEnumerable().Any().Should().BeTrue({0}).And.ToString();" ,
53
+ newAssertion : "actual.AsEnumerable().Should().NotBeEmpty({0}).And.ToString();" ) ]
54
+ [ Implemented ]
55
+ public void CollectionsShouldNotBeEmpty_Array_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyArrayCSharpFixCodeBlock < CollectionShouldNotBeEmptyCodeFix , CollectionShouldNotBeEmptyAnalyzer > ( oldAssertion , newAssertion ) ;
56
+
41
57
[ AssertionDataTestMethod ]
42
58
[ AssertionDiagnostic ( "actual.Any().Should().BeFalse({0});" ) ]
43
59
[ AssertionDiagnostic ( "actual.Should().HaveCount(0{0});" ) ]
@@ -666,6 +682,36 @@ public void CollectionShouldContainSingle_TestAnalyzer_GenericIEnumerableShouldR
666
682
} ) ;
667
683
}
668
684
685
+ private void VerifyArrayCSharpDiagnosticCodeBlock < TDiagnosticAnalyzer > ( string sourceAssertion ) where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
686
+ {
687
+ var source = GenerateCode . GenericArrayCodeBlockAssertion ( sourceAssertion ) ;
688
+
689
+ var type = typeof ( TDiagnosticAnalyzer ) ;
690
+ var diagnosticId = ( string ) type . GetField ( "DiagnosticId" ) . GetValue ( null ) ;
691
+ var message = ( string ) type . GetField ( "Message" ) . GetValue ( null ) ;
692
+
693
+ DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( source , new DiagnosticResult
694
+ {
695
+ Id = diagnosticId ,
696
+ Message = message ,
697
+ Locations = new DiagnosticResultLocation [ ]
698
+ {
699
+ new DiagnosticResultLocation ( "Test0.cs" , 11 , 13 )
700
+ } ,
701
+ Severity = DiagnosticSeverity . Info
702
+ } ) ;
703
+ }
704
+
705
+ private void VerifyArrayCSharpFixCodeBlock < TCodeFixProvider , TDiagnosticAnalyzer > ( string oldSourceAssertion , string newSourceAssertion )
706
+ where TCodeFixProvider : Microsoft . CodeAnalysis . CodeFixes . CodeFixProvider , new ( )
707
+ where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
708
+ {
709
+ var oldSource = GenerateCode . GenericArrayCodeBlockAssertion ( oldSourceAssertion ) ;
710
+ var newSource = GenerateCode . GenericArrayCodeBlockAssertion ( newSourceAssertion ) ;
711
+
712
+ DiagnosticVerifier . VerifyCSharpFix < TCodeFixProvider , TDiagnosticAnalyzer > ( oldSource , newSource ) ;
713
+ }
714
+
669
715
private void VerifyCSharpFixCodeBlock < TCodeFixProvider , TDiagnosticAnalyzer > ( string oldSourceAssertion , string newSourceAssertion )
670
716
where TCodeFixProvider : Microsoft . CodeAnalysis . CodeFixes . CodeFixProvider , new ( )
671
717
where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
0 commit comments