BindingFlags.Public needed here as Exception.HResult is now public in .NET 4.5. This...
[mono.git] / mcs / tests / test-async-32.cs
1 using System;
2 using System.Threading;
3 using System.Threading.Tasks;
4
5 class Program
6 {
7         static async Task<int> TestCanceled()
8         {
9                 await Task.FromResult(1);
10                 throw new OperationCanceledException();
11         }
12
13         static async Task TestCanceled_2()
14         {
15                 await Task.FromResult(1);
16                 throw new OperationCanceledException();
17         }
18
19         static async Task<int> TestException()
20         {
21                 await Task.FromResult(1);
22                 throw new ApplicationException();
23         }
24
25         static int Main()
26         {
27                 bool canceled = false;
28                 var t = TestCanceled().ContinueWith(l =>
29                 {
30                         canceled = l.IsCanceled;
31                 }, TaskContinuationOptions.ExecuteSynchronously);
32
33                 t.Wait();
34
35                 if (!canceled)
36                         return 1;
37
38                 if (t.Exception != null)
39                         return 2;
40
41                 t = TestCanceled_2().ContinueWith(l =>
42                 {
43                         canceled = l.IsCanceled;
44                 }, TaskContinuationOptions.ExecuteSynchronously);
45
46                 t.Wait();
47
48                 if (!canceled)
49                         return 11;
50
51                 if (t.Exception != null)
52                         return 12;
53
54                 bool faulted = false;
55                 t = TestException().ContinueWith(l =>
56                 {
57                         faulted = l.IsFaulted;
58                 }, TaskContinuationOptions.ExecuteSynchronously);
59
60                 if (!faulted)
61                         return 21;
62
63                 if (t.Exception != null)
64                         return 22;
65
66                 Console.WriteLine("ok");
67                 return 0;
68         }
69 }