Another dist build fix for rx integration, move *.cs file to safe-ish path.
[mono-project.git] / mcs / tests / test-async-32.cs
blobf0e3fc64870f8d1954df2e65932cf256b770c310
1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
5 class Program
7 static async Task<int> TestCanceled()
9 await Task.FromResult(1);
10 throw new OperationCanceledException();
13 static async Task TestCanceled_2()
15 await Task.FromResult(1);
16 throw new OperationCanceledException();
19 static async Task<int> TestException()
21 await Task.FromResult(1);
22 throw new ApplicationException();
25 static int Main()
27 bool canceled = false;
28 var t = TestCanceled().ContinueWith(l =>
30 canceled = l.IsCanceled;
31 }, TaskContinuationOptions.ExecuteSynchronously);
33 t.Wait();
35 if (!canceled)
36 return 1;
38 if (t.Exception != null)
39 return 2;
41 t = TestCanceled_2().ContinueWith(l =>
43 canceled = l.IsCanceled;
44 }, TaskContinuationOptions.ExecuteSynchronously);
46 t.Wait();
48 if (!canceled)
49 return 11;
51 if (t.Exception != null)
52 return 12;
54 bool faulted = false;
55 bool has_exception = false;
56 t = TestException().ContinueWith(l =>
58 faulted = l.IsFaulted;
59 has_exception = l.Exception != null; // Has to observe it or will throw on shutdown
60 }, TaskContinuationOptions.ExecuteSynchronously);
62 if (!faulted)
63 return 21;
65 if (!has_exception)
66 return 22;
68 if (t.Exception != null)
69 return 23;
71 Console.WriteLine("ok");
72 return 0;