11using Microsoft . CodeAnalysis ;
22using Microsoft . VisualStudio . TestTools . UnitTesting ;
33
4- namespace FluentAssertions . Analyzers . Tests . Tips
4+ namespace FluentAssertions . Analyzers . Tests
55{
66 [ TestClass ]
77 public class ExceptionsTests
88 {
9- [ AssertionDataTestMethod ]
9+ [ AssertionDataTestMethod ]
1010 [ AssertionDiagnostic ( "action.Should().Throw<Exception>().Which.Message.Should().Contain(expectedMessage{0});" ) ]
1111 [ AssertionDiagnostic ( "action.Should().Throw<Exception>().And.Message.Should().Contain(expectedMessage{0});" ) ]
1212 [ AssertionDiagnostic ( "action.Should().Throw<Exception>().Which.Message.Should().Contain(\" a constant string\" {0});" ) ]
@@ -38,7 +38,7 @@ public class ExceptionsTests
3838 newAssertion : "action.Should().Throw<Exception>().WithMessage(\" *a constant string*\" {0});" ) ]
3939 [ AssertionCodeFix (
4040 oldAssertion : "action.Should().Throw<Exception>().And.Message.Should().Contain(\" a constant string\" {0});" ,
41- newAssertion : "action.Should().Throw<Exception>().WithMessage(\" *a constant string*\" {0});" ) ]
41+ newAssertion : "action.Should().Throw<Exception>().WithMessage(\" *a constant string*\" {0});" ) ]
4242 [ AssertionCodeFix (
4343 oldAssertion : "action.Should().Throw<Exception>().Which.Message.Should().Be(expectedMessage{0});" ,
4444 newAssertion : "action.Should().Throw<Exception>().WithMessage(expectedMessage{0});" ) ]
@@ -62,7 +62,7 @@ public class ExceptionsTests
6262 newAssertion : "action.Should().Throw<Exception>().WithMessage(\" a constant string*\" {0});" ) ]
6363 [ AssertionCodeFix (
6464 oldAssertion : "action.Should().Throw<Exception>().And.Message.Should().StartWith(\" a constant string\" {0});" ,
65- newAssertion : "action.Should().Throw<Exception>().WithMessage(\" a constant string*\" {0});" ) ]
65+ newAssertion : "action.Should().Throw<Exception>().WithMessage(\" a constant string*\" {0});" ) ]
6666 [ AssertionCodeFix (
6767 oldAssertion : "action.Should().Throw<Exception>().Which.Message.Should().EndWith(expectedMessage{0});" ,
6868 newAssertion : "action.Should().Throw<Exception>().WithMessage($\" *{{expectedMessage}}\" {0});" ) ]
@@ -74,7 +74,7 @@ public class ExceptionsTests
7474 newAssertion : "action.Should().Throw<Exception>().WithMessage(\" *a constant string\" {0});" ) ]
7575 [ AssertionCodeFix (
7676 oldAssertion : "action.Should().Throw<Exception>().And.Message.Should().EndWith(\" a constant string\" {0});" ,
77- newAssertion : "action.Should().Throw<Exception>().WithMessage(\" *a constant string\" {0});" ) ]
77+ newAssertion : "action.Should().Throw<Exception>().WithMessage(\" *a constant string\" {0});" ) ]
7878 [ Implemented ]
7979 public void ExceptionShouldThrowWithMessage_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < ExceptionShouldThrowWithMessageCodeFix , ExceptionShouldThrowWithMessageAnalyzer > ( oldAssertion , newAssertion ) ;
8080
@@ -134,7 +134,7 @@ public class ExceptionsTests
134134 newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage(\" a constant string*\" {0});" ) ]
135135 [ AssertionCodeFix (
136136 oldAssertion : "action.Should().ThrowExactly<Exception>().And.Message.Should().StartWith(\" a constant string\" {0});" ,
137- newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage(\" a constant string*\" {0});" ) ]
137+ newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage(\" a constant string*\" {0});" ) ]
138138 [ AssertionCodeFix (
139139 oldAssertion : "action.Should().ThrowExactly<Exception>().Which.Message.Should().EndWith(expectedMessage{0});" ,
140140 newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage($\" *{{expectedMessage}}\" {0});" ) ]
@@ -146,14 +146,62 @@ public class ExceptionsTests
146146 newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage(\" *a constant string\" {0});" ) ]
147147 [ AssertionCodeFix (
148148 oldAssertion : "action.Should().ThrowExactly<Exception>().And.Message.Should().EndWith(\" a constant string\" {0});" ,
149- newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage(\" *a constant string\" {0});" ) ]
149+ newAssertion : "action.Should().ThrowExactly<Exception>().WithMessage(\" *a constant string\" {0});" ) ]
150150 [ Implemented ]
151151 public void ExceptionShouldThrowExactlyWithMessage_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < ExceptionShouldThrowWithMessageCodeFix , ExceptionShouldThrowWithMessageAnalyzer > ( oldAssertion , newAssertion ) ;
152152
153- private void VerifyCSharpDiagnostic < TDiagnosticAnalyzer > ( string sourceAssersion ) where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
153+ [ AssertionDataTestMethod ]
154+ [ AssertionDiagnostic ( "action.Should().Throw<Exception>().And.InnerException.Should().BeOfType<ArgumentException>({0});" ) ]
155+ [ AssertionDiagnostic ( "action.Should().Throw<Exception>().Which.InnerException.Should().BeOfType<ArgumentException>({0});" ) ]
156+ [ AssertionDiagnostic ( "action.Should().ThrowExactly<Exception>().And.InnerException.Should().BeOfType<ArgumentException>({0});" ) ]
157+ [ AssertionDiagnostic ( "action.Should().ThrowExactly<Exception>().Which.InnerException.Should().BeOfType<ArgumentException>({0});" ) ]
158+ [ Implemented ]
159+ public void ExceptionShouldThrowWithInnerExceptionExactly_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic < ExceptionShouldThrowWithInnerExceptionAnalyzer > ( assertion ) ;
160+
161+ [ AssertionDataTestMethod ]
162+ [ AssertionCodeFix (
163+ oldAssertion : "action.Should().Throw<Exception>().And.InnerException.Should().BeOfType<ArgumentException>({0});" ,
164+ newAssertion : "action.Should().Throw<Exception>().WithInnerExceptionExactly<ArgumentException>({0});" ) ]
165+ [ AssertionCodeFix (
166+ oldAssertion : "action.Should().Throw<Exception>().Which.InnerException.Should().BeOfType<ArgumentException>({0});" ,
167+ newAssertion : "action.Should().Throw<Exception>().WithInnerExceptionExactly<ArgumentException>({0});" ) ]
168+ [ AssertionCodeFix (
169+ oldAssertion : "action.Should().ThrowExactly<Exception>().And.InnerException.Should().BeOfType<ArgumentException>({0});" ,
170+ newAssertion : "action.Should().ThrowExactly<Exception>().WithInnerExceptionExactly<ArgumentException>({0});" ) ]
171+ [ AssertionCodeFix (
172+ oldAssertion : "action.Should().ThrowExactly<Exception>().Which.InnerException.Should().BeOfType<ArgumentException>({0});" ,
173+ newAssertion : "action.Should().ThrowExactly<Exception>().WithInnerExceptionExactly<ArgumentException>({0});" ) ]
174+ [ Implemented ]
175+ public void ExceptionShouldThrowWithInnerExceptionExactly_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < ExceptionShouldThrowWithInnerExceptionCodeFix , ExceptionShouldThrowWithInnerExceptionAnalyzer > ( oldAssertion , newAssertion ) ;
176+
177+ [ AssertionDataTestMethod ]
178+ [ AssertionDiagnostic ( "action.Should().ThrowExactly<Exception>().And.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ) ]
179+ [ AssertionDiagnostic ( "action.Should().ThrowExactly<Exception>().Which.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ) ]
180+ [ AssertionDiagnostic ( "action.Should().Throw<Exception>().And.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ) ]
181+ [ AssertionDiagnostic ( "action.Should().Throw<Exception>().Which.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ) ]
182+ [ Implemented ]
183+ public void ExceptionShouldThrowWithInnerException_TestAnalyzer ( string assertion ) => VerifyCSharpDiagnostic < ExceptionShouldThrowWithInnerExceptionAnalyzer > ( assertion ) ;
184+
185+ [ AssertionDataTestMethod ]
186+ [ AssertionCodeFix (
187+ oldAssertion : "action.Should().Throw<Exception>().And.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ,
188+ newAssertion : "action.Should().Throw<Exception>().WithInnerException<ArgumentException>({0});" ) ]
189+ [ AssertionCodeFix (
190+ oldAssertion : "action.Should().Throw<Exception>().Which.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ,
191+ newAssertion : "action.Should().Throw<Exception>().WithInnerException<ArgumentException>({0});" ) ]
192+ [ AssertionCodeFix (
193+ oldAssertion : "action.Should().ThrowExactly<Exception>().And.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ,
194+ newAssertion : "action.Should().ThrowExactly<Exception>().WithInnerException<ArgumentException>({0});" ) ]
195+ [ AssertionCodeFix (
196+ oldAssertion : "action.Should().ThrowExactly<Exception>().Which.InnerException.Should().BeAssignableTo<ArgumentException>({0});" ,
197+ newAssertion : "action.Should().ThrowExactly<Exception>().WithInnerException<ArgumentException>({0});" ) ]
198+ [ Implemented ]
199+ public void ExceptionShouldThrowWithInnerException_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix < ExceptionShouldThrowWithInnerExceptionCodeFix , ExceptionShouldThrowWithInnerExceptionAnalyzer > ( oldAssertion , newAssertion ) ;
200+
201+ private void VerifyCSharpDiagnostic < TDiagnosticAnalyzer > ( string sourceAssertion ) where TDiagnosticAnalyzer : Microsoft . CodeAnalysis . Diagnostics . DiagnosticAnalyzer , new ( )
154202 {
155- System . Console . WriteLine ( sourceAssersion ) ;
156- var source = GenerateCode . ExceptionAssertion ( sourceAssersion ) ;
203+ System . Console . WriteLine ( sourceAssertion ) ;
204+ var source = GenerateCode . ExceptionAssertion ( sourceAssertion ) ;
157205
158206 var type = typeof ( TDiagnosticAnalyzer ) ;
159207 var diagnosticId = ( string ) type . GetField ( "DiagnosticId" ) . GetValue ( null ) ;
0 commit comments