Files
coverlet/test/coverlet.core.tests/Samples/Instrumentation.AsyncAwait.cs
T
Marco Rossignoli e251d23a39 Fix and simplify async coverage (#549)
Fix and simplify async coverage
2019-09-23 11:00:31 +02:00

88 lines
2.1 KiB
C#

// Remember to use full name because adding new using directives change line numbers
using System.Threading.Tasks;
namespace Coverlet.Core.Samples.Tests
{
public class AsyncAwait
{
async public Task<int> AsyncExecution(bool skipLast)
{
int res = 0;
res += await Async();
res += await Async();
if (!skipLast)
{
res += await Async();
}
return res;
}
async public Task<int> Async()
{
await Task.Delay(1000);
return 42;
}
async public Task SyncExecution()
{
await Sync();
}
public Task Sync()
{
return Task.CompletedTask;
}
async public Task<int> AsyncExecution(int val)
{
int res = 0;
switch (val)
{
case 1:
{
res += await Async();
break;
}
case 2:
{
res += await Async() + await Async();
break;
}
case 3:
{
res += await Async() + await Async() +
await Async();
break;
}
case 4:
{
res += await Async() + await Async() +
await Async() + await Async();
break;
}
default:
break;
}
return res;
}
async public Task<int> ContinuationNotCalled()
{
int res = 0;
res += await Async().ContinueWith(x => x.Result);
return res;
}
async public Task<int> ContinuationCalled()
{
int res = 0;
res += await Async().ContinueWith(x => x.Result);
return res;
}
}
}