Skip to content
This repository was archived by the owner on Nov 8, 2018. It is now read-only.

Commit ca7bcad

Browse files
committed
Add tests for the non-generic ValueTask return type
1 parent a770626 commit ca7bcad

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/Naming/AvoidAsyncSuffixUnitTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,21 @@ public async Task TestReturnValueTaskAsync()
346346
string testCode = @"
347347
using System.Threading.Tasks;
348348
class ClassName
349+
{
350+
ValueTask FirstMethod() { return default(ValueTask); }
351+
ValueTask SecondMethodAsync() { return default(ValueTask); }
352+
}
353+
";
354+
355+
await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
356+
}
357+
358+
[Fact]
359+
public async Task TestReturnGenericValueTaskAsync()
360+
{
361+
string testCode = @"
362+
using System.Threading.Tasks;
363+
class ClassName
349364
{
350365
ValueTask<int> FirstMethod() { return new ValueTask<int>(3); }
351366
ValueTask<int> SecondMethodAsync() { return new ValueTask<int>(3); }

AsyncUsageAnalyzers/AsyncUsageAnalyzers.Test/Naming/UseAsyncSuffixUnitTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,32 @@ class ClassName
346346
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
347347
}
348348

349+
[Fact]
350+
public async Task TestReturnValueTaskAsync()
351+
{
352+
string testCode = @"
353+
using System.Threading.Tasks;
354+
class ClassName
355+
{
356+
ValueTask FirstMethod() { return default(ValueTask); }
357+
ValueTask SecondMethodAsync() { return default(ValueTask); }
358+
}
359+
";
360+
string fixedCode = @"
361+
using System.Threading.Tasks;
362+
class ClassName
363+
{
364+
ValueTask FirstMethodAsync() { return default(ValueTask); }
365+
ValueTask SecondMethodAsync() { return default(ValueTask); }
366+
}
367+
";
368+
369+
DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("FirstMethod").WithLocation(5, 15);
370+
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
371+
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
372+
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
373+
}
374+
349375
[Fact]
350376
public async Task TestReturnGenericValueTaskAsync()
351377
{

0 commit comments

Comments
 (0)