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 namespace Castle
.DynamicProxy
.Tests
18 using System
.Collections
;
20 using System
.Reflection
;
21 using System
.Runtime
.Serialization
;
22 using System
.Runtime
.Serialization
.Formatters
.Binary
;
23 using System
.Text
.RegularExpressions
;
24 using Castle
.Core
.Interceptor
;
25 using Castle
.DynamicProxy
.Serialization
;
26 using Castle
.DynamicProxy
.Tests
.Classes
;
27 using Castle
.DynamicProxy
.Tests
;
28 using Castle
.DynamicProxy
.Tests
.BugsReported
;
29 using Castle
.DynamicProxy
.Tests
.InterClasses
;
30 using NUnit
.Framework
;
35 public class SerializableClassTestCase
: BasePEVerifyTestCase
37 public override void Init ()
40 ProxyObjectReference
.ResetScope ();
43 public override void TearDown ()
46 ProxyObjectReference
.ResetScope ();
50 public void CreateSerializable()
52 MySerializableClass proxy
= (MySerializableClass
)
53 generator
.CreateClassProxy(typeof(MySerializableClass
), new StandardInterceptor());
55 Assert
.IsTrue(proxy
.GetType().IsSerializable
);
59 public void ImplementsISerializable()
61 MySerializableClass proxy
= (MySerializableClass
)
62 generator
.CreateClassProxy(typeof(MySerializableClass
), new StandardInterceptor());
64 Assert
.IsTrue(proxy
is ISerializable
);
68 public void SimpleProxySerialization()
70 MySerializableClass proxy
= (MySerializableClass
)
71 generator
.CreateClassProxy(typeof(MySerializableClass
), new StandardInterceptor());
73 DateTime current
= proxy
.Current
;
75 MySerializableClass otherProxy
= (MySerializableClass
) SerializeAndDeserialize(proxy
);
77 Assert
.AreEqual(current
, otherProxy
.Current
);
81 public void SerializationDelegate()
83 MySerializableClass2 proxy
= (MySerializableClass2
)
84 generator
.CreateClassProxy(typeof(MySerializableClass2
), new StandardInterceptor());
86 DateTime current
= proxy
.Current
;
88 MySerializableClass2 otherProxy
= (MySerializableClass2
) SerializeAndDeserialize(proxy
);
90 Assert
.AreEqual(current
, otherProxy
.Current
);
94 public void SimpleInterfaceProxy()
97 generator
.CreateInterfaceProxyWithTarget(typeof(IMyInterface2
), new MyInterfaceImpl(), new StandardInterceptor());
99 Assert
.IsTrue(proxy
.GetType().IsSerializable
);
101 IMyInterface2 inter
= (IMyInterface2
) proxy
;
104 Assert
.AreEqual("opa", inter
.Name
);
105 inter
.Started
= true;
106 Assert
.AreEqual(true, inter
.Started
);
108 IMyInterface2 otherProxy
= (IMyInterface2
) SerializeAndDeserialize(proxy
);
110 Assert
.AreEqual(inter
.Name
, otherProxy
.Name
);
111 Assert
.AreEqual(inter
.Started
, otherProxy
.Started
);
116 public void SimpleInterfaceProxy_WithoutTarget()
119 generator
.CreateInterfaceProxyWithoutTarget(typeof(IMyInterface2
), new Type
[] {typeof(IMyInterface)}
,
120 new StandardInterceptor());
122 Assert
.IsTrue(proxy
is IMyInterface2
);
123 Assert
.IsTrue(proxy
is IMyInterface
);
126 object otherProxy
= SerializeAndDeserialize(proxy
);
128 Assert
.IsTrue(otherProxy
is IMyInterface2
);
129 Assert
.IsTrue(otherProxy
is IMyInterface
);
133 public void CustomMarkerInterface()
135 object proxy
= generator
.CreateClassProxy(typeof(ClassWithMarkerInterface
),
136 new Type
[] {typeof(IMarkerInterface)}
,
137 new StandardInterceptor());
139 Assert
.IsNotNull(proxy
);
140 Assert
.IsTrue(proxy
is IMarkerInterface
);
142 object otherProxy
= SerializeAndDeserialize(proxy
);
144 Assert
.IsTrue(otherProxy
is IMarkerInterface
);
148 public void HashtableSerialization()
150 object proxy
= generator
.CreateClassProxy(
151 typeof(Hashtable
), new StandardInterceptor());
153 Assert
.IsTrue(typeof(Hashtable
).IsAssignableFrom(proxy
.GetType()));
155 (proxy
as Hashtable
).Add("key", "helloooo!");
157 Hashtable otherProxy
= (Hashtable
) SerializeAndDeserialize(proxy
);
159 Assert
.IsTrue(otherProxy
.ContainsKey("key"));
160 Assert
.AreEqual("helloooo!", otherProxy
["key"]);
163 public static T SerializeAndDeserialize
<T
>(T proxy
)
165 MemoryStream stream
= new MemoryStream();
166 BinaryFormatter formatter
= new BinaryFormatter();
167 formatter
.Serialize(stream
, proxy
);
169 return (T
) formatter
.Deserialize(stream
);
186 public void SerializatingObjectsWithoutDefaultConstructor ()
188 C proxy
= (C
) generator
.CreateClassProxy (typeof (C
), new IInterceptor
[] { new StandardInterceptor () }
, 1);
189 C otherProxy
= (C
) SerializeAndDeserialize (proxy
);
191 Assert
.AreEqual (proxy
.I
, otherProxy
.I
);
192 Assert
.AreSame (otherProxy
, otherProxy
.This
);
196 public class EventHandlerClass
198 public void TestHandler (object sender
, EventArgs e
)
205 public class DelegateHolder
207 public EventHandler DelegateMember
;
208 public ArrayList ComplexTypeMember
;
210 public DelegateHolder ()
214 public void TestHandler (object sender
, EventArgs e
)
220 public class IndirectDelegateHolder
222 public DelegateHolder DelegateHolder
= new DelegateHolder();
224 public void TestHandler (object sender
, EventArgs e
)
230 public void SerializeObjectsWithDelegateToOtherObject ()
232 EventHandlerClass eventHandlerInstance
= new EventHandlerClass();
233 DelegateHolder proxy
= (DelegateHolder
) generator
.CreateClassProxy (typeof (DelegateHolder
), new IInterceptor
[] {new StandardInterceptor ()}
);
235 proxy
.DelegateMember
= new EventHandler(eventHandlerInstance
.TestHandler
);
236 proxy
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
237 proxy
.ComplexTypeMember
.Add (eventHandlerInstance
);
239 Assert
.IsNotNull (proxy
.DelegateMember
);
240 Assert
.IsNotNull (proxy
.DelegateMember
.Target
);
242 Assert
.IsNotNull (proxy
.ComplexTypeMember
);
243 Assert
.AreEqual (4, proxy
.ComplexTypeMember
.Count
);
244 Assert
.AreEqual (1, proxy
.ComplexTypeMember
[0]);
245 Assert
.AreEqual (2, proxy
.ComplexTypeMember
[1]);
246 Assert
.AreEqual (3, proxy
.ComplexTypeMember
[2]);
247 Assert
.AreSame (proxy
.ComplexTypeMember
[3], proxy
.DelegateMember
.Target
);
249 DelegateHolder otherProxy
= (DelegateHolder
) (SerializeAndDeserialize (proxy
));
251 Assert
.IsNotNull (otherProxy
.DelegateMember
);
252 Assert
.IsNotNull (otherProxy
.DelegateMember
.Target
);
254 Assert
.IsNotNull (otherProxy
.ComplexTypeMember
);
255 Assert
.AreEqual (4, otherProxy
.ComplexTypeMember
.Count
);
256 Assert
.AreEqual (1, otherProxy
.ComplexTypeMember
[0]);
257 Assert
.AreEqual (2, otherProxy
.ComplexTypeMember
[1]);
258 Assert
.AreEqual (3, otherProxy
.ComplexTypeMember
[2]);
259 Assert
.AreSame (otherProxy
.ComplexTypeMember
[3], otherProxy
.DelegateMember
.Target
);
263 public void SerializeObjectsWithDelegateToThisObject ()
265 DelegateHolder proxy
= (DelegateHolder
) generator
.CreateClassProxy (typeof (DelegateHolder
), new IInterceptor
[] { new StandardInterceptor () }
);
267 proxy
.DelegateMember
= new EventHandler (proxy
.TestHandler
);
268 proxy
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
270 Assert
.IsNotNull (proxy
.DelegateMember
);
271 Assert
.AreSame (proxy
, proxy
.DelegateMember
.Target
);
273 Assert
.IsNotNull (proxy
.ComplexTypeMember
);
274 Assert
.AreEqual (3, proxy
.ComplexTypeMember
.Count
);
275 Assert
.AreEqual (1, proxy
.ComplexTypeMember
[0]);
276 Assert
.AreEqual (2, proxy
.ComplexTypeMember
[1]);
277 Assert
.AreEqual (3, proxy
.ComplexTypeMember
[2]);
279 DelegateHolder otherProxy
= (DelegateHolder
) (SerializeAndDeserialize (proxy
));
281 Assert
.IsNotNull (otherProxy
.DelegateMember
);
282 Assert
.AreSame (otherProxy
, otherProxy
.DelegateMember
.Target
);
284 Assert
.IsNotNull (otherProxy
.ComplexTypeMember
);
285 Assert
.AreEqual (3, otherProxy
.ComplexTypeMember
.Count
);
286 Assert
.AreEqual (1, otherProxy
.ComplexTypeMember
[0]);
287 Assert
.AreEqual (2, otherProxy
.ComplexTypeMember
[1]);
288 Assert
.AreEqual (3, otherProxy
.ComplexTypeMember
[2]);
292 public void SerializeObjectsWithIndirectDelegateToThisObject ()
294 IndirectDelegateHolder proxy
= (IndirectDelegateHolder
) generator
.CreateClassProxy (typeof (IndirectDelegateHolder
),
295 new IInterceptor
[] { new StandardInterceptor () }
);
297 proxy
.DelegateHolder
.DelegateMember
= new EventHandler (proxy
.TestHandler
);
298 proxy
.DelegateHolder
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
300 Assert
.IsNotNull (proxy
.DelegateHolder
.DelegateMember
);
301 Assert
.AreSame (proxy
, proxy
.DelegateHolder
.DelegateMember
.Target
);
303 Assert
.IsNotNull (proxy
.DelegateHolder
.ComplexTypeMember
);
304 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
.Count
);
305 Assert
.AreEqual (1, proxy
.DelegateHolder
.ComplexTypeMember
[0]);
306 Assert
.AreEqual (2, proxy
.DelegateHolder
.ComplexTypeMember
[1]);
307 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
[2]);
309 IndirectDelegateHolder otherProxy
= (IndirectDelegateHolder
) (SerializeAndDeserialize (proxy
));
311 Assert
.IsNotNull (otherProxy
.DelegateHolder
.DelegateMember
);
312 Assert
.AreSame (otherProxy
, otherProxy
.DelegateHolder
.DelegateMember
.Target
);
314 Assert
.IsNotNull (otherProxy
.DelegateHolder
.ComplexTypeMember
);
315 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
.Count
);
316 Assert
.AreEqual (1, otherProxy
.DelegateHolder
.ComplexTypeMember
[0]);
317 Assert
.AreEqual (2, otherProxy
.DelegateHolder
.ComplexTypeMember
[1]);
318 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
[2]);
322 public void SerializeObjectsWithIndirectDelegateToMember ()
324 IndirectDelegateHolder proxy
= (IndirectDelegateHolder
) generator
.CreateClassProxy (typeof (IndirectDelegateHolder
),
325 new IInterceptor
[] { new StandardInterceptor () }
);
327 proxy
.DelegateHolder
.DelegateMember
= new EventHandler (proxy
.DelegateHolder
.TestHandler
);
328 proxy
.DelegateHolder
.ComplexTypeMember
= new ArrayList (new int[] { 1, 2, 3 }
);
330 Assert
.IsNotNull (proxy
.DelegateHolder
.DelegateMember
);
331 Assert
.AreSame (proxy
.DelegateHolder
, proxy
.DelegateHolder
.DelegateMember
.Target
);
333 Assert
.IsNotNull (proxy
.DelegateHolder
.ComplexTypeMember
);
334 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
.Count
);
335 Assert
.AreEqual (1, proxy
.DelegateHolder
.ComplexTypeMember
[0]);
336 Assert
.AreEqual (2, proxy
.DelegateHolder
.ComplexTypeMember
[1]);
337 Assert
.AreEqual (3, proxy
.DelegateHolder
.ComplexTypeMember
[2]);
339 IndirectDelegateHolder otherProxy
= (IndirectDelegateHolder
) (SerializeAndDeserialize (proxy
));
341 Assert
.IsNotNull (otherProxy
.DelegateHolder
.DelegateMember
);
342 Assert
.AreSame (otherProxy
.DelegateHolder
, otherProxy
.DelegateHolder
.DelegateMember
.Target
);
344 Assert
.IsNotNull (otherProxy
.DelegateHolder
.ComplexTypeMember
);
345 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
.Count
);
346 Assert
.AreEqual (1, otherProxy
.DelegateHolder
.ComplexTypeMember
[0]);
347 Assert
.AreEqual (2, otherProxy
.DelegateHolder
.ComplexTypeMember
[1]);
348 Assert
.AreEqual (3, otherProxy
.DelegateHolder
.ComplexTypeMember
[2]);
352 public class ClassWithIndirectSelfReference
354 public ArrayList List
= new ArrayList();
356 public ClassWithIndirectSelfReference()
363 public void SerializeClassWithIndirectSelfReference ()
365 ClassWithIndirectSelfReference proxy
= (ClassWithIndirectSelfReference
) generator
.CreateClassProxy (typeof (ClassWithIndirectSelfReference
),
366 new Type
[0], new StandardInterceptor ());
367 Assert
.AreSame (proxy
, proxy
.List
[0]);
369 ClassWithIndirectSelfReference otherProxy
= (ClassWithIndirectSelfReference
) SerializeAndDeserialize (proxy
);
370 Assert
.AreSame (otherProxy
, otherProxy
.List
[0]);
374 public class ClassWithDirectAndIndirectSelfReference
376 public ClassWithDirectAndIndirectSelfReference This
;
377 public ArrayList List
= new ArrayList();
379 public ClassWithDirectAndIndirectSelfReference ()
387 public void SerializeClassWithDirectAndIndirectSelfReference ()
389 ClassWithDirectAndIndirectSelfReference proxy
= (ClassWithDirectAndIndirectSelfReference
) generator
.CreateClassProxy (typeof (ClassWithDirectAndIndirectSelfReference
),
390 new Type
[0], new StandardInterceptor ());
391 Assert
.AreSame (proxy
, proxy
.This
);
393 ClassWithDirectAndIndirectSelfReference otherProxy
= (ClassWithDirectAndIndirectSelfReference
) SerializeAndDeserialize (proxy
);
394 Assert
.AreSame (otherProxy
, otherProxy
.List
[0]);
395 Assert
.AreSame (otherProxy
, otherProxy
.This
);
399 public void ProxyKnowsItsGenerationOptions ()
401 MethodFilterHook hook
= new MethodFilterHook (".*");
402 ProxyGenerationOptions options
= new ProxyGenerationOptions (hook
);
403 options
.AddMixinInstance (new SerializableMixin ());
405 object proxy
= generator
.CreateClassProxy (
406 typeof (MySerializableClass
),
409 new StandardInterceptor ());
411 FieldInfo field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
412 Assert
.IsNotNull (field
);
413 Assert
.AreSame (options
, field
.GetValue (proxy
));
417 proxy
= generator
.CreateInterfaceProxyWithoutTarget (typeof (IService
), new StandardInterceptor ());
418 field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
419 Assert
.AreSame (ProxyGenerationOptions
.Default
, field
.GetValue (proxy
));
423 proxy
= generator
.CreateInterfaceProxyWithTarget (typeof (IService
), new ServiceImpl(), options
, new StandardInterceptor ());
424 field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
425 Assert
.AreSame (options
, field
.GetValue (proxy
));
429 proxy
= generator
.CreateInterfaceProxyWithTargetInterface (typeof (IService
), new ServiceImpl(), new StandardInterceptor ());
430 field
= proxy
.GetType ().GetField ("proxyGenerationOptions");
431 Assert
.AreSame (ProxyGenerationOptions
.Default
, field
.GetValue (proxy
));
435 class MethodFilterHook
: IProxyGenerationHook
437 private string nameFilter
;
439 public MethodFilterHook (string nameFilter
)
441 this.nameFilter
= nameFilter
;
444 public bool ShouldInterceptMethod (Type type
, MethodInfo memberInfo
)
446 return Regex
.IsMatch (memberInfo
.Name
, nameFilter
);
449 public void NonVirtualMemberNotification (Type type
, MemberInfo memberInfo
)
453 public void MethodsInspected ()
458 public interface IMixedInterface
463 public class SerializableMixin
: IMixedInterface
468 public class SerializableInterceptorSelector
: IInterceptorSelector
470 public IInterceptor
[] SelectInterceptors (Type type
, MethodInfo method
, IInterceptor
[] interceptors
)
477 public void ProxyGenerationOptionsRespectedOnDeserialization ()
479 MethodFilterHook hook
= new MethodFilterHook ("get_Current");
480 ProxyGenerationOptions options
= new ProxyGenerationOptions (hook
);
481 options
.AddMixinInstance (new SerializableMixin());
482 options
.Selector
= new SerializableInterceptorSelector ();
484 MySerializableClass proxy
= (MySerializableClass
) generator
.CreateClassProxy (
485 typeof (MySerializableClass
),
488 new StandardInterceptor());
490 Assert
.AreEqual (proxy
.GetType(), proxy
.GetType().GetMethod ("get_Current").DeclaringType
);
491 Assert
.AreNotEqual (proxy
.GetType(), proxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
492 Assert
.AreEqual (proxy
.GetType().BaseType
, proxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
493 ProxyGenerationOptions options2
= (ProxyGenerationOptions
) proxy
.GetType().GetField("proxyGenerationOptions").GetValue(null);
494 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
495 Assert
.IsNotNull (options2
.Selector
);
497 MySerializableClass otherProxy
= (MySerializableClass
) SerializeAndDeserialize (proxy
);
498 Assert
.AreEqual (otherProxy
.GetType(), otherProxy
.GetType().GetMethod ("get_Current").DeclaringType
);
499 Assert
.AreNotEqual (otherProxy
.GetType(), otherProxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
500 Assert
.AreEqual (otherProxy
.GetType().BaseType
, otherProxy
.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
501 options2
= (ProxyGenerationOptions
) otherProxy
.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
502 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
503 Assert
.IsNotNull (options2
.Selector
);
507 [Ignore ("Checks serialization with mixins, un-ignore when these are implemented.")]
508 public void MixinsAppliedOnDeserialization ()
510 ProxyGenerationOptions options
= new ProxyGenerationOptions ();
511 options
.AddMixinInstance (new SerializableMixin ());
513 MySerializableClass proxy
= (MySerializableClass
) generator
.CreateClassProxy (
514 typeof (MySerializableClass
),
517 new StandardInterceptor ());
519 Assert
.IsTrue (proxy
is IMixedInterface
);
521 MySerializableClass otherProxy
= (MySerializableClass
) SerializeAndDeserialize (proxy
);
522 Assert
.IsTrue (otherProxy
is IMixedInterface
);
529 public object Element
;
532 // With naive serialization of ProxyGenerationOptions, the following test case fails due to problems with the order of deserialization:
533 // in ProxyObjectReference, the deserialized ProxyGenerationOptions will only contain null and default values. ProxyGenerationOptions must
534 // avoid serializing Type objects in order for this test case to pass.
536 public void ProxyGenerationOptionsRespectedOnDeserializationComplex ()
538 MethodFilterHook hook
= new MethodFilterHook ("get_Current");
539 ProxyGenerationOptions options
= new ProxyGenerationOptions (hook
);
540 options
.AddMixinInstance (new SerializableMixin());
541 options
.Selector
= new SerializableInterceptorSelector ();
543 ComplexHolder holder
= new ComplexHolder();
544 holder
.Type
= typeof (MySerializableClass
);
545 holder
.Element
= generator
.CreateClassProxy (typeof (MySerializableClass
), new Type
[0], options
, new StandardInterceptor ());
547 // check holder elements
548 Assert
.AreEqual (typeof (MySerializableClass
), holder
.Type
);
549 Assert
.IsNotNull (holder
.Element
);
550 Assert
.IsTrue (holder
.Element
is MySerializableClass
) ;
551 Assert
.AreNotEqual (typeof (MySerializableClass
), holder
.Element
.GetType ());
553 // check whether options were applied correctly
554 Assert
.AreEqual (holder
.Element
.GetType (), holder
.Element
.GetType ().GetMethod ("get_Current").DeclaringType
);
555 Assert
.AreNotEqual (holder
.Element
.GetType (), holder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
556 Assert
.AreEqual (holder
.Element
.GetType ().BaseType
, holder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
557 ProxyGenerationOptions options2
= (ProxyGenerationOptions
) holder
.Element
.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
558 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
559 Assert
.IsNotNull (options2
.Selector
);
561 ComplexHolder otherHolder
= (ComplexHolder
) SerializeAndDeserialize (holder
);
563 // check holder elements
564 Assert
.AreEqual (typeof (MySerializableClass
), otherHolder
.Type
);
565 Assert
.IsNotNull (otherHolder
.Element
);
566 Assert
.IsTrue (otherHolder
.Element
is MySerializableClass
);
567 Assert
.AreNotEqual(typeof (MySerializableClass
), otherHolder
.Element
.GetType());
569 // check whether options were applied correctly
570 Assert
.AreEqual (otherHolder
.Element
.GetType (), otherHolder
.Element
.GetType ().GetMethod ("get_Current").DeclaringType
);
571 Assert
.AreNotEqual (otherHolder
.Element
.GetType (), otherHolder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
572 Assert
.AreEqual (otherHolder
.Element
.GetType ().BaseType
, otherHolder
.Element
.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType
);
573 options2
= (ProxyGenerationOptions
) otherHolder
.Element
.GetType ().GetField ("proxyGenerationOptions").GetValue (null);
574 Assert
.IsNotNull (Array
.Find (options2
.MixinsAsArray (), delegate (object o
) { return o is SerializableMixin; }
));
575 Assert
.IsNotNull (options2
.Selector
);
579 public void ReusingModuleScopeFromProxyObjectReference ()
581 ProxyGenerator generatorWithSpecificModuleScope
= new ProxyGenerator (new DefaultProxyBuilder (ProxyObjectReference
.ModuleScope
));
582 Assert
.AreSame (generatorWithSpecificModuleScope
.ProxyBuilder
.ModuleScope
, ProxyObjectReference
.ModuleScope
);
583 MySerializableClass first
= generatorWithSpecificModuleScope
.CreateClassProxy
<MySerializableClass
> (new StandardInterceptor ());
584 MySerializableClass second
= SerializeAndDeserialize (first
);
585 Assert
.AreSame (first
.GetType (), second
.GetType ());
589 public void DeserializationWithSpecificModuleScope ()
591 ProxyObjectReference
.SetScope (generator
.ProxyBuilder
.ModuleScope
);
592 MySerializableClass first
= generator
.CreateClassProxy
<MySerializableClass
> (new StandardInterceptor ());
593 MySerializableClass second
= SerializeAndDeserialize (first
);
594 Assert
.AreSame (first
.GetType (), second
.GetType ());