@@ -28,11 +28,7 @@ public void SupportExcludingMethods()
2828 [ Implemented ]
2929 public void MsTest_NotReportedAsserts_TestAnalyzer ( string assertion )
3030 {
31- DiagnosticVerifier . VerifyDiagnostic ( new DiagnosticVerifierArguments ( )
32- . WithAllAnalyzers ( )
33- . WithSources ( GenerateCode . MsTestAssertion ( string . Empty , assertion ) )
34- . WithPackageReferences ( PackageReference . AwesomeAssertions_latest , PackageReference . MSTestTestFramework_3_1_1 )
35- ) ;
31+ VerifyNoCSharpDiagnostic ( string . Empty , assertion ) ;
3632 }
3733
3834 [ TestMethod ]
@@ -46,184 +42,184 @@ public void MsTest_NotReportedAsserts_TestAnalyzer(string assertion)
4642 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
4743 [ Implemented ]
4844 public void AssertIsTrue_NestedUsingInNamespace1_TestAnalyzer ( string assertion )
49- => VerifyCSharpDiagnostic ( new StringBuilder ( )
50- . AppendLine ( " using System;" )
51- . AppendLine ( " using AwesomeAssertions;" )
52- . AppendLine ( " using AwesomeAssertions.Extensions;" )
53- . AppendLine ( " using System.Threading.Tasks;" )
54- . AppendLine ( " namespace Microsoft.VisualStudio.TestTools" )
55- . AppendLine ( "{" )
56- . AppendLine ( " using UnitTesting;" )
57- . AppendLine ( " class TestClass" )
58- . AppendLine ( " {" )
59- . AppendLine ( $ " void TestMethod(bool actual)" )
60- . AppendLine ( " {" )
61- . AppendLine ( $ " { assertion } " )
62- . AppendLine ( " }" )
63- . AppendLine ( " }" )
64- . AppendLine ( "}" )
65- . ToString ( ) ) ;
45+ => VerifyCSharpDiagnostic ( $$ """
46+ using System;
47+ using AwesomeAssertions;
48+ using AwesomeAssertions.Extensions;
49+ using System.Threading.Tasks;
50+ namespace Microsoft.VisualStudio
51+ {
52+ using TestTools. UnitTesting;
53+ class TestClass
54+ {
55+ void TestMethod(bool actual)
56+ {
57+ {{ assertion }}
58+ }
59+ }
60+ }
61+ """ ) ;
6662
6763 [ TestMethod ]
6864 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
6965 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
7066 [ Implemented ]
7167 public void AssertIsTrue_NestedUsingInNamespace2_TestAnalyzer ( string assertion )
72- => VerifyCSharpDiagnostic ( new StringBuilder ( )
73- . AppendLine ( " using System;" )
74- . AppendLine ( " using AwesomeAssertions;" )
75- . AppendLine ( " using AwesomeAssertions.Extensions;" )
76- . AppendLine ( " using System.Threading.Tasks;" )
77- . AppendLine ( " namespace Microsoft.VisualStudio" )
78- . AppendLine ( "{" )
79- . AppendLine ( " using TestTools.UnitTesting;" )
80- . AppendLine ( " class TestClass" )
81- . AppendLine ( " {" )
82- . AppendLine ( $ " void TestMethod(bool actual)" )
83- . AppendLine ( " {" )
84- . AppendLine ( $ " { assertion } " )
85- . AppendLine ( " }" )
86- . AppendLine ( " }" )
87- . AppendLine ( "}" )
88- . ToString ( ) ) ;
68+ => VerifyCSharpDiagnostic ( $$ """
69+ using System;
70+ using AwesomeAssertions;
71+ using AwesomeAssertions.Extensions;
72+ using System.Threading.Tasks;
73+ namespace Microsoft.VisualStudio
74+ {
75+ using TestTools.UnitTesting;
76+ class TestClass
77+ {
78+ void TestMethod(bool actual)
79+ {
80+ {{ assertion }}
81+ }
82+ }
83+ }
84+ """ ) ;
8985
9086 [ TestMethod ]
9187 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
9288 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
9389 [ Implemented ]
9490 public void AssertIsTrue_NestedUsingInNamespace3_TestAnalyzer ( string assertion )
95- => VerifyCSharpDiagnostic ( new StringBuilder ( )
96- . AppendLine ( " using System;" )
97- . AppendLine ( " using AwesomeAssertions;" )
98- . AppendLine ( " using AwesomeAssertions.Extensions;" )
99- . AppendLine ( " using System.Threading.Tasks;" )
100- . AppendLine ( " namespace Microsoft" )
101- . AppendLine ( " { namespace VisualStudio {" )
102- . AppendLine ( " using TestTools.UnitTesting;" )
103- . AppendLine ( " class TestClass" )
104- . AppendLine ( " {" )
105- . AppendLine ( $ " void TestMethod(bool actual)" )
106- . AppendLine ( " {" )
107- . AppendLine ( $ " { assertion } " )
108- . AppendLine ( " }" )
109- . AppendLine ( " }}" )
110- . AppendLine ( "}" )
111- . ToString ( ) ) ;
91+ => VerifyCSharpDiagnostic ( $$ """
92+ using System;
93+ using AwesomeAssertions;
94+ using AwesomeAssertions.Extensions;
95+ using System.Threading.Tasks;
96+ namespace Microsoft
97+ { namespace VisualStudio {
98+ using TestTools.UnitTesting;
99+ class TestClass
100+ {
101+ void TestMethod(bool actual)
102+ {
103+ {{ assertion }}
104+ }
105+ } }
106+ }
107+ """ ) ;
112108
113109 [ TestMethod ]
114110 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
115111 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
116112 [ Implemented ]
117113 public void AssertIsTrue_NestedUsingInNamespace4_TestAnalyzer ( string assertion )
118- => VerifyCSharpDiagnostic ( new StringBuilder ( )
119- . AppendLine ( " using System;" )
120- . AppendLine ( " using AwesomeAssertions;" )
121- . AppendLine ( " using AwesomeAssertions.Extensions;" )
122- . AppendLine ( " using System.Threading.Tasks;" )
123- . AppendLine ( " namespace Microsoft" )
124- . AppendLine ( " { namespace VisualStudio {" )
125- . AppendLine ( " using TestTools . UnitTesting;" )
126- . AppendLine ( " class TestClass" )
127- . AppendLine ( " {" )
128- . AppendLine ( $ " void TestMethod(bool actual)" )
129- . AppendLine ( " {" )
130- . AppendLine ( $ " { assertion } " )
131- . AppendLine ( " }" )
132- . AppendLine ( " }}" )
133- . AppendLine ( "}" )
134- . ToString ( ) ) ;
114+ => VerifyCSharpDiagnostic ( $$ """
115+ using System;
116+ using AwesomeAssertions;
117+ using AwesomeAssertions.Extensions;
118+ using System.Threading.Tasks;
119+ namespace Microsoft
120+ { namespace VisualStudio {
121+ using TestTools . UnitTesting;
122+ class TestClass
123+ {
124+ void TestMethod(bool actual)
125+ {
126+ {{ assertion }}
127+ }
128+ } }
129+ }
130+ """ ) ;
135131
136132 [ TestMethod ]
137133 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
138134 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
139135 [ Implemented ]
140136 public void AssertIsTrue_NestedUsingInNamespace5_TestAnalyzer ( string assertion )
141- => VerifyCSharpDiagnostic ( new StringBuilder ( )
142- . AppendLine ( " using System;" )
143- . AppendLine ( " using AwesomeAssertions;" )
144- . AppendLine ( " using AwesomeAssertions.Extensions;" )
145- . AppendLine ( " using System.Threading.Tasks;" )
146- . AppendLine ( " using Microsoft . VisualStudio . TestTools . UnitTesting;" )
147- . AppendLine ( " namespace Testing" )
148- . AppendLine ( "{" )
149- . AppendLine ( " class TestClass" )
150- . AppendLine ( " {" )
151- . AppendLine ( $ " void TestMethod(bool actual)" )
152- . AppendLine ( " {" )
153- . AppendLine ( $ " { assertion } " )
154- . AppendLine ( " }" )
155- . AppendLine ( " }" )
156- . AppendLine ( "}" )
157- . ToString ( ) ) ;
137+ => VerifyCSharpDiagnostic ( $$ """
138+ using System;
139+ using AwesomeAssertions;
140+ using AwesomeAssertions.Extensions;
141+ using System.Threading.Tasks;
142+ using Microsoft . VisualStudio . TestTools . UnitTesting;
143+ namespace Testing
144+ {
145+ class TestClass
146+ {
147+ void TestMethod(bool actual)
148+ {
149+ {{ assertion }}
150+ }
151+ }
152+ }
153+ """ ) ;
158154
159155 [ TestMethod ]
160156 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
161157 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
162158 [ Implemented ]
163159 public void AssertIsTrue_NestedUsingInNamespace6_TestAnalyzer ( string assertion )
164- => VerifyCSharpDiagnostic ( new StringBuilder ( )
165- . AppendLine ( " using System;" )
166- . AppendLine ( " using AwesomeAssertions;" )
167- . AppendLine ( " using AwesomeAssertions.Extensions;" )
168- . AppendLine ( " using System.Threading.Tasks; using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;" )
169- . AppendLine ( " using Microsoft . VisualStudio . TestTools . UnitTesting;" )
170- . AppendLine ( " namespace Testing" )
171- . AppendLine ( "{" )
172- . AppendLine ( " class TestClass" )
173- . AppendLine ( " {" )
174- . AppendLine ( $ " void TestMethod(bool actual)" )
175- . AppendLine ( " {" )
176- . AppendLine ( $ " { assertion } " )
177- . AppendLine ( " }" )
178- . AppendLine ( " }" )
179- . AppendLine ( "}" )
180- . ToString ( ) ) ;
160+ => VerifyCSharpDiagnostic ( $$ """
161+ using System;
162+ using AwesomeAssertions;
163+ using AwesomeAssertions.Extensions;
164+ using System.Threading.Tasks; using static Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
165+ using Microsoft . VisualStudio . TestTools . UnitTesting;
166+ namespace Testing
167+ {
168+ class TestClass
169+ {
170+ void TestMethod(bool actual)
171+ {
172+ {{ assertion }}
173+ }
174+ }
175+ }
176+ """ ) ;
181177
182178 [ TestMethod ]
183179 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
184180 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
185181 [ Implemented ]
186182 public void AssertIsTrue_NestedUsingInNamespace7_TestAnalyzer ( string assertion )
187- => VerifyCSharpDiagnostic ( new StringBuilder ( )
188- . AppendLine ( " using System;" )
189- . AppendLine ( " using AwesomeAssertions;" )
190- . AppendLine ( " using AwesomeAssertions.Extensions;" )
191- . AppendLine ( " using System.Threading.Tasks; using MsAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;" )
192- . AppendLine ( " using Microsoft . VisualStudio . TestTools . UnitTesting;" )
193- . AppendLine ( " namespace Testing" )
194- . AppendLine ( "{" )
195- . AppendLine ( " class TestClass" )
196- . AppendLine ( " {" )
197- . AppendLine ( $ " void TestMethod(bool actual)" )
198- . AppendLine ( " {" )
199- . AppendLine ( $ " { assertion } " )
200- . AppendLine ( " }" )
201- . AppendLine ( " }" )
202- . AppendLine ( "}" )
203- . ToString ( ) ) ;
183+ => VerifyCSharpDiagnostic ( $$ """
184+ using System;
185+ using AwesomeAssertions;
186+ using AwesomeAssertions.Extensions;
187+ using System.Threading.Tasks; using MsAssert = Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
188+ using Microsoft . VisualStudio . TestTools . UnitTesting;
189+ namespace Testing
190+ {
191+ class TestClass
192+ {
193+ void TestMethod(bool actual)
194+ {
195+ {{ assertion }}
196+ }
197+ }
198+ }
199+ """ ) ;
204200
205201 [ TestMethod ]
206202 [ AssertionDiagnostic ( "Assert.IsTrue(actual{0});" ) ]
207203 [ AssertionDiagnostic ( "Assert.IsTrue(bool.Parse(\" true\" ){0});" ) ]
208204 [ Implemented ]
209205 public void AssertIsTrue_NestedUsingInNamespace8_TestAnalyzer ( string assertion )
210- => VerifyCSharpDiagnostic ( new StringBuilder ( )
211- . AppendLine ( " using System;" )
212- . AppendLine ( " using AwesomeAssertions;" )
213- . AppendLine ( " using AwesomeAssertions.Extensions;" )
214- . AppendLine ( " using System.Threading.Tasks;" )
215- . AppendLine ( " namespace Testing" )
216- . AppendLine ( "{" )
217- . AppendLine ( " using Microsoft.VisualStudio.TestTools.UnitTesting;" )
218- . AppendLine ( " class TestClass" )
219- . AppendLine ( " {" )
220- . AppendLine ( $ " void TestMethod(bool actual)" )
221- . AppendLine ( " {" )
222- . AppendLine ( $ " { assertion } " )
223- . AppendLine ( " }" )
224- . AppendLine ( " }" )
225- . AppendLine ( "}" )
226- . ToString ( ) ) ;
206+ => VerifyCSharpDiagnostic ( $$ """
207+ using System;
208+ using AwesomeAssertions;
209+ using AwesomeAssertions.Extensions;
210+ using System.Threading.Tasks;
211+ namespace Testing
212+ {
213+ using Microsoft.VisualStudio.TestTools.UnitTesting;
214+ class TestClass
215+ {
216+ void TestMethod(bool actual)
217+ {
218+ {{ assertion }}
219+ }
220+ }
221+ }
222+ """ ) ;
227223
228224 [ TestMethod ]
229225 [ AssertionCodeFix (
@@ -860,28 +856,50 @@ public void AssertThrowsExceptionAsync_TestCodeFix(string oldAssertion, string n
860856 [ Implemented ]
861857 public void StringAssertDoesNotMatch_TestCodeFix ( string oldAssertion , string newAssertion ) => VerifyCSharpFix ( "string actual, System.Text.RegularExpressions.Regex pattern" , oldAssertion , newAssertion ) ;
862858
863- private void VerifyCSharpDiagnostic ( string source )
859+ [ TestMethod ]
860+ [ AssertionDiagnostic ( "throw new AssertFailedException();" ) ]
861+ [ Implemented ]
862+ public void ThrowAssertFailedException_TestAnalyzer ( string assertion )
863+ => VerifyCSharpDiagnostic ( string . Empty , assertion ) ;
864+
865+ [ TestMethod ]
866+ [ AssertionDiagnostic ( "throw new AssertInconclusiveException();" ) ]
867+ [ Implemented ]
868+ public void ThrowAssertInconclusiveException_TestNoAnalyzer ( string assertion )
869+ => VerifyNoCSharpDiagnostic ( string . Empty , assertion ) ;
870+
871+ private static void VerifyCSharpDiagnostic ( string source )
864872 {
865- DiagnosticVerifier . VerifyDiagnostic ( new DiagnosticVerifierArguments ( )
866- . WithAllAnalyzers ( )
867- . WithSources ( source )
868- . WithPackageReferences ( PackageReference . AwesomeAssertions_latest , PackageReference . MSTestTestFramework_3_1_1 )
869- . WithExpectedDiagnostics ( new DiagnosticResult
873+ VerifyCSharpDiagnosticUsingAllAnalyzers ( source ,
874+ new DiagnosticResult
870875 {
871876 Id = AssertAnalyzer . MSTestsRule . Id ,
872877 Message = AssertAnalyzer . Message ,
873- Locations = new DiagnosticResultLocation [ ]
874- {
878+ Locations =
879+ [
875880 new DiagnosticResultLocation ( "Test0.cs" , 12 , 13 )
876- } ,
881+ ] ,
877882 Severity = DiagnosticSeverity . Info
878- } )
883+ } ) ;
884+ }
885+
886+ private static void VerifyCSharpDiagnosticUsingAllAnalyzers ( string source , params DiagnosticResult [ ] expectedDiagnostics )
887+ {
888+ DiagnosticVerifier . VerifyDiagnostic ( new DiagnosticVerifierArguments ( )
889+ . WithAllAnalyzers ( )
890+ . WithSources ( source )
891+ . WithPackageReferences ( PackageReference . AwesomeAssertions_latest , PackageReference . MSTestTestFramework_3_1_1 )
892+ . WithExpectedDiagnostics ( expectedDiagnostics )
879893 ) ;
880894 }
881- private void VerifyCSharpDiagnostic ( string methodArguments , string assertion )
895+
896+ private static void VerifyCSharpDiagnostic ( string methodArguments , string assertion )
882897 => VerifyCSharpDiagnostic ( GenerateCode . MsTestAssertion ( methodArguments , assertion ) ) ;
883898
884- private void VerifyCSharpFix ( string methodArguments , string oldAssertion , string newAssertion )
899+ private static void VerifyNoCSharpDiagnostic ( string methodArguments , string assertion )
900+ => VerifyCSharpDiagnosticUsingAllAnalyzers ( GenerateCode . MsTestAssertion ( methodArguments , assertion ) ) ;
901+
902+ private static void VerifyCSharpFix ( string methodArguments , string oldAssertion , string newAssertion )
885903 {
886904 var oldSource = GenerateCode . MsTestAssertion ( methodArguments , oldAssertion ) ;
887905 var newSource = GenerateCode . MsTestAssertion ( methodArguments , newAssertion ) ;
0 commit comments