1 namespace Castle
.DynamicProxy
.Tests
4 using System
.Collections
;
5 using System
.Reflection
;
6 using Castle
.DynamicProxy
.Generators
;
10 public class MethodFinderTestCase
12 private static void AssertArraysAreEqualUnsorted(object[] expected
, object[] actual
)
14 Assert
.AreEqual(expected
.Length
, actual
.Length
);
15 ArrayList actualAsList
= new ArrayList(actual
);
16 foreach(object expectedElement
in expected
)
18 Assert
.Contains(expectedElement
, actualAsList
);
19 actualAsList
.Remove(expectedElement
);
20 // need to remove the element after it has been found to guarantee that duplicate elements are handled correctly
25 public void AssertArrayAreEqualUnsorted()
27 AssertArraysAreEqualUnsorted(new object[0], new object[0]);
28 AssertArraysAreEqualUnsorted(new object[] {null}
, new object[] {null}
);
29 AssertArraysAreEqualUnsorted(new object[] {null, "one", null}
, new object[] {null, null, "one"}
);
30 AssertArraysAreEqualUnsorted(new object[] {null, "one", null}
, new object[] {"one", null, null}
);
34 AssertArraysAreEqualUnsorted(new object[] {null, "one", null}
, new object[] {"one", "one", null}
);
37 catch(AssertionException
)
43 AssertArraysAreEqualUnsorted(new object[] {null, "one"}
, new object[] {"one", null, null}
);
46 catch(AssertionException
)
52 AssertArraysAreEqualUnsorted(new object[] {null, "one", null}
, new object[] {"one", null}
);
55 catch(AssertionException
)
62 public void GetMethodsForPublic()
64 MethodInfo
[] methods
=
65 MethodFinder
.GetAllInstanceMethods(typeof(object), BindingFlags
.Instance
| BindingFlags
.Public
);
66 MethodInfo
[] realMethods
= typeof(object).GetMethods(BindingFlags
.Instance
| BindingFlags
.Public
);
67 AssertArraysAreEqualUnsorted(realMethods
, methods
);
71 public void GetMethodsForNonPublic()
73 MethodInfo
[] methods
=
74 MethodFinder
.GetAllInstanceMethods(typeof(object), BindingFlags
.Instance
| BindingFlags
.NonPublic
);
75 MethodInfo
[] realMethods
= typeof(object).GetMethods(BindingFlags
.Instance
| BindingFlags
.NonPublic
);
76 AssertArraysAreEqualUnsorted(realMethods
, methods
);
80 public void GetMethodsForPublicAndNonPublic()
82 MethodInfo
[] methods
=
83 MethodFinder
.GetAllInstanceMethods(typeof(object),
84 BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.Public
);
85 MethodInfo
[] realMethods
=
86 typeof(object).GetMethods(BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.Public
);
87 AssertArraysAreEqualUnsorted(realMethods
, methods
);
91 [ExpectedException(typeof(ArgumentException
))]
92 public void GetMethodsThrowsOnStatic()
94 MethodFinder
.GetAllInstanceMethods(typeof(object), BindingFlags
.Static
| BindingFlags
.NonPublic
| BindingFlags
.Public
);
98 [ExpectedException(typeof(ArgumentException
))]
99 public void GetMethodsThrowsOnOtherFlags()
101 MethodFinder
.GetAllInstanceMethods(typeof(object),
102 BindingFlags
.Instance
| BindingFlags
.NonPublic
| BindingFlags
.Public
|
103 BindingFlags
.DeclaredOnly
);