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

Commit

Permalink
Add tests for the non-generic ValueTask return type
Browse files Browse the repository at this point in the history
  • Loading branch information
sharwell committed Aug 6, 2018
1 parent a770626 commit 5473b23
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,21 @@ public async Task TestReturnValueTaskAsync()
string testCode = @"
using System.Threading.Tasks;
class ClassName
{
ValueTask FirstMethod() { return default; }
ValueTask SecondMethodAsync() { return default; }
}
";

await this.VerifyCSharpDiagnosticAsync(testCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestReturnGenericValueTaskAsync()
{
string testCode = @"
using System.Threading.Tasks;
class ClassName
{
ValueTask<int> FirstMethod() { return new ValueTask<int>(3); }
ValueTask<int> SecondMethodAsync() { return new ValueTask<int>(3); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,32 @@ class ClassName
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestReturnValueTaskAsync()
{
string testCode = @"
using System.Threading.Tasks;
class ClassName
{
ValueTask FirstMethod() { return default; }
ValueTask SecondMethodAsync() { return default; }
}
";
string fixedCode = @"
using System.Threading.Tasks;
class ClassName
{
ValueTask FirstMethodAsync() { return default; }
ValueTask SecondMethodAsync() { return default; }
}
";

DiagnosticResult expected = this.CSharpDiagnostic().WithArguments("FirstMethod").WithLocation(5, 20);
await this.VerifyCSharpDiagnosticAsync(testCode, expected, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpDiagnosticAsync(fixedCode, EmptyDiagnosticResults, CancellationToken.None).ConfigureAwait(false);
await this.VerifyCSharpFixAsync(testCode, fixedCode, cancellationToken: CancellationToken.None).ConfigureAwait(false);
}

[Fact]
public async Task TestReturnGenericValueTaskAsync()
{
Expand Down

0 comments on commit 5473b23

Please sign in to comment.