@@ -21,7 +21,7 @@ public class NumericTests
2121 oldAssertion : "actual.Should().BeGreaterThan(0{0}).ToString();" ,
2222 newAssertion : "actual.Should().BePositive({0}).ToString();" ) ]
2323 [ Implemented ]
24- public void NumericShouldBePositive_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < FluentAssertionsCodeFix , FluentAssertionsOperationAnalyzer > ( oldAssertion , newAssertion ) ;
24+ public void NumericShouldBePositive_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix ( oldAssertion , newAssertion ) ;
2525
2626 [ DataTestMethod ]
2727 [ AssertionDiagnostic ( "actual.Should().BeLessThan(0{0});" ) ]
@@ -37,7 +37,7 @@ public class NumericTests
3737 oldAssertion : "actual.Should().BeLessThan(0{0}).ToString();" ,
3838 newAssertion : "actual.Should().BeNegative({0}).ToString();" ) ]
3939 [ Implemented ]
40- public void NumericShouldBeNegative_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < FluentAssertionsCodeFix , FluentAssertionsOperationAnalyzer > ( oldAssertion , newAssertion ) ;
40+ public void NumericShouldBeNegative_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix ( oldAssertion , newAssertion ) ;
4141
4242 [ DataTestMethod ]
4343 [ AssertionDiagnostic ( "actual.Should().BeGreaterOrEqualTo(lower{0}).And.BeLessOrEqualTo(upper);" ) ]
@@ -51,6 +51,27 @@ public class NumericTests
5151 [ Implemented ]
5252 public void NumericShouldBeInRange_BeLessOrEqualToAndBeGreaterOrEqualTo_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic ( assertion , DiagnosticMetadata . NumericShouldBeInRange_BeLessOrEqualToAndBeGreaterOrEqualTo ) ;
5353
54+ [ DataTestMethod ]
55+ [ DataRow ( "actual.Should().BeLessOrEqualTo(upper, \" because reason 1\" ).And.BeGreaterOrEqualTo(lower, \" because reason 2\" );" ) ]
56+ [ DataRow ( "actual.Should().BeLessOrEqualTo(upper, \" because reason 1\" ).And.BeGreaterOrEqualTo(lower, \" because reason 2\" );" ) ]
57+ [ Implemented ]
58+ public void NumericShouldBeInRange_BeLessOrEqualToAndBeGreaterOrEqualTo_WithMessagesInBothAssertions_TestAnalyzer ( string assertion )
59+ {
60+ verifyNoDiagnostic ( "double" ) ;
61+ verifyNoDiagnostic ( "float" ) ;
62+ verifyNoDiagnostic ( "decimal" ) ;
63+
64+ void verifyNoDiagnostic ( string type )
65+ {
66+ var source = GenerateCode . NumericAssertion ( assertion , type ) ;
67+ DiagnosticVerifier . VerifyDiagnostic ( new DiagnosticVerifierArguments ( )
68+ . WithSources ( source )
69+ . WithAllAnalyzers ( )
70+ . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 )
71+ ) ;
72+ }
73+ }
74+
5475 [ DataTestMethod ]
5576 [ AssertionCodeFix (
5677 oldAssertion : "actual.Should().BeGreaterOrEqualTo(lower{0}).And.BeLessOrEqualTo(upper);" ,
@@ -65,7 +86,7 @@ public class NumericTests
6586 oldAssertion : "actual.Should().BeLessOrEqualTo(upper).And.BeGreaterOrEqualTo(lower{0});" ,
6687 newAssertion : "actual.Should().BeInRange(lower, upper{0});" ) ]
6788 [ NotImplemented ]
68- public void NumericShouldBeInRange_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < FluentAssertionsCodeFix , FluentAssertionsOperationAnalyzer > ( oldAssertion , newAssertion ) ;
89+ public void NumericShouldBeInRange_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix ( oldAssertion , newAssertion ) ;
6990
7091 [ DataTestMethod ]
7192 [ AssertionDiagnostic ( "Math.Abs(expected - actual).Should().BeLessOrEqualTo(delta{0});" ) ]
@@ -77,33 +98,56 @@ public class NumericTests
7798 oldAssertion : "Math.Abs(expected - actual).Should().BeLessOrEqualTo(delta{0});" ,
7899 newAssertion : "actual.Should().BeApproximately(expected, delta{0});" ) ]
79100 [ Implemented ]
80- public void NumericShouldBeApproximately_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < FluentAssertionsCodeFix , FluentAssertionsOperationAnalyzer > ( oldAssertion , newAssertion ) ;
101+ public void NumericShouldBeApproximately_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix ( oldAssertion , newAssertion ) ;
81102
82103 private void VerifyCSharpDiagnostic ( string sourceAssertion , DiagnosticMetadata metadata )
83104 {
84- var source = GenerateCode . DoubleAssertion ( sourceAssertion ) ;
105+ VerifyCSharpDiagnostic ( sourceAssertion , metadata , "double" ) ;
106+ VerifyCSharpDiagnostic ( sourceAssertion , metadata , "float" ) ;
107+ VerifyCSharpDiagnostic ( sourceAssertion , metadata , "decimal" ) ;
108+ }
85109
86- DiagnosticVerifier . VerifyCSharpDiagnosticUsingAllAnalyzers ( source , new DiagnosticResult
87- {
88- Id = FluentAssertionsOperationAnalyzer . DiagnosticId ,
89- Message = metadata . Message ,
90- VisitorName = metadata . Name ,
91- Locations = new DiagnosticResultLocation [ ]
110+ private void VerifyCSharpDiagnostic ( string sourceAssertion , DiagnosticMetadata metadata , string numericType )
111+ {
112+ var source = GenerateCode . NumericAssertion ( sourceAssertion , numericType ) ;
113+
114+ DiagnosticVerifier . VerifyDiagnostic ( new DiagnosticVerifierArguments ( )
115+ . WithSources ( source )
116+ . WithAllAnalyzers ( )
117+ . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 )
118+ . WithExpectedDiagnostics ( new DiagnosticResult
92119 {
93- new DiagnosticResultLocation ( "Test0.cs" , 10 , 13 )
94- } ,
95- Severity = DiagnosticSeverity . Info
96- } ) ;
120+ Id = FluentAssertionsOperationAnalyzer . DiagnosticId ,
121+ Message = metadata . Message ,
122+ VisitorName = metadata . Name ,
123+ Locations = new DiagnosticResultLocation [ ]
124+ {
125+ new DiagnosticResultLocation ( "Test0.cs" , 10 , 13 )
126+ } ,
127+ Severity = DiagnosticSeverity . Info
128+ } )
129+ ) ;
130+ }
131+
132+ private void VerifyCSharpFix ( string oldSourceAssertion , string newSourceAssertion )
133+ {
134+ VerifyCSharpFix ( oldSourceAssertion , newSourceAssertion , "double" ) ;
135+ VerifyCSharpFix ( oldSourceAssertion , newSourceAssertion , "float" ) ;
136+ VerifyCSharpFix ( oldSourceAssertion , newSourceAssertion , "decimal" ) ;
97137 }
98138
99- private void VerifyCSharpFix < TCodeFixProvider , TDiagnosticAnalyzer > ( string oldSourceAssertion , string newSourceAssertion )
100- where TCodeFixProvider : Microsoft . CodeAnalysis . CodeFixes . CodeFixProvider , new ( )
101- where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
139+ private void VerifyCSharpFix ( string oldSourceAssertion , string newSourceAssertion , string numericType )
102140 {
103- var oldSource = GenerateCode . DoubleAssertion ( oldSourceAssertion ) ;
104- var newSource = GenerateCode . DoubleAssertion ( newSourceAssertion ) ;
141+ var oldSource = GenerateCode . NumericAssertion ( oldSourceAssertion , numericType ) ;
142+ var newSource = GenerateCode . NumericAssertion ( newSourceAssertion , numericType ) ;
105143
106- DiagnosticVerifier . VerifyCSharpFix < TCodeFixProvider , TDiagnosticAnalyzer > ( oldSource , newSource ) ;
144+ DiagnosticVerifier . VerifyFix ( new CodeFixVerifierArguments ( )
145+ . WithCodeFixProvider < FluentAssertionsCodeFix > ( )
146+ . WithDiagnosticAnalyzer < FluentAssertionsOperationAnalyzer > ( )
147+ . WithSources ( oldSource )
148+ . WithFixedSources ( newSource )
149+ . WithPackageReferences ( PackageReference . FluentAssertions_6_12_0 )
150+ ) ;
107151 }
108152 }
109153}
0 commit comments