Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mcs / tests / test-async-77.cs
1 using System;
2 using System.Threading.Tasks;
3
4 public class Class1
5 {
6         protected void InvokeAction (Action action)
7         {
8                 action ();
9         }
10
11         public void Bar()
12         {
13         }
14
15         async Task Test ()
16         {
17                 Task.Run(async () =>
18                         {
19                                 var implementor = ServiceLocator.GetImplementor<IInterface1> ();
20                                 string message = null;
21                                 bool result = await implementor.Foo ((s) => message = s);
22
23                                 InvokeAction (() => Bar ());
24                         }).Wait ();
25         }
26
27         interface IInterface1
28         {
29                 Task<bool> Foo(Action<string> action);
30         }
31
32         class CIInterface1 : IInterface1
33         {
34                 public Task<bool> Foo (Action<string> action)
35                 {
36                         action ("msg");
37                         return Task.FromResult (false);
38                 }
39         }
40
41         static class ServiceLocator
42         {
43                 public static TService GetImplementor<TService>() where TService : class
44                 {
45                         return (TService) (object) new CIInterface1 ();
46                 }
47         }
48
49         public static void Main ()
50         {
51                 new Class1 ().Test ().Wait ();
52         }
53 }
54