1 // Copyright 2004-2007 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 using System
.Text
.RegularExpressions
;
17 namespace Castle
.DynamicProxy
.Tests
20 using System
.Collections
;
22 using System
.Reflection
;
23 using System
.Runtime
.Serialization
;
24 using System
.Runtime
.Serialization
.Formatters
.Binary
;
25 using Castle
.Core
.Interceptor
;
26 using Castle
.DynamicProxy
.Serialization
;
27 using Castle
.DynamicProxy
.Tests
.Classes
;
28 using Castle
.DynamicProxy
.Tests
;
29 using Castle
.DynamicProxy
.Tests
.BugsReported
;
30 using Castle
.DynamicProxy
.Tests
.InterClasses
;
31 using NUnit
.Framework
;
36 public class SerializableClassTestCase
: BasePEVerifyTestCase
38 public override void Init ()
41 ProxyObjectReference
.ResetScope ();
44 public override void TearDown ()
47 ProxyObjectReference
.ResetScope ();
51 public void CreateSerializable()
53 MySerializableClass proxy
= (MySerializableClass
)
54 generator
.CreateClassProxy(typeof(MySerializableClass
), new StandardInterceptor());
56 Assert
.IsTrue(proxy
.GetType().IsSerializable
);
60 public void ImplementsISerializable()
62 MySerializableClass proxy
= (MySerializableClass
)
63 generator
.CreateClassProxy(typeof(MySerializableClass
), new StandardInterceptor());
65 Assert
.IsTrue(proxy
is ISerializable
);
69 public void SimpleProxySerialization()
71 MySerializableClass proxy
= (MySerializableClass
)
72 generator
.CreateClassProxy(typeof(MySerializableClass
), new StandardInterceptor());
74 DateTime current
= proxy
.Current
;
76 MySerializableClass otherProxy
= (MySerializableClass
) SerializeAndDeserialize(proxy
);
78 Assert
.AreEqual(current
, otherProxy
.Current
);
82 public void SerializationDelegate()
84 MySerializableClass2 proxy
= (MySerializableClass2
)
85 generator
.CreateClassProxy(typeof(MySerializableClass2
), new StandardInterceptor());
87 DateTime current
= proxy
.Current
;
89 MySerializableClass2 otherProxy
= (MySerializableClass2
) SerializeAndDeserialize(proxy
);
91 Assert
.AreEqual(current
, otherProxy
.Current
);
95 public void SimpleInterfaceProxy()
98 generator
.CreateInterfaceProxyWithTarget(typeof(IMyInterface2
), new MyInterfaceImpl(), new StandardInterceptor());
100 Assert
.IsTrue(proxy
.GetType().IsSerializable
);
102 IMyInterface2 inter
= (IMyInterface2
) proxy
;
105 Assert
.AreEqual("opa", inter
.Name
);
106 inter
.Started
= true;
107 Assert
.AreEqual(true, inter
.Started
);
109 IMyInterface2 otherProxy
= (IMyInterface2
) SerializeAndDeserialize(proxy
);
111 Assert
.AreEqual(inter
.Name
, otherProxy
.Name
);
112 Assert
.AreEqual(inter
.Started
, otherProxy
.Started
);
117 public void SimpleInterfaceProxy_WithoutTarget()
120 generator
.CreateInterfaceProxyWithoutTarget(typeof(IMyInterface2
), new Type
[] {typeof(IMyInterface)}
,
121 new StandardInterceptor());
123 Assert
.IsTrue(proxy
is IMyInterface2
);
124 Assert
.IsTrue(proxy
is IMyInterface
);
127 object otherProxy
= SerializeAndDeserialize(proxy
);
129 Assert
.IsTrue(otherProxy
is IMyInterface2
);
130 Assert
.IsTrue(otherProxy
is IMyInterface
);
134 public void CustomMarkerInterface()
136 object proxy
= generator
.CreateClassProxy(typeof(ClassWithMarkerInterface
),
137 new Type
[] {typeof(IMarkerInterface)}
,
138 new StandardInterceptor());
140 Assert
.IsNotNull(proxy
);
141 Assert
.IsTrue(proxy
is IMarkerInterface
);
143 object otherProxy
= SerializeAndDeserialize(proxy
);
145 Assert
.IsTrue(otherProxy
is IMarkerInterface
);
149 public void HashtableSerialization()
151 object proxy
= generator
.CreateClassProxy(
152 typeof(Hashtable
), new StandardInterceptor());
154 Assert
.IsTrue(typeof(Hashtable
).IsAssignableFrom(proxy
.GetType()));
156 (proxy
as Hashtable
).Add("key", "helloooo!");
158 Hashtable otherProxy
= (Hashtable
) SerializeAndDeserialize(proxy
);
160 Assert
.IsTrue(otherProxy
.ContainsKey("key"));
161 Assert
.AreEqual("helloooo!", otherProxy
["key"]);
164 public static T SerializeAndDeserialize
<T
>(T proxy
)
166 MemoryStream stream
= new MemoryStream();
167 BinaryFormatter formatter
= new BinaryFormatter();
168 formatter
.Serialize(stream
, proxy
);
170 return (T
) formatter
.Deserialize(stream
);
187 public void SerializatingObjectsWithoutDefaultConstructor ()
189 C proxy
= (C
) generator
.CreateClassProxy (typeof (C
), new IInterceptor
[] { new StandardInterceptor () }
, 1);
190 C otherProxy
= (C
) SerializeAndDeserialize (proxy
);
192 Assert
.AreEqual (proxy
.I
, otherProxy
.I
);
193 Assert
.AreSame (otherProxy
, otherProxy
.This
);
197 public class EventHandlerClass
199 public void TestHandler (object sender
, EventArgs e
)
206 public class DelegateHolder
208 public EventHandler DelegateMember
;
209 public ArrayList ComplexTypeMember
;
211 public DelegateHolder ()
215 public void TestHandler (object sender
, EventArgs e
)
221 public class IndirectDelegateHolder
223 public DelegateHolder DelegateHolder
= new DelegateHolder();
225 public void TestHandler (object sender
, EventArgs e
)
231 public void SerializeObjectsWithDelegateToOtherObject ()
233 EventHandlerClass eventHandlerInstance
= new EventHandlerClass();
234 DelegateHolder proxy
= (DelegateHolder
) generator
.CreateClassProxy (typeof (DelegateHolder
), new IInterceptor
[] {new StandardInterceptor ()}
);
236 proxy
.DelegateMember
= new EventHandler(eventHandlerInstance
.TestHandler
);
237 proxy
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
238 proxy
.ComplexTypeMember
.Add (eventHandlerInstance
);
240 Assert
.IsNotNull (proxy
.DelegateMember
);
241 Assert
.IsNotNull (proxy
.DelegateMember
.Target
);
243 Assert
.IsNotNull (proxy
.ComplexTypeMember
);
244 Assert
.AreEqual (4, proxy
.ComplexTypeMember
.Count
);
245 Assert
.AreEqual (1, proxy
.ComplexTypeMember
[0]);
246 Assert
.AreEqual (2, proxy
.ComplexTypeMember
[1]);
247 Assert
.AreEqual (3, proxy
.ComplexTypeMember
[2]);
248 Assert
.AreSame (proxy
.ComplexTypeMember
[3], proxy
.DelegateMember
.Target
);
250 DelegateHolder otherProxy
= (DelegateHolder
) (SerializeAndDeserialize (proxy
));
252 Assert
.IsNotNull (otherProxy
.DelegateMember
);
253 Assert
.IsNotNull (otherProxy
.DelegateMember
.Target
);
255 Assert
.IsNotNull (otherProxy
.ComplexTypeMember
);
256 Assert
.AreEqual (4, otherProxy
.ComplexTypeMember
.Count
);
257 Assert
.AreEqual (1, otherProxy
.ComplexTypeMember
[0]);
258 Assert
.AreEqual (2, otherProxy
.ComplexTypeMember
[1]);
259 Assert
.AreEqual (3, otherProxy
.ComplexTypeMember
[2]);
260 Assert
.AreSame (otherProxy
.ComplexTypeMember
[3], otherProxy
.DelegateMember
.Target
);
264 public void SerializeObjectsWithDelegateToThisObject ()
266 DelegateHolder proxy
= (DelegateHolder
) generator
.CreateClassProxy (typeof (DelegateHolder
), new IInterceptor
[] { new StandardInterceptor () }
);
268 proxy
.DelegateMember
= new EventHandler (proxy
.TestHandler
);
269 proxy
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
271 Assert
.IsNotNull (proxy
.DelegateMember
);
272 Assert
.AreSame (proxy
, proxy
.DelegateMember
.Target
);
274 Assert
.IsNotNull (proxy
.ComplexTypeMember
);
275 Assert
.AreEqual (3, proxy
.ComplexTypeMember
.Count
);
276 Assert
.AreEqual (1, proxy
.ComplexTypeMember
[0]);
277 Assert
.AreEqual (2, proxy
.ComplexTypeMember
[1]);
278 Assert
.AreEqual (3, proxy
.ComplexTypeMember
[2]);
280 DelegateHolder otherProxy
= (DelegateHolder
) (SerializeAndDeserialize (proxy
));
282 Assert
.IsNotNull (otherProxy
.DelegateMember
);
283 Assert
.AreSame (otherProxy
, otherProxy
.DelegateMember
.Target
);
285 Assert
.IsNotNull (otherProxy
.ComplexTypeMember
);
286 Assert
.AreEqual (3, otherProxy
.ComplexTypeMember
.Count
);
287 Assert
.AreEqual (1, otherProxy
.ComplexTypeMember
[0]);
288 Assert
.AreEqual (2, otherProxy
.ComplexTypeMember
[1]);
289 Assert
.AreEqual (3, otherProxy
.ComplexTypeMember
[2]);
293 public void SerializeObjectsWithIndirectDelegateToThisObject ()
295 IndirectDelegateHolder proxy
= (IndirectDelegateHolder
) generator
.CreateClassProxy (typeof (IndirectDelegateHolder
),
296 new IInterceptor
[] { new StandardInterceptor () }
);
298 proxy
.DelegateHolder
.DelegateMember
= new EventHandler (proxy
.TestHandler
);
299 proxy
.DelegateHolder
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
301 Assert
.IsNotNull (proxy
.DelegateHolder
.DelegateMember
);
302 Assert
.AreSame (proxy
, proxy
.DelegateHolder
.DelegateMember
.Target
);
304 Assert
.IsNotNull (proxy
.DelegateHolder
.ComplexTypeMember
);
305 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
.Count
);
306 Assert
.AreEqual (1, proxy
.DelegateHolder
.ComplexTypeMember
[0]);
307 Assert
.AreEqual (2, proxy
.DelegateHolder
.ComplexTypeMember
[1]);
308 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
[2]);
310 IndirectDelegateHolder otherProxy
= (IndirectDelegateHolder
) (SerializeAndDeserialize (proxy
));
312 Assert
.IsNotNull (otherProxy
.DelegateHolder
.DelegateMember
);
313 Assert
.AreSame (otherProxy
, otherProxy
.DelegateHolder
.DelegateMember
.Target
);
315 Assert
.IsNotNull (otherProxy
.DelegateHolder
.ComplexTypeMember
);
316 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
.Count
);
317 Assert
.AreEqual (1, otherProxy
.DelegateHolder
.ComplexTypeMember
[0]);
318 Assert
.AreEqual (2, otherProxy
.DelegateHolder
.ComplexTypeMember
[1]);
319 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
[2]);
323 public void SerializeObjectsWithIndirectDelegateToMember ()
325 IndirectDelegateHolder proxy
= (IndirectDelegateHolder
) generator
.CreateClassProxy (typeof (IndirectDelegateHolder
),
326 new IInterceptor
[] { new StandardInterceptor () }
);
328 proxy
.DelegateHolder
.DelegateMember
= new EventHandler (proxy
.DelegateHolder
.TestHandler
);
329 proxy
.DelegateHolder
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
331 Assert
.IsNotNull (proxy
.DelegateHolder
.DelegateMember
);
332 Assert
.AreSame (proxy
.DelegateHolder
, proxy
.DelegateHolder
.DelegateMember
.Target
);
334 Assert
.IsNotNull (proxy
.DelegateHolder
.ComplexTypeMember
);
335 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
.Count
);
336 Assert
.AreEqual (1, proxy
.DelegateHolder
.ComplexTypeMember
[0]);
337 Assert
.AreEqual (2, proxy
.DelegateHolder
.ComplexTypeMember
[1]);
338 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
[2]);
340 IndirectDelegateHolder otherProxy
= (IndirectDelegateHolder
) (SerializeAndDeserialize (proxy
));
342 Assert
.IsNotNull (otherProxy
.DelegateHolder
.DelegateMember
);
343 Assert
.AreSame (otherProxy
.DelegateHolder
, otherProxy
.DelegateHolder
.DelegateMember
.Target
);
345 Assert
.IsNotNull (otherProxy
.DelegateHolder
.ComplexTypeMember
);
346 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
.Count
);
347 Assert
.AreEqual (1, otherProxy
.DelegateHolder
.ComplexTypeMember
[0]);
348 Assert
.AreEqual (2, otherProxy
.DelegateHolder
.ComplexTypeMember
[1]);
349 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
[2]);
353 public class ClassWithIndirectSelfReference
355 public ArrayList List
= new ArrayList();
357 public ClassWithIndirectSelfReference()
364 public void SerializeClassWithIndirectSelfReference ()
366 ClassWithIndirectSelfReference proxy
= (ClassWithIndirectSelfReference
) generator
.CreateClassProxy (typeof (ClassWithIndirectSelfReference
),
367 new Type
[0], new StandardInterceptor ());
368 Assert
.AreSame (proxy
, proxy
.List
[0]);
370 ClassWithIndirectSelfReference otherProxy
= (ClassWithIndirectSelfReference
) SerializeAndDeserialize (proxy
);
371 Assert
.AreSame (otherProxy
, otherProxy
.List
[0]);
375 public class ClassWithDirectAndIndirectSelfReference
377 public ClassWithDirectAndIndirectSelfReference This
;
378 public ArrayList List
= new ArrayList();
380 public ClassWithDirectAndIndirectSelfReference ()
388 public void SerializeClassWithDirectAndIndirectSelfReference ()
390 ClassWithDirectAndIndirectSelfReference proxy
= (ClassWithDirectAndIndirectSelfReference
) generator
.CreateClassProxy (typeof (ClassWithDirectAndIndirectSelfReference
),
391 new Type
[0], new StandardInterceptor ());
392 Assert
.AreSame (proxy
, proxy
.This
);
394 ClassWithDirectAndIndirectSelfReference otherProxy
= (ClassWithDirectAndIndirectSelfReference
) SerializeAndDeserialize (proxy
);
395 Assert
.AreSame (otherProxy
, otherProxy
.List
[0]);
396 Assert
.AreSame (otherProxy
, otherProxy
.This
);
400 public void ProxyKnowsItsGenerationOptions ()
402 MethodFilterHook hook
= new MethodFilterHook (".*");
403 ProxyGenerationOptions options
= new ProxyGenerationOptions (hook
);
404 options
.AddMixinInstance (new SerializableMixin ());
406 object proxy
= generator
.CreateClassProxy (
407 typeof (MySerializableClass
),
410 new StandardInterceptor ());
412 FieldInfo field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
413 Assert
.IsNotNull (field
);
414 Assert
.AreSame (options
, field
.GetValue (proxy
));
418 proxy
= generator
.CreateInterfaceProxyWithoutTarget (typeof (IService
), new StandardInterceptor ());
419 field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
420 Assert
.AreSame (ProxyGenerationOptions
.Default
, field
.GetValue (proxy
));
424 proxy
= generator
.CreateInterfaceProxyWithTarget (typeof (IService
), new ServiceImpl(), options
, new StandardInterceptor ());
425 field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
426 Assert
.AreSame (options
, field
.GetValue (proxy
));
430 proxy
= generator
.CreateInterfaceProxyWithTargetInterface (typeof (IService
), new ServiceImpl(), new StandardInterceptor ());
431 field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
432 Assert
.AreSame (ProxyGenerationOptions
.Default
, field
.GetValue (proxy
));
436 class MethodFilterHook
: IProxyGenerationHook
438 private string nameFilter
;
440 public MethodFilterHook (string nameFilter
)
442 this.nameFilter
= nameFilter
;
445 public bool ShouldInterceptMethod (Type type
, MethodInfo memberInfo
)
447 return Regex
.IsMatch (memberInfo
.Name
, nameFilter
);
450 public void NonVirtualMemberNotification (Type type
, MemberInfo memberInfo
)
454 public void MethodsInspected ()
459 public interface IMixedInterface
464 public class SerializableMixin
: IMixedInterface
469 public class SerializableInterceptorSelector
: IInterceptorSelector
471 public IInterceptor
[] SelectInterceptors (Type type
, MethodInfo method
, IInterceptor
[] interceptors
)
478 public void ProxyGenerationOptionsRespectedOnDeserialization ()
480 MethodFilterHook hook
= new MethodFilterHook ("get_Current");
481 ProxyGenerationOptions options
= new ProxyGenerationOptions (hook
);
482 options
.AddMixinInstance (new SerializableMixin());
483 options
.Selector
= new SerializableInterceptorSelector ();
485 MySerializableClass proxy
= (MySerializableClass
) generator
.CreateClassProxy (
486 typeof (MySerializableClass
),
489 new StandardInterceptor());
491 Assert
.AreEqual (proxy
.GetType(), proxy
.GetType().GetMethod ("get_Current").DeclaringType
);
492 Assert
.AreNotEqual (proxy
.GetType(), proxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
493 Assert
.AreEqual (proxy
.GetType().BaseType
, proxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
494 ProxyGenerationOptions options2
= (ProxyGenerationOptions
) proxy
.GetType().GetField("proxyGenerationOptions").GetValue(null);
495 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
496 Assert
.IsNotNull (options2
.Selector
);
498 MySerializableClass otherProxy
= (MySerializableClass
) SerializeAndDeserialize (proxy
);
499 Assert
.AreEqual (otherProxy
.GetType(), otherProxy
.GetType().GetMethod ("get_Current").DeclaringType
);
500 Assert
.AreNotEqual (otherProxy
.GetType(), otherProxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
501 Assert
.AreEqual (otherProxy
.GetType().BaseType
, otherProxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
502 options2
= (ProxyGenerationOptions
) otherProxy
.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
503 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
504 Assert
.IsNotNull (options2
.Selector
);
508 [Ignore ("Checks serialization with mixins, un-ignore when these are implemented.")]
509 public void MixinsAppliedOnDeserialization ()
511 ProxyGenerationOptions options
= new ProxyGenerationOptions ();
512 options
.AddMixinInstance (new SerializableMixin ());
514 MySerializableClass proxy
= (MySerializableClass
) generator
.CreateClassProxy (
515 typeof (MySerializableClass
),
518 new StandardInterceptor ());
520 Assert
.IsTrue (proxy
is IMixedInterface
);
522 MySerializableClass otherProxy
= (MySerializableClass
) SerializeAndDeserialize (proxy
);
523 Assert
.IsTrue (otherProxy
is IMixedInterface
);
530 public object Element
;
533 // With naive serialization of ProxyGenerationOptions, the following test case fails due to problems with the order of deserialization:
534 // in ProxyObjectReference, the deserialized ProxyGenerationOptions will only contain null and default values. ProxyGenerationOptions must
535 // avoid serializing Type objects in order for this test case to pass.
537 public void ProxyGenerationOptionsRespectedOnDeserializationComplex ()
539 MethodFilterHook hook
= new MethodFilterHook ("get_Current");
540 ProxyGenerationOptions options
= new ProxyGenerationOptions (hook
);
541 options
.AddMixinInstance (new SerializableMixin());
542 options
.Selector
= new SerializableInterceptorSelector ();
544 ComplexHolder holder
= new ComplexHolder();
545 holder
.Type
= typeof (MySerializableClass
);
546 holder
.Element
= generator
.CreateClassProxy (typeof (MySerializableClass
), new Type
[0], options
, new StandardInterceptor ());
548 // check holder elements
549 Assert
.AreEqual (typeof (MySerializableClass
), holder
.Type
);
550 Assert
.IsNotNull (holder
.Element
);
551 Assert
.IsTrue (holder
.Element
is MySerializableClass
) ;
552 Assert
.AreNotEqual (typeof (MySerializableClass
), holder
.Element
.GetType ());
554 // check whether options were applied correctly
555 Assert
.AreEqual (holder
.Element
.GetType (), holder
.Element
.GetType ().GetMethod ("get_Current").DeclaringType
);
556 Assert
.AreNotEqual (holder
.Element
.GetType (), holder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
557 Assert
.AreEqual (holder
.Element
.GetType ().BaseType
, holder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
558 ProxyGenerationOptions options2
= (ProxyGenerationOptions
) holder
.Element
.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
559 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
560 Assert
.IsNotNull (options2
.Selector
);
562 ComplexHolder otherHolder
= (ComplexHolder
) SerializeAndDeserialize (holder
);
564 // check holder elements
565 Assert
.AreEqual (typeof (MySerializableClass
), otherHolder
.Type
);
566 Assert
.IsNotNull (otherHolder
.Element
);
567 Assert
.IsTrue (otherHolder
.Element
is MySerializableClass
);
568 Assert
.AreNotEqual(typeof (MySerializableClass
), otherHolder
.Element
.GetType());
570 // check whether options were applied correctly
571 Assert
.AreEqual (otherHolder
.Element
.GetType (), otherHolder
.Element
.GetType ().GetMethod ("get_Current").DeclaringType
);
572 Assert
.AreNotEqual (otherHolder
.Element
.GetType (), otherHolder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
573 Assert
.AreEqual (otherHolder
.Element
.GetType ().BaseType
, otherHolder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
574 options2
= (ProxyGenerationOptions
) otherHolder
.Element
.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
575 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
576 Assert
.IsNotNull (options2
.Selector
);
580 public void ReusingModuleScopeFromProxyObjectReference ()
582 ProxyGenerator generatorWithSpecificModuleScope
= new ProxyGenerator (new DefaultProxyBuilder (ProxyObjectReference
.ModuleScope
));
583 Assert
.AreSame (generatorWithSpecificModuleScope
.ProxyBuilder
.ModuleScope
, ProxyObjectReference
.ModuleScope
);
584 MySerializableClass first
= generatorWithSpecificModuleScope
.CreateClassProxy
<MySerializableClass
> (new StandardInterceptor ());
585 MySerializableClass second
= SerializeAndDeserialize (first
);
586 Assert
.AreSame (first
.GetType (), second
.GetType ());
590 public void DeserializationWithSpecificModuleScope ()
592 ProxyObjectReference
.SetScope (generator
.ProxyBuilder
.ModuleScope
);
593 MySerializableClass first
= generator
.CreateClassProxy
<MySerializableClass
> (new StandardInterceptor ());
594 MySerializableClass second
= SerializeAndDeserialize (first
);
595 Assert
.AreSame (first
.GetType (), second
.GetType ());