main
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Reflection;
5
6namespace tests
7{
8 static class TestRunner
9 {
10 static public void run_stacked<Delegate>(this Type target, object instance)
11 {
12 var stack = new Stack<Type>();
13 target.class_hierarchy(x => stack.Push(x));
14 stack.each(x => x.run_single<Delegate>(instance));
15 }
16
17 static public void run_single<Delegate>(this IReflect target, object instance)
18 {
19 var fields = target.collect_fields_of_type<Delegate>();
20 if (fields.Count() > 0)
21 {
22 fields
23 .First()
24 .GetValue(instance)
25 .downcast_to<System.Delegate>()
26 .DynamicInvoke();
27 }
28 }
29
30 static public void run_all<Delegate>(this IReflect target, object target_instance)
31 {
32 target
33 .collect_fields_of_type<Delegate>()
34 .each(x =>
35 {
36 try
37 {
38 x.invoke_delegate_on(target_instance);
39 Console.Out.WriteLine(" {0}", x);
40 }
41 catch (Exception e)
42 {
43 Console.Out.WriteLine(":FAILED {0}", x);
44 throw e.InnerException;
45 }
46 });
47 }
48
49 static public void run(this KeyValuePair<string, it> specification)
50 {
51 try
52 {
53 specification.Value();
54 Console.Out.WriteLine(" it {0}", specification.Key);
55 }
56 catch
57 {
58 Console.Out.WriteLine(":FAILED it {0}", specification.Key);
59 throw;
60 }
61 }
62 }
63}