@@ -21,7 +21,7 @@ public class NumericTests
21
21
oldAssertion : "actual.Should().BeGreaterThan(0{0}).ToString();" ,
22
22
newAssertion : "actual.Should().BePositive({0}).ToString();" ) ]
23
23
[ 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 ) ;
25
25
26
26
[ DataTestMethod ]
27
27
[ AssertionDiagnostic ( "actual.Should().BeLessThan(0{0});" ) ]
@@ -37,7 +37,7 @@ public class NumericTests
37
37
oldAssertion : "actual.Should().BeLessThan(0{0}).ToString();" ,
38
38
newAssertion : "actual.Should().BeNegative({0}).ToString();" ) ]
39
39
[ 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 ) ;
41
41
42
42
[ DataTestMethod ]
43
43
[ AssertionDiagnostic ( "actual.Should().BeGreaterOrEqualTo(lower{0}).And.BeLessOrEqualTo(upper);" ) ]
@@ -51,6 +51,27 @@ public class NumericTests
51
51
[ Implemented ]
52
52
public void NumericShouldBeInRange_BeLessOrEqualToAndBeGreaterOrEqualTo_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic ( assertion , DiagnosticMetadata . NumericShouldBeInRange_BeLessOrEqualToAndBeGreaterOrEqualTo ) ;
53
53
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
+
54
75
[ DataTestMethod ]
55
76
[ AssertionCodeFix (
56
77
oldAssertion : "actual.Should().BeGreaterOrEqualTo(lower{0}).And.BeLessOrEqualTo(upper);" ,
@@ -65,7 +86,7 @@ public class NumericTests
65
86
oldAssertion : "actual.Should().BeLessOrEqualTo(upper).And.BeGreaterOrEqualTo(lower{0});" ,
66
87
newAssertion : "actual.Should().BeInRange(lower, upper{0});" ) ]
67
88
[ 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 ) ;
69
90
70
91
[ DataTestMethod ]
71
92
[ AssertionDiagnostic ( "Math.Abs(expected - actual).Should().BeLessOrEqualTo(delta{0});" ) ]
@@ -77,33 +98,56 @@ public class NumericTests
77
98
oldAssertion : "Math.Abs(expected - actual).Should().BeLessOrEqualTo(delta{0});" ,
78
99
newAssertion : "actual.Should().BeApproximately(expected, delta{0});" ) ]
79
100
[ 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 ) ;
81
102
82
103
private void VerifyCSharpDiagnostic ( string sourceAssertion , DiagnosticMetadata metadata )
83
104
{
84
- var source = GenerateCode . DoubleAssertion ( sourceAssertion ) ;
105
+ VerifyCSharpDiagnostic ( sourceAssertion , metadata , "double" ) ;
106
+ VerifyCSharpDiagnostic ( sourceAssertion , metadata , "float" ) ;
107
+ VerifyCSharpDiagnostic ( sourceAssertion , metadata , "decimal" ) ;
108
+ }
85
109
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
92
119
{
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" ) ;
97
137
}
98
138
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 )
102
140
{
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 ) ;
105
143
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
+ ) ;
107
151
}
108
152
}
109
153
}
0 commit comments