1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle
.DynamicProxy
.Tests
18 using System
.Collections
;
19 using System
.Collections
.Generic
;
20 using System
.Reflection
;
21 using Castle
.DynamicProxy
.Generators
;
22 using NUnit
.Framework
;
25 public class MethodComparerTestCase
27 public static void GenericMethod
<T
> () { }
28 public static void GenericMethod2
<T
> () { }
30 public static void GenericMethod3
<T
, H
> (T t
, H h
) { }
34 public static void GenericMethod () { }
35 public static void GenericMethod3
<T
> (T t
) { }
40 public static void GenericMethod3
<T
, H
> (H t
, T h
) { }
44 public void CompareMethods ()
46 MethodSignatureComparer mc
= MethodSignatureComparer
.Instance
;
47 Assert
.IsTrue (mc
.Equals (null, null));
48 Assert
.IsFalse (mc
.Equals (null, typeof (object).GetMethod ("ToString")));
50 Assert
.IsTrue (mc
.Equals (typeof (object).GetMethod ("ToString"), typeof (object).GetMethod ("ToString")));
51 Assert
.IsTrue (mc
.Equals (typeof (List
<>).GetMethod ("get_Count"), typeof (List
<>).GetMethod ("get_Count")));
52 Assert
.IsTrue (mc
.Equals (typeof (List
<int>).GetMethod ("get_Count"), typeof (List
<int>).GetMethod ("get_Count")));
53 Assert
.IsTrue (mc
.Equals (typeof (List
<>).GetMethod ("get_Count"), typeof (List
<int>).GetMethod ("get_Count")));
54 Assert
.IsTrue (mc
.Equals (typeof (List
<string>).GetMethod ("get_Count"), typeof (List
<>).GetMethod ("get_Count")));
55 Assert
.IsTrue (mc
.Equals (typeof (List
<>).GetMethod ("get_Item"), typeof (List
<>).GetMethod ("get_Item")));
57 Assert
.IsTrue (mc
.Equals (typeof (List
<string>).GetMethod ("Add"), typeof (List
<string>).GetMethod ("Add")));
58 Assert
.IsFalse (mc
.Equals (typeof (List
<string>).GetMethod ("Add"), typeof (List
<>).GetMethod ("Add")));
59 Assert
.IsFalse (mc
.Equals (typeof (List
<>).GetMethod ("Add"), typeof (List
<string>).GetMethod ("Add")));
61 Assert
.IsTrue (mc
.Equals (typeof (List
<string>).GetMethod ("get_Item"), typeof (List
<string>).GetMethod ("get_Item")));
62 Assert
.IsFalse (mc
.Equals (typeof (List
<string>).GetMethod ("get_Item"), typeof (List
<>).GetMethod ("get_Item")));
63 Assert
.IsFalse (mc
.Equals (typeof (List
<>).GetMethod ("get_Item"), typeof (List
<string>).GetMethod ("get_Item")));
65 Assert
.IsTrue (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod"), typeof (MethodComparerTestCase
).GetMethod ("GenericMethod")));
66 Assert
.IsTrue (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)),
67 typeof (MethodComparerTestCase
).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int))));
68 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)),
69 typeof (MethodComparerTestCase
).GetMethod ("GenericMethod").MakeGenericMethod (typeof (string))));
70 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod").MakeGenericMethod (typeof (int)),
71 typeof (MethodComparerTestCase
).GetMethod ("GenericMethod")));
72 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod"), typeof (MethodComparerTestCase
).GetMethod ("GenericMethod2")));
74 Assert
.IsTrue (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3"), typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3")));
75 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3"), typeof (NewScope
).GetMethod ("GenericMethod3")));
76 Assert
.IsTrue (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3").MakeGenericMethod (typeof (int), typeof (int)),
77 typeof (NewScope
).GetMethod ("GenericMethod3").MakeGenericMethod (typeof (int), typeof (int))));
79 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3").MakeGenericMethod (typeof (int), typeof (string)),
80 typeof (NewScope
).GetMethod ("GenericMethod3").MakeGenericMethod (typeof (int), typeof (string))));
82 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3").MakeGenericMethod (typeof (int), typeof (string)),
83 typeof (NewScope
).GetMethod ("GenericMethod3").MakeGenericMethod (typeof (string), typeof (int))));
85 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod3"), typeof (FakeScope
).GetMethod ("GenericMethod3")));
87 Assert
.IsFalse (mc
.Equals (typeof (MethodComparerTestCase
).GetMethod ("GenericMethod"), typeof (FakeScope
).GetMethod ("GenericMethod")));
89 Assert
.IsFalse (mc
.Equals (typeof (Console
).GetMethod ("WriteLine", new Type
[] { typeof (object) }
),
90 typeof (Console
).GetMethod ("WriteLine", new Type
[] { typeof (string), typeof (object[]) }
)));
91 Assert
.IsTrue (mc
.Equals (typeof (Console
).GetMethod ("WriteLine", new Type
[] { typeof (string), typeof (object[]) }
),
92 typeof (Console
).GetMethod ("WriteLine", new Type
[] { typeof (string), typeof (object[]) }
)));