Skip to content

Commit fd48232

Browse files
committed
Tests for await using
1 parent db9d104 commit fd48232

File tree

2 files changed

+56
-0
lines changed
  • IDisposableAnalyzers.NetCoreTests/IDISP004DontIgnoreReturnValueOfTypeIDisposableTests
  • ValidCode.NetCore/AsyncDisposable

2 files changed

+56
-0
lines changed

IDisposableAnalyzers.NetCoreTests/IDISP004DontIgnoreReturnValueOfTypeIDisposableTests/Valid.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,43 @@ public static class Valid
99
{
1010
private static readonly DiagnosticAnalyzer Analyzer = new CreationAnalyzer();
1111

12+
[Test]
13+
public static void AwaitUsing()
14+
{
15+
var asyncDisposable = @"
16+
namespace N
17+
{
18+
using System;
19+
using System.IO;
20+
using System.Threading.Tasks;
21+
22+
public class AsyncDisposable : IAsyncDisposable
23+
{
24+
private readonly IAsyncDisposable disposable = File.OpenRead(string.Empty);
25+
26+
public async ValueTask DisposeAsync()
27+
{
28+
await this.disposable.DisposeAsync().ConfigureAwait(false);
29+
}
30+
}
31+
}";
32+
var code = @"
33+
namespace N
34+
{
35+
using System.Threading.Tasks;
36+
37+
class C
38+
{
39+
public async Task M()
40+
{
41+
await using var asyncDisposable = new AsyncDisposable();
42+
}
43+
}
44+
}
45+
";
46+
RoslynAssert.Valid(Analyzer, asyncDisposable, code);
47+
}
48+
1249
[Test]
1350
public static void ILoggerFactoryAddApplicationInsights()
1451
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace ValidCode.NetCore.AsyncDisposable
2+
{
3+
using System.Threading.Tasks;
4+
5+
class AwaitUsing
6+
{
7+
public async void M1()
8+
{
9+
await using var impl1 = new Impl1();
10+
await using var impl2 = new Impl2();
11+
}
12+
13+
public async Task M2()
14+
{
15+
await using var impl1 = new Impl1();
16+
await using var impl2 = new Impl2();
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)