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 NUnit
.Framework
;
21 public class ProxyGenerationOptionsTestCase
23 ProxyGenerationOptions _options1
;
24 ProxyGenerationOptions _options2
;
29 _options1
= new ProxyGenerationOptions();
30 _options2
= new ProxyGenerationOptions();
34 public void Equals_EmptyOptions ()
36 Assert
.AreEqual (_options1
, _options2
);
40 public void Equals_EqualNonEmptyOptions ()
42 _options1
= new ProxyGenerationOptions ();
43 _options2
= new ProxyGenerationOptions ();
45 _options1
.BaseTypeForInterfaceProxy
= typeof (IConvertible
);
46 _options2
.BaseTypeForInterfaceProxy
= typeof (IConvertible
);
48 object mixin
= new object ();
49 _options1
.AddMixinInstance (mixin
);
50 _options2
.AddMixinInstance (mixin
);
52 IProxyGenerationHook hook
= new AllMethodsHook ();
53 _options1
.Hook
= hook
;
54 _options2
.Hook
= hook
;
56 IInterceptorSelector selector
= new Castle
.DynamicProxy
.Tests
.SerializableClassTestCase
.SerializableInterceptorSelector ();
57 _options1
.Selector
= selector
;
58 _options2
.Selector
= selector
;
60 _options1
.UseSelector
= true;
61 _options2
.UseSelector
= true;
63 _options1
.UseSingleInterfaceProxy
= true;
64 _options2
.UseSingleInterfaceProxy
= true;
66 Assert
.AreEqual (_options1
, _options2
);
70 public void Equals_DifferentOptions_BaseTypeForInterfaceProxy ()
72 _options1
.BaseTypeForInterfaceProxy
= typeof (IConvertible
);
73 _options2
.BaseTypeForInterfaceProxy
= typeof (object);
75 Assert
.AreNotEqual (_options1
, _options2
);
79 public void Equals_DifferentOptions_AddMixinInstance ()
81 object mixin
= new object ();
82 _options1
.AddMixinInstance (mixin
);
84 Assert
.AreNotEqual (_options1
, _options2
);
88 public void Equals_DifferentOptions_Hook ()
90 IProxyGenerationHook hook
= new GenerationHookTestCase
.LogHook (typeof (object), true);
91 _options1
.Hook
= hook
;
93 Assert
.AreNotEqual (_options1
, _options2
);
97 public void Equals_DifferentOptions_Selector ()
99 IInterceptorSelector selector
= new Castle
.DynamicProxy
.Tests
.SerializableClassTestCase
.SerializableInterceptorSelector ();
100 _options1
.Selector
= selector
;
102 Assert
.AreNotEqual (_options1
, _options2
);
106 public void Equals_DifferentOptions_UseSelector ()
108 _options1
.UseSelector
= true;
109 _options2
.UseSelector
= false;
111 Assert
.AreNotEqual (_options1
, _options2
);
115 public void Equals_DifferentOptions_UseSingleInterfaceProxy ()
117 _options1
.UseSingleInterfaceProxy
= true;
118 _options2
.UseSingleInterfaceProxy
= false;
120 Assert
.AreNotEqual (_options1
, _options2
);
124 public void GetHashCode_EmptyOptions ()
126 Assert
.AreEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
130 public void GetHashCode_EqualNonEmptyOptions ()
132 _options1
= new ProxyGenerationOptions ();
133 _options2
= new ProxyGenerationOptions ();
135 _options1
.BaseTypeForInterfaceProxy
= typeof (IConvertible
);
136 _options2
.BaseTypeForInterfaceProxy
= typeof (IConvertible
);
138 object mixin
= new object ();
139 _options1
.AddMixinInstance (mixin
);
140 _options2
.AddMixinInstance (mixin
);
142 IProxyGenerationHook hook
= new AllMethodsHook ();
143 _options1
.Hook
= hook
;
144 _options2
.Hook
= hook
;
146 IInterceptorSelector selector
= new Castle
.DynamicProxy
.Tests
.SerializableClassTestCase
.SerializableInterceptorSelector ();
147 _options1
.Selector
= selector
;
148 _options2
.Selector
= selector
;
150 _options1
.UseSelector
= true;
151 _options2
.UseSelector
= true;
153 _options1
.UseSingleInterfaceProxy
= true;
154 _options2
.UseSingleInterfaceProxy
= true;
156 Assert
.AreEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
160 public void GetHashCode_DifferentOptions_BaseTypeForInterfaceProxy ()
162 _options1
.BaseTypeForInterfaceProxy
= typeof (IConvertible
);
163 _options2
.BaseTypeForInterfaceProxy
= typeof (object);
165 Assert
.AreNotEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
169 public void GetHashCode_DifferentOptions_AddMixinInstance ()
171 object mixin
= new object ();
172 _options1
.AddMixinInstance (mixin
);
174 Assert
.AreNotEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
178 public void GetHashCode_DifferentOptions_Hook ()
180 IProxyGenerationHook hook
= new GenerationHookTestCase
.LogHook (typeof (object), true);
181 _options1
.Hook
= hook
;
183 Assert
.AreNotEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
187 public void GetHashCode_DifferentOptions_Selector ()
189 IInterceptorSelector selector
= new Castle
.DynamicProxy
.Tests
.SerializableClassTestCase
.SerializableInterceptorSelector ();
190 _options1
.Selector
= selector
;
192 Assert
.AreNotEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
196 public void GetHashCode_DifferentOptions_UseSelector ()
198 _options1
.UseSelector
= true;
199 _options2
.UseSelector
= false;
201 Assert
.AreNotEqual (_options1
.GetHashCode(), _options2
.GetHashCode());
205 public void GetHashCode_DifferentOptions_UseSingleInterfaceProxy ()
207 _options1
.UseSingleInterfaceProxy
= true;
208 _options2
.UseSingleInterfaceProxy
= false;
210 Assert
.AreNotEqual (_options1
.GetHashCode(), _options2
.GetHashCode());