2 using System
.Threading
.Tasks
;
3 using System
.Threading
;
4 using System
.Reflection
;
6 using System
.Collections
.Generic
;
8 class Base
: IDisposable
10 protected static int dispose_counter
;
12 public void Dispose ()
20 async Task
<int> SwitchTest_1 ()
22 switch (await Task
.Factory
.StartNew (() => "X").ConfigureAwait (false)) {
38 async Task
<int> Using_1 ()
40 using (Base a
= await Task
.Factory
.StartNew (() => new Base ()).ConfigureAwait (false),
41 b
= await Task
.Factory
.StartNew (() => new Tester ()).ConfigureAwait (false),
42 c
= await Task
.Factory
.StartNew (() => new Base ()).ConfigureAwait (false),
43 d
= await Task
.Factory
.StartNew (() => new Base ()).ConfigureAwait (false)) {
46 if (dispose_counter
!= 4)
52 async Task
<int> Foreach_1 ()
55 foreach (var e
in await Task
.Factory
.StartNew (() => new List
<int> () { 1, 2, 3 }
).ConfigureAwait (false)) {
62 static bool RunTest (MethodInfo test
)
64 Console
.Write ("Running test {0, -25}", test
.Name
);
66 Task t
= test
.Invoke (new Tester (), null) as Task
;
67 if (!Task
.WaitAll (new[] { t }
, 1000)) {
68 Console
.WriteLine ("FAILED (Timeout)");
72 var ti
= t
as Task
<int>;
75 Console
.WriteLine ("FAILED (Result={0})", ti
.Result
);
79 var tb
= t
as Task
<bool>;
82 Console
.WriteLine ("FAILED (Result={0})", tb
.Result
);
88 Console
.WriteLine ("OK");
90 } catch (Exception e
) {
91 Console
.WriteLine ("FAILED");
92 Console
.WriteLine (e
.ToString ());
97 public static int Main ()
99 var tests
= from test
in typeof (Tester
).GetMethods (BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.DeclaredOnly
)
100 where test
.GetParameters ().Length
== 0
102 select RunTest (test
);
104 int failures
= tests
.Count (a
=> !a
);
105 Console
.WriteLine (failures
+ " tests failed");