Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-async-35.cs
1 using System;
2 using System.Reflection;
3 using System.Threading.Tasks;
4 using System.Runtime.CompilerServices;
5 using System.Linq;
6
7 namespace N.M
8 {
9         class C
10         {
11                 public static async Task<int> AsyncMethod ()
12                 {
13                         await Task.Delay (1);
14                         return 0;
15                 }
16
17                 public static async Task NestedAsyncAnonymousMethod ()
18                 {
19                         Action a = async delegate {
20                                 await Task.Yield();
21                         };
22
23                         await Task.Yield();
24                 }
25
26                 public static int Main ()
27                 {
28                         var m = typeof (C).GetMethod ("AsyncMethod");
29                         var attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
30                         if (attr == null)
31                                 return 1;
32
33                         if (attr.StateMachineType == null)
34                                 return 2;
35
36                         Func<Task<int>> a = async () => await AsyncMethod ();
37
38                         var c = typeof (C).GetMethods (BindingFlags.NonPublic | BindingFlags.Static).Where (l =>
39                                 l.IsDefined (typeof (AsyncStateMachineAttribute))).Count ();
40
41                         if (c != 1)
42                                 return 3;
43
44
45                         m = typeof (C).GetMethod ("NestedAsyncAnonymousMethod");
46                         attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
47                         if (attr == null)
48                                 return 10;
49
50                         if (attr.StateMachineType == null)
51                                 return 11;
52
53                         var n = typeof (C).GetNestedTypes (BindingFlags.NonPublic).Single (l => l.Name.Contains ("NestedAsyncAnonymousMethod"));
54                         if (n == null)
55                                 return 12;
56
57                         m = n.GetMethods (BindingFlags.NonPublic | BindingFlags.Static).Single (l => l.Name.Contains ("m__"));
58
59                         attr = m.GetCustomAttribute<AsyncStateMachineAttribute> ();
60                         if (attr == null)
61                                 return 13;
62
63                         if (attr.StateMachineType == null)
64                                 return 14;
65
66                         return 0;
67                 }
68         }
69 }