2 using System.Threading.Tasks;
3 using System.Threading;
4 using System.Reflection;
9 async Task<int> TestException_1 ()
11 await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
15 async Task TestException_2 ()
17 await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
20 async Task TestException_3 ()
22 Func<Task> a = async () => await Task.Factory.StartNew (() => { throw new ApplicationException (); }).ConfigureAwait (false);
23 await a ().ConfigureAwait (false);
26 async Task<int> TestException_4 ()
29 await Task.Factory.StartNew (() => 5).ConfigureAwait (false);
31 throw new ApplicationException ();
35 async Task<int> TestException_5 ()
39 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
41 } catch (ArgumentException) {
45 throw new ApplicationException ();
51 async Task<int> TestException_6 ()
54 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
55 } catch (ArgumentException) {
56 throw new ApplicationException ();
62 async Task<int> TestException_7 ()
65 await Task.Factory.StartNew (() => { throw new ArgumentException (); }).ConfigureAwait (false);
66 } catch (ArgumentException e) {
67 if (e.StackTrace.Contains (".MoveNext"))
68 throw new ApplicationException ();
74 static bool RunTest (MethodInfo test)
76 Console.Write ("Running test {0, -25}", test.Name);
78 Task t = test.Invoke (new Tester (), null) as Task;
80 if (!Task.WaitAll (new[] { t }, 1000)) {
81 Console.WriteLine ("FAILED (Timeout)");
84 } catch (AggregateException) {
87 if (t.Status != TaskStatus.Faulted) {
88 Console.WriteLine ("FAILED (Status={0})", t.Status);
92 if (!(t.Exception.InnerException is ApplicationException)) {
93 Console.WriteLine ("FAILED with wrong exception");
97 Console.WriteLine ("OK");
99 } catch (Exception e) {
100 Console.WriteLine ("FAILED");
101 Console.WriteLine (e.ToString ());
106 public static int Main ()
108 var tests = from test in typeof (Tester).GetMethods (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly)
109 where test.GetParameters ().Length == 0
111 select RunTest (test);
113 int failures = tests.Count (a => !a);
114 Console.WriteLine (failures + " tests failed");