linux-packaging-mono/mcs/tests/test-async-32.cs
Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

75 lines
1.3 KiB
C#

using System;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static async Task<int> TestCanceled()
{
await Task.FromResult(1);
throw new OperationCanceledException();
}
static async Task TestCanceled_2()
{
await Task.FromResult(1);
throw new OperationCanceledException();
}
static async Task<int> TestException()
{
await Task.FromResult(1);
throw new ApplicationException();
}
public static int Main()
{
bool canceled = false;
var t = TestCanceled().ContinueWith(l =>
{
canceled = l.IsCanceled;
}, TaskContinuationOptions.ExecuteSynchronously);
t.Wait();
if (!canceled)
return 1;
if (t.Exception != null)
return 2;
t = TestCanceled_2().ContinueWith(l =>
{
canceled = l.IsCanceled;
}, TaskContinuationOptions.ExecuteSynchronously);
t.Wait();
if (!canceled)
return 11;
if (t.Exception != null)
return 12;
bool faulted = false;
bool has_exception = false;
t = TestException().ContinueWith(l =>
{
faulted = l.IsFaulted;
has_exception = l.Exception != null; // Has to observe it or will throw on shutdown
}, TaskContinuationOptions.ExecuteSynchronously);
if (!faulted)
return 21;
if (!has_exception)
return 22;
if (t.Exception != null)
return 23;
Console.WriteLine("ok");
return 0;
}
}