Skip to content

Commit

Permalink
Added AccessingTaskResultWithoutAwait_ObjectInitializer test
Browse files Browse the repository at this point in the history
  • Loading branch information
Vannevelj committed May 10, 2020
1 parent 8a819ca commit 8c73c21
Showing 1 changed file with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,5 +328,52 @@ async Task MyMethod()
VerifyDiagnostic(original, "Use await to get the result of a Task.");
VerifyFix(original, result);
}

[TestMethod]
public void AccessingTaskResultWithoutAwait_ObjectInitializer()
{
var original = @"
using System;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class MyClass
{
async Task MyMethod()
{
Console.Write(new {
Prop = Get().Result
});
}
async Task<int> Get() => 5;
}
}";

var result = @"
using System;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class MyClass
{
async Task MyMethod()
{
Console.Write(new {
Prop = await Get()
});
}
async Task<int> Get() => 5;
}
}";

VerifyDiagnostic(original, "Use await to get the result of a Task.");
VerifyFix(original, result);
}
}
}

0 comments on commit 8c73c21

Please # to comment.