|
3 | 3 |
|
4 | 4 | using VerifyCS = MSTest.Analyzers.Test.CSharpCodeFixVerifier<
|
5 | 5 | MSTest.Analyzers.TypeContainingTestMethodShouldBeATestClassAnalyzer,
|
6 |
| - Microsoft.CodeAnalysis.Testing.EmptyCodeFixProvider>; |
| 6 | + MSTest.Analyzers.AddTestClassFixer>; |
7 | 7 |
|
8 | 8 | namespace MSTest.Analyzers.Test;
|
9 | 9 |
|
@@ -42,7 +42,18 @@ public void TestMethod1() {}
|
42 | 42 | }
|
43 | 43 | """;
|
44 | 44 |
|
45 |
| - await VerifyCS.VerifyAnalyzerAsync(code); |
| 45 | + string fixedCode = """ |
| 46 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 47 | +
|
| 48 | + [TestClass] |
| 49 | + public class MyTestClass |
| 50 | + { |
| 51 | + [TestMethod] |
| 52 | + public void TestMethod1() {} |
| 53 | + } |
| 54 | + """; |
| 55 | + |
| 56 | + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); |
46 | 57 | }
|
47 | 58 |
|
48 | 59 | [TestMethod]
|
@@ -71,7 +82,31 @@ public void TestMethod2()
|
71 | 82 | }
|
72 | 83 | """;
|
73 | 84 |
|
74 |
| - await VerifyCS.VerifyAnalyzerAsync(code); |
| 85 | + string fixedCode = """ |
| 86 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 87 | +
|
| 88 | + [TestClass] |
| 89 | + public class MyTestClass : WithTestMethods_WithoutTestClass |
| 90 | + { |
| 91 | +
|
| 92 | + } |
| 93 | +
|
| 94 | + [TestClass] |
| 95 | + public class WithTestMethods_WithoutTestClass |
| 96 | + { |
| 97 | + [TestMethod] |
| 98 | + public void TestMethod1() |
| 99 | + { |
| 100 | + } |
| 101 | +
|
| 102 | + [TestMethod] |
| 103 | + public void TestMethod2() |
| 104 | + { |
| 105 | + } |
| 106 | + } |
| 107 | + """; |
| 108 | + |
| 109 | + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); |
75 | 110 | }
|
76 | 111 |
|
77 | 112 | [TestMethod]
|
@@ -100,7 +135,31 @@ public void TestMethod2()
|
100 | 135 | }
|
101 | 136 | """;
|
102 | 137 |
|
103 |
| - await VerifyCS.VerifyAnalyzerAsync(code); |
| 138 | + string fixedCode = """ |
| 139 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 140 | +
|
| 141 | + [TestClass] |
| 142 | + public class Base |
| 143 | + { |
| 144 | +
|
| 145 | + } |
| 146 | +
|
| 147 | + [TestClass] |
| 148 | + public class MyTestClass : Base |
| 149 | + { |
| 150 | + [TestMethod] |
| 151 | + public void TestMethod1() |
| 152 | + { |
| 153 | + } |
| 154 | +
|
| 155 | + [TestMethod] |
| 156 | + public void TestMethod2() |
| 157 | + { |
| 158 | + } |
| 159 | + } |
| 160 | + """; |
| 161 | + |
| 162 | + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); |
104 | 163 | }
|
105 | 164 |
|
106 | 165 | [TestMethod]
|
@@ -149,7 +208,24 @@ public void MyTestMethod()
|
149 | 208 | }
|
150 | 209 | """;
|
151 | 210 |
|
152 |
| - await VerifyCS.VerifyAnalyzerAsync(code); |
| 211 | + string fixedCode = """ |
| 212 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 213 | +
|
| 214 | + public class DerivedTestMethod : TestMethodAttribute |
| 215 | + { |
| 216 | + } |
| 217 | +
|
| 218 | + [TestClass] |
| 219 | + public class MyTestClass |
| 220 | + { |
| 221 | + [DerivedTestMethod] |
| 222 | + public void MyTestMethod() |
| 223 | + { |
| 224 | + } |
| 225 | + } |
| 226 | + """; |
| 227 | + |
| 228 | + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); |
153 | 229 | }
|
154 | 230 |
|
155 | 231 | [TestMethod]
|
@@ -192,6 +268,26 @@ public void TestMethod1()
|
192 | 268 | }
|
193 | 269 | """;
|
194 | 270 |
|
195 |
| - await VerifyCS.VerifyAnalyzerAsync(code); |
| 271 | + string fixedCode = """ |
| 272 | + using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 273 | +
|
| 274 | + [TestClass] |
| 275 | + public class TestClass |
| 276 | + { |
| 277 | + [TestInitialize] |
| 278 | + public void Initialize() |
| 279 | + { |
| 280 | +
|
| 281 | + } |
| 282 | +
|
| 283 | + [TestMethod] |
| 284 | + public void TestMethod1() |
| 285 | + { |
| 286 | +
|
| 287 | + } |
| 288 | + } |
| 289 | + """; |
| 290 | + |
| 291 | + await VerifyCS.VerifyCodeFixAsync(code, fixedCode); |
196 | 292 | }
|
197 | 293 | }
|
0 commit comments