public void ProxyGenerationOptionsRespectedOnDeserialization() { var hook = new MethodFilterHook("(get_Current)|(GetExecutingObject)"); var options = new ProxyGenerationOptions(hook); options.AddMixinInstance(new SerializableMixin()); options.Selector = new SerializableInterceptorSelector(); var proxy = (MySerializableClass)generator.CreateClassProxy( typeof(MySerializableClass), new Type[0], options, new StandardInterceptor()); Assert.AreEqual(proxy.GetType(), proxy.GetType().GetMethod("get_Current").DeclaringType); Assert.AreNotEqual(proxy.GetType(), proxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual(proxy.GetType().BaseType, proxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); var options2 = (ProxyGenerationOptions)proxy.GetType().GetField("proxyGenerationOptions").GetValue(null); Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return(o is SerializableMixin); })); Assert.IsNotNull(options2.Selector); var otherProxy = SerializeAndDeserialize(proxy); Assert.AreEqual(otherProxy.GetType(), otherProxy.GetType().GetMethod("get_Current").DeclaringType); Assert.AreNotEqual(otherProxy.GetType(), otherProxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual(otherProxy.GetType().BaseType, otherProxy.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); options2 = (ProxyGenerationOptions)otherProxy.GetType().GetField("proxyGenerationOptions").GetValue(null); Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return(o is SerializableMixin); })); Assert.IsNotNull(options2.Selector); }
public void ProxyKnowsItsGenerationOptions() { var hook = new MethodFilterHook(".*"); var options = new ProxyGenerationOptions(hook); options.AddMixinInstance(new SerializableMixin()); var proxy = generator.CreateClassProxy( typeof(MySerializableClass), new Type[0], options, new StandardInterceptor() ); var field = proxy .GetType() .GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); Assert.IsNotNull(field); Assert.AreSame(options, field.GetValue(proxy)); base.Init(); proxy = generator.CreateInterfaceProxyWithoutTarget( typeof(IService), new StandardInterceptor() ); field = proxy .GetType() .GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); Assert.AreSame(ProxyGenerationOptions.Default, field.GetValue(proxy)); base.Init(); proxy = generator.CreateInterfaceProxyWithTarget( typeof(IService), new ServiceImpl(), options, new StandardInterceptor() ); field = proxy .GetType() .GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); Assert.AreSame(options, field.GetValue(proxy)); base.Init(); proxy = generator.CreateInterfaceProxyWithTargetInterface( typeof(IService), new ServiceImpl(), new StandardInterceptor() ); field = proxy .GetType() .GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic); Assert.AreSame(ProxyGenerationOptions.Default, field.GetValue(proxy)); }
public void ProxyGenerationOptionsRespectedOnDeserializationComplex() { var hook = new MethodFilterHook("(get_Current)|(GetExecutingObject)"); var options = new ProxyGenerationOptions(hook); options.AddMixinInstance(new SerializableMixin()); options.Selector = new SerializableInterceptorSelector(); var holder = new ComplexHolder(); holder.Type = typeof(MySerializableClass); holder.Element = generator.CreateClassProxy(typeof(MySerializableClass), new Type[0], options, new StandardInterceptor()); // check holder elements Assert.AreEqual(typeof(MySerializableClass), holder.Type); Assert.IsNotNull(holder.Element); Assert.IsTrue(holder.Element is MySerializableClass); Assert.AreNotEqual(typeof(MySerializableClass), holder.Element.GetType()); // check whether options were applied correctly Assert.AreEqual(holder.Element.GetType(), holder.Element.GetType().GetMethod("get_Current").DeclaringType); Assert.AreNotEqual(holder.Element.GetType(), holder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual(holder.Element.GetType().BaseType, holder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); var options2 = (ProxyGenerationOptions)holder.Element.GetType(). GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return(o is SerializableMixin); })); Assert.IsNotNull(options2.Selector); var otherHolder = SerializeAndDeserialize(holder); // check holder elements Assert.AreEqual(typeof(MySerializableClass), otherHolder.Type); Assert.IsNotNull(otherHolder.Element); Assert.IsTrue(otherHolder.Element is MySerializableClass); Assert.AreNotEqual(typeof(MySerializableClass), otherHolder.Element.GetType()); // check whether options were applied correctly Assert.AreEqual(otherHolder.Element.GetType(), otherHolder.Element.GetType().GetMethod("get_Current").DeclaringType); Assert.AreNotEqual(otherHolder.Element.GetType(), otherHolder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual(otherHolder.Element.GetType().BaseType, otherHolder.Element.GetType().GetMethod("CalculateSumDistanceNow").DeclaringType); options2 = (ProxyGenerationOptions)otherHolder.Element.GetType(). GetField("proxyGenerationOptions", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); Assert.IsNotNull(Array.Find(options2.MixinsAsArray(), delegate(object o) { return(o is SerializableMixin); })); Assert.IsNotNull(options2.Selector); }
public void ProxyGenerationOptionsRespectedOnDeserializationComplex () { ProxyObjectReference.ResetScope (); MethodFilterHook hook = new MethodFilterHook ("get_Current"); ProxyGenerationOptions options = new ProxyGenerationOptions (hook); options.AddMixinInstance (new SerializableMixin()); options.Selector = new SerializableInterceptorSelector (); ComplexHolder holder = new ComplexHolder(); holder.Type = typeof (MySerializableClass); holder.Element = generator.CreateClassProxy (typeof (MySerializableClass), new Type[0], options, new StandardInterceptor ()); // check holder elements Assert.AreEqual (typeof (MySerializableClass), holder.Type); Assert.IsNotNull (holder.Element); Assert.IsTrue (holder.Element is MySerializableClass) ; Assert.AreNotEqual (typeof (MySerializableClass), holder.Element.GetType ()); // check whether options were applied correctly Assert.AreEqual (holder.Element.GetType (), holder.Element.GetType ().GetMethod ("get_Current").DeclaringType); Assert.AreNotEqual (holder.Element.GetType (), holder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual (holder.Element.GetType ().BaseType, holder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType); ProxyGenerationOptions options2 = (ProxyGenerationOptions) holder.Element.GetType ().GetField ("proxyGenerationOptions").GetValue (null); Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; })); Assert.IsNotNull (options2.Selector); ComplexHolder otherHolder = (ComplexHolder) SerializeAndDeserialize (holder); // check holder elements Assert.AreEqual (typeof (MySerializableClass), otherHolder.Type); Assert.IsNotNull (otherHolder.Element); Assert.IsTrue (otherHolder.Element is MySerializableClass); Assert.AreNotEqual(typeof (MySerializableClass), otherHolder.Element.GetType()); // check whether options were applied correctly Assert.AreEqual (otherHolder.Element.GetType (), otherHolder.Element.GetType ().GetMethod ("get_Current").DeclaringType); Assert.AreNotEqual (otherHolder.Element.GetType (), otherHolder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual (otherHolder.Element.GetType ().BaseType, otherHolder.Element.GetType ().GetMethod ("CalculateSumDistanceNow").DeclaringType); options2 = (ProxyGenerationOptions) otherHolder.Element.GetType ().GetField ("proxyGenerationOptions").GetValue (null); Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; })); Assert.IsNotNull (options2.Selector); }
public void ProxyGenerationOptionsRespectedOnDeserialization () { ProxyObjectReference.ResetScope(); MethodFilterHook hook = new MethodFilterHook ("get_Current"); ProxyGenerationOptions options = new ProxyGenerationOptions (hook); options.AddMixinInstance (new SerializableMixin()); options.Selector = new SerializableInterceptorSelector (); MySerializableClass proxy = (MySerializableClass) generator.CreateClassProxy ( typeof (MySerializableClass), new Type[0], options, new StandardInterceptor()); Assert.AreEqual (proxy.GetType(), proxy.GetType().GetMethod ("get_Current").DeclaringType); Assert.AreNotEqual (proxy.GetType(), proxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual (proxy.GetType().BaseType, proxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType); ProxyGenerationOptions options2 = (ProxyGenerationOptions) proxy.GetType().GetField("proxyGenerationOptions").GetValue(null); Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; })); Assert.IsNotNull (options2.Selector); MySerializableClass otherProxy = (MySerializableClass) SerializeAndDeserialize (proxy); Assert.AreEqual (otherProxy.GetType(), otherProxy.GetType().GetMethod ("get_Current").DeclaringType); Assert.AreNotEqual (otherProxy.GetType(), otherProxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType); Assert.AreEqual (otherProxy.GetType().BaseType, otherProxy.GetType().GetMethod ("CalculateSumDistanceNow").DeclaringType); options2 = (ProxyGenerationOptions) otherProxy.GetType ().GetField ("proxyGenerationOptions").GetValue (null); Assert.IsNotNull (Array.Find (options2.MixinsAsArray (), delegate (object o) { return o is SerializableMixin; })); Assert.IsNotNull (options2.Selector); }
public void ProxyKnowsItsGenerationOptions () { MethodFilterHook hook = new MethodFilterHook (".*"); ProxyGenerationOptions options = new ProxyGenerationOptions (hook); options.AddMixinInstance (new SerializableMixin ()); object proxy = generator.CreateClassProxy ( typeof (MySerializableClass), new Type[0], options, new StandardInterceptor ()); FieldInfo field = proxy.GetType ().GetField ("proxyGenerationOptions"); Assert.IsNotNull (field); Assert.AreSame (options, field.GetValue (proxy)); base.Init (); proxy = generator.CreateInterfaceProxyWithoutTarget (typeof (IService), new StandardInterceptor ()); field = proxy.GetType ().GetField ("proxyGenerationOptions"); Assert.AreSame (ProxyGenerationOptions.Default, field.GetValue (proxy)); base.Init (); proxy = generator.CreateInterfaceProxyWithTarget (typeof (IService), new ServiceImpl(), options, new StandardInterceptor ()); field = proxy.GetType ().GetField ("proxyGenerationOptions"); Assert.AreSame (options, field.GetValue (proxy)); base.Init (); proxy = generator.CreateInterfaceProxyWithTargetInterface (typeof (IService), new ServiceImpl(), new StandardInterceptor ()); field = proxy.GetType ().GetField ("proxyGenerationOptions"); Assert.AreSame (ProxyGenerationOptions.Default, field.GetValue (proxy)); }