Skip to content

Commit be0c6a9

Browse files
committed
Update SA1519 for asynchronous streams
1 parent 8154da4 commit be0c6a9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

StyleCop.Analyzers/StyleCop.Analyzers.Test.CSharp8/LayoutRules/SA1519CSharp8UnitTests.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,52 @@
33

44
namespace StyleCop.Analyzers.Test.CSharp8.LayoutRules
55
{
6+
using System.Threading;
7+
using System.Threading.Tasks;
68
using StyleCop.Analyzers.Test.CSharp7.LayoutRules;
9+
using Xunit;
10+
using static StyleCop.Analyzers.Test.Verifiers.StyleCopCodeFixVerifier<
11+
StyleCop.Analyzers.LayoutRules.SA1519BracesMustNotBeOmittedFromMultiLineChildStatement,
12+
StyleCop.Analyzers.LayoutRules.SA1503CodeFixProvider>;
713

814
public partial class SA1519CSharp8UnitTests : SA1519CSharp7UnitTests
915
{
16+
[Fact]
17+
[WorkItem(3007, "https://github.com/DotNetAnalyzers/StyleCopAnalyzers/issues/3007")]
18+
public async Task TestAwaitForEachMultiLineChildRequiresBracesAsync()
19+
{
20+
var testCode = @"
21+
using System.Collections.Generic;
22+
using System.Threading.Tasks;
23+
24+
public class TestClass
25+
{
26+
public async Task TestAsync(IAsyncEnumerable<int> values)
27+
{
28+
await foreach (var value in values)
29+
{|#0:System.Console.WriteLine(
30+
value);|}
31+
}
32+
}
33+
";
34+
var fixedCode = @"
35+
using System.Collections.Generic;
36+
using System.Threading.Tasks;
37+
38+
public class TestClass
39+
{
40+
public async Task TestAsync(IAsyncEnumerable<int> values)
41+
{
42+
await foreach (var value in values)
43+
{
44+
System.Console.WriteLine(
45+
value);
46+
}
47+
}
48+
}
49+
";
50+
51+
await VerifyCSharpFixAsync(testCode, Diagnostic().WithLocation(0), fixedCode, CancellationToken.None).ConfigureAwait(false);
52+
}
1053
}
1154
}

0 commit comments

Comments
 (0)