Skip to content

Commit 88bd9b5

Browse files
committed
WIP failing tests.
#190
1 parent b75905d commit 88bd9b5

2 files changed

Lines changed: 80 additions & 3 deletions

File tree

IDisposableAnalyzers.Test/IDISP004DoNotIgnoreCreatedTests/Valid.Using.cs

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace IDisposableAnalyzers.Test.IDISP004DoNotIgnoreCreatedTests
1+
namespace IDisposableAnalyzers.Test.IDISP004DoNotIgnoreCreatedTests
22
{
33
using Gu.Roslyn.Asserts;
44
using NUnit.Framework;
@@ -47,8 +47,65 @@ public void M()
4747
RoslynAssert.Valid(Analyzer, code);
4848
}
4949

50+
[TestCase("await Task.FromResult(new Disposable())")]
51+
[TestCase("await Task.FromResult(new Disposable()).ConfigureAwait(false)")]
52+
[TestCase("await Task.Run(() => new Disposable())")]
53+
[TestCase("await Task.Run(() => new Disposable()).ConfigureAwait(false)")]
54+
[TestCase("await Task.Run(() => new Disposable()).Result")]
55+
[TestCase("await Task.Run(() => new Disposable()).GetAwaiter().GetResult()")]
56+
public static void AwaitSimple(string expression)
57+
{
58+
var code = @"
59+
namespace N
60+
{
61+
using System;
62+
using System.Threading;
63+
using System.Threading.Tasks;
64+
65+
class C
66+
{
67+
public async Task M()
68+
{
69+
using (await Task.FromResult(new Disposable()))
70+
{
71+
}
72+
73+
await Task.Delay(10);
74+
}
75+
}
76+
}".AssertReplace("await Task.FromResult(new Disposable())", expression);
77+
RoslynAssert.Valid(Analyzer, DisposableCode, code);
78+
}
79+
80+
[TestCase("await Task.FromResult(new Disposable())")]
81+
[TestCase("await Task.FromResult(new Disposable()).ConfigureAwait(false)")]
82+
[TestCase("await Task.Run(() => new Disposable())")]
83+
[TestCase("await Task.Run(() => new Disposable()).ConfigureAwait(false)")]
84+
[TestCase("await Task.Run(() => new Disposable()).Result")]
85+
[TestCase("await Task.Run(() => new Disposable()).GetAwaiter().GetResult()")]
86+
public static void AwaitSimpleUsingDeclaration(string expression)
87+
{
88+
var code = @"
89+
namespace N
90+
{
91+
using System;
92+
using System.Threading;
93+
using System.Threading.Tasks;
94+
95+
class C
96+
{
97+
public async Task M()
98+
{
99+
using var disposable = await Task.FromResult(new Disposable());
100+
await Task.Delay(10);
101+
}
102+
}
103+
}".AssertReplace("await Task.FromResult(new Disposable())", expression);
104+
RoslynAssert.Valid(Analyzer, DisposableCode, code);
105+
}
106+
50107
[Test]
51-
public static void SampleWithAwait()
108+
public static void AwaitWeirdCase()
52109
{
53110
var code = @"
54111
namespace N

ValidCode/Async.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// ReSharper disable All
1+
// ReSharper disable All
22
namespace ValidCode
33
{
44
using System;
@@ -49,6 +49,26 @@ public async Task Calls()
4949
using (var disposable = await Task.Run(() => new Disposable()).ConfigureAwait(false))
5050
{
5151
}
52+
53+
using (Task.FromResult(new Disposable()).GetAwaiter().GetResult())
54+
{
55+
}
56+
57+
using (var disposable = Task.FromResult(new Disposable()).GetAwaiter().GetResult())
58+
{
59+
}
60+
61+
using var disposable1 = Task.FromResult(new Disposable()).GetAwaiter().GetResult();
62+
63+
using (Task.FromResult(new Disposable()).Result)
64+
{
65+
}
66+
67+
using (var disposable = Task.FromResult(new Disposable()).Result)
68+
{
69+
}
70+
71+
using var disposable2 = Task.FromResult(new Disposable()).Result;
5272
}
5373

5474
public static async Task<string> Bar1Async()

0 commit comments

Comments
 (0)