Fixed test issue - PEVerify is now called with a quoted assembly path (to allow for...
[castle.git] / Tools / Castle.DynamicProxy2 / Castle.DynamicProxy.Tests / MethodFinderTestCase.cs
blobc776145004219d1b6b5e4b959f62f6aaf641bac7
1 namespace Castle.DynamicProxy.Tests
3 using System;
4 using System.Collections;
5 using System.Reflection;
6 using Castle.DynamicProxy.Generators;
7 using NUnit.Framework;
9 [TestFixture]
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
24 [Test]
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});
32 try
34 AssertArraysAreEqualUnsorted(new object[] {null, "one", null}, new object[] {"one", "one", null});
35 Assert.Fail();
37 catch(AssertionException)
39 // ok
41 try
43 AssertArraysAreEqualUnsorted(new object[] {null, "one"}, new object[] {"one", null, null});
44 Assert.Fail();
46 catch(AssertionException)
48 // ok
50 try
52 AssertArraysAreEqualUnsorted(new object[] {null, "one", null}, new object[] {"one", null});
53 Assert.Fail();
55 catch(AssertionException)
57 // ok
61 [Test]
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);
70 [Test]
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);
79 [Test]
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);
90 [Test]
91 [ExpectedException(typeof(ArgumentException))]
92 public void GetMethodsThrowsOnStatic()
94 MethodFinder.GetAllInstanceMethods(typeof(object), BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public);
97 [Test]
98 [ExpectedException(typeof(ArgumentException))]
99 public void GetMethodsThrowsOnOtherFlags()
101 MethodFinder.GetAllInstanceMethods(typeof(object),
102 BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public |
103 BindingFlags.DeclaredOnly);