@@ -34,6 +34,7 @@ public void TestMethod()
34
34
Assert.That(false, Is.False);
35
35
Console.WriteLine(""Next Statement"");
36
36
}" ) ;
37
+
37
38
var fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
38
39
public void TestMethod()
39
40
{
@@ -44,12 +45,36 @@ public void TestMethod()
44
45
});
45
46
Console.WriteLine(""Next Statement"");
46
47
}" ) ;
47
- RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode ) ;
48
+
49
+ RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertMultiple ) ;
50
+
51
+ #if NUNIT4
52
+ fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
53
+ public void TestMethod()
54
+ {
55
+ using (Assert.EnterMultipleScope())
56
+ {
57
+ Assert.That(true, Is.True);
58
+ Assert.That(false, Is.False);
59
+ }
60
+ Console.WriteLine(""Next Statement"");
61
+ }" ) ;
62
+
63
+ RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertEnterMultipleScope ) ;
64
+ #endif
48
65
}
49
66
50
67
[ Test ]
51
68
public void VerifyPartlyIndependent ( )
52
69
{
70
+ const string ConfigurationClass = @"
71
+ private sealed class Configuration
72
+ {
73
+ public int Value1 { get; set; }
74
+ public double Value2 { get; set; }
75
+ public string Value11 { get; set; } = string.Empty;
76
+ }" ;
77
+
53
78
var code = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
54
79
public void Test()
55
80
{
@@ -59,14 +84,8 @@ public void Test()
59
84
Assert.That(configuration.Value2, Is.EqualTo(0.0));
60
85
Assert.That(configuration.Value11, Is.EqualTo(string.Empty));
61
86
configuration = null;
62
- }
87
+ }" + ConfigurationClass ) ;
63
88
64
- private sealed class Configuration
65
- {
66
- public int Value1 { get; set; }
67
- public double Value2 { get; set; }
68
- public string Value11 { get; set; } = string.Empty;
69
- }" ) ;
70
89
var fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
71
90
public void Test()
72
91
{
@@ -79,40 +98,54 @@ public void Test()
79
98
Assert.That(configuration.Value11, Is.EqualTo(string.Empty));
80
99
});
81
100
configuration = null;
101
+ }" + ConfigurationClass ) ;
102
+
103
+ RoslynAssert . FixAll ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertMultiple ) ;
104
+
105
+ #if NUNIT4
106
+ fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
107
+ public void Test()
108
+ {
109
+ var configuration = new Configuration();
110
+ Assert.That(configuration, Is.Not.Null);
111
+ using (Assert.EnterMultipleScope())
112
+ {
113
+ Assert.That(configuration.Value1, Is.EqualTo(0));
114
+ Assert.That(configuration.Value2, Is.EqualTo(0.0));
115
+ Assert.That(configuration.Value11, Is.EqualTo(string.Empty));
116
+ }
117
+ configuration = null;
118
+ }" + ConfigurationClass ) ;
119
+
120
+ RoslynAssert . FixAll ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertEnterMultipleScope ) ;
121
+ #endif
82
122
}
83
123
124
+ [ Test ]
125
+ public void AddsAsyncWhenAwaitIsUsed ( )
126
+ {
127
+ const string ConfigurationClass = @"
84
128
private sealed class Configuration
85
129
{
86
130
public int Value1 { get; set; }
87
131
public double Value2 { get; set; }
88
132
public string Value11 { get; set; } = string.Empty;
89
- }" ) ;
90
- RoslynAssert . FixAll ( analyzer , fix , expectedDiagnostic , code , fixedCode ) ;
91
- }
133
+ public Task<string> AsStringAsync() => Task.FromResult(Value11);
134
+ }" ;
92
135
93
- [ Test ]
94
- public void AddsAsyncWhenAwaitIsUsed ( )
95
- {
96
136
var code = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
97
- public void Test()
137
+ public async Task Test()
98
138
{
99
139
var configuration = new Configuration();
100
140
Assert.That(configuration, Is.Not.Null);
101
141
↓Assert.That(configuration.Value1, Is.EqualTo(0));
102
142
Assert.That(configuration.Value2, Is.EqualTo(0.0));
103
143
Assert.That(await configuration.AsStringAsync(), Is.EqualTo(string.Empty));
104
144
configuration = null;
105
- }
145
+ }" + ConfigurationClass ) ;
106
146
107
- private sealed class Configuration
108
- {
109
- public int Value1 { get; set; }
110
- public double Value2 { get; set; }
111
- public string Value11 { get; set; } = string.Empty;
112
- public Task<string> AsStringAsync() => Task.FromResult(Value11);
113
- }" ) ;
114
147
var fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
115
- public void Test()
148
+ public async Task Test()
116
149
{
117
150
var configuration = new Configuration();
118
151
Assert.That(configuration, Is.Not.Null);
@@ -123,16 +156,30 @@ public void Test()
123
156
Assert.That(await configuration.AsStringAsync(), Is.EqualTo(string.Empty));
124
157
});
125
158
configuration = null;
126
- }
159
+ }" + ConfigurationClass ) ;
127
160
128
- private sealed class Configuration
161
+ // The test method itself no longer awaits, so CS1998 is generated.
162
+ // Fixing this is outside the scope of this analyzer and there could be other non-touched statements that are waited.
163
+ RoslynAssert . FixAll ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertMultiple ,
164
+ Settings . Default . WithAllowedCompilerDiagnostics ( AllowedCompilerDiagnostics . WarningsAndErrors ) ) ;
165
+
166
+ #if NUNIT4
167
+ fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
168
+ public async Task Test()
129
169
{
130
- public int Value1 { get; set; }
131
- public double Value2 { get; set; }
132
- public string Value11 { get; set; } = string.Empty;
133
- public Task<string> AsStringAsync() => Task.FromResult(Value11);
134
- }" ) ;
135
- RoslynAssert . FixAll ( analyzer , fix , expectedDiagnostic , code , fixedCode ) ;
170
+ var configuration = new Configuration();
171
+ Assert.That(configuration, Is.Not.Null);
172
+ using (Assert.EnterMultipleScope())
173
+ {
174
+ Assert.That(configuration.Value1, Is.EqualTo(0));
175
+ Assert.That(configuration.Value2, Is.EqualTo(0.0));
176
+ Assert.That(await configuration.AsStringAsync(), Is.EqualTo(string.Empty));
177
+ }
178
+ configuration = null;
179
+ }" + ConfigurationClass ) ;
180
+
181
+ RoslynAssert . FixAll ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertEnterMultipleScope ) ;
182
+ #endif
136
183
}
137
184
138
185
[ Test ]
@@ -152,6 +199,7 @@ public void TestMethod()
152
199
Assert.That(False, Is.False);{ newline }
153
200
{ preComment } Console.WriteLine(""Next Statement"");{ postComment }
154
201
}}" ) ;
202
+
155
203
var fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @$ "
156
204
public void TestMethod()
157
205
{{
@@ -166,30 +214,67 @@ public void TestMethod()
166
214
}});{ newline }
167
215
{ preComment } Console.WriteLine(""Next Statement"");{ postComment }
168
216
}}" ) ;
169
- RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode ) ;
217
+
218
+ RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertMultiple ) ;
219
+
220
+ #if NUNIT4
221
+ fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @$ "
222
+ public void TestMethod()
223
+ {{
224
+ const bool True = true;
225
+ const bool False = false;
226
+
227
+ using (Assert.EnterMultipleScope())
228
+ {{
229
+ // Verify that our bool constants are correct
230
+ Assert.That(True, Is.True);
231
+ Assert.That(False, Is.False);
232
+ }}{ newline }
233
+ { preComment } Console.WriteLine(""Next Statement"");{ postComment }
234
+ }}" ) ;
235
+
236
+ RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertEnterMultipleScope ) ;
237
+ #endif
170
238
}
171
239
172
240
[ Test ]
173
241
public void VerifyKeepsTrivia ( )
174
242
{
175
- var code = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @$ "
243
+ var code = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
176
244
public void TestMethod()
177
- {{
178
- // Verify that boolean work as expected
245
+ {
246
+ // Verify that boolean work as expected
179
247
↓Assert.That(true, Is.True);
180
248
Assert.That(false, Is.False);
181
- }}" ) ;
182
- var fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @$ "
249
+ }" ) ;
250
+
251
+ var fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
183
252
public void TestMethod()
184
- {{
253
+ {
185
254
Assert.Multiple(() =>
186
- {{
255
+ {
187
256
// Verify that boolean work as expected
188
257
Assert.That(true, Is.True);
189
258
Assert.That(false, Is.False);
190
- }});
191
- }}" ) ;
192
- RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode ) ;
259
+ });
260
+ }" ) ;
261
+
262
+ RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertMultiple ) ;
263
+
264
+ #if NUNIT4
265
+ fixedCode = TestUtility . WrapMethodInClassNamespaceAndAddUsings ( @"
266
+ public void TestMethod()
267
+ {
268
+ using (Assert.EnterMultipleScope())
269
+ {
270
+ // Verify that boolean work as expected
271
+ Assert.That(true, Is.True);
272
+ Assert.That(false, Is.False);
273
+ }
274
+ }" ) ;
275
+
276
+ RoslynAssert . CodeFix ( analyzer , fix , expectedDiagnostic , code , fixedCode , UseAssertMultipleCodeFix . WrapWithAssertEnterMultipleScope ) ;
277
+ #endif
193
278
}
194
279
}
195
280
}
0 commit comments