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 static void TestObjectContainerFromToObject() { var initialBag = new Eina.Array <Efl.Object>(); var tmp1 = new Dummy.TestObject(); var tmp2 = new Dummy.TestObject(); var tmp3 = new Dummy.TestObject(); initialBag.Push(tmp1); initialBag.Push(tmp2); initialBag.Push(tmp3); var source = new ComplexHolder { BagOfObjects = initialBag }; var prop = source.GetType().GetProperty("BagOfObjects"); var v = new Eina.Value(prop.GetValue(source)); Test.AssertEquals(prop.GetValue(source), initialBag); Test.AssertEquals(v.GetValueType(), Eina.ValueType.Array); Test.AssertEquals(v.GetValueSubType(), Eina.ValueType.Object); Test.AssertEquals(v[0], initialBag[0]); Test.AssertEquals(v[1], initialBag[1]); Test.AssertEquals(v[2], initialBag[2]); var first = new Dummy.TestObject(); var second = new Dummy.TestObject(); var third = new Dummy.TestObject(); v[0] = first; v[1] = second; v[2] = third; prop.SetValue(source, v.Unwrap()); IEnumerable <Efl.Object> newVal = prop.GetValue(source) as IEnumerable <Efl.Object>; var toCheck = newVal.ToList(); Test.AssertEquals(toCheck[0], first); Test.AssertEquals(toCheck[1], second); Test.AssertEquals(toCheck[2], third); tmp3.Dispose(); tmp2.Dispose(); tmp1.Dispose(); v.Dispose(); }
public static void TestContainerFromToObject() { var initialBag = new Eina.Array <int>(); initialBag.Push(2); initialBag.Push(4); initialBag.Push(6); var source = new ComplexHolder { Bag = initialBag }; var prop = source.GetType().GetProperty("Bag"); var v = new Eina.Value(prop.GetValue(source)); Test.AssertEquals(prop.GetValue(source), initialBag); Test.AssertEquals(v.GetValueType(), Eina.ValueType.Array); Test.AssertEquals(v.GetValueSubType(), Eina.ValueType.Int32); Test.AssertEquals(v[0], initialBag[0]); Test.AssertEquals(v[1], initialBag[1]); Test.AssertEquals(v[2], initialBag[2]); v[0] = 100; v[1] = 200; v[2] = 300; prop.SetValue(source, v.Unwrap()); IEnumerable <int> newVal = prop.GetValue(source) as IEnumerable <int>; var toCheck = newVal.ToList(); Test.AssertEquals(toCheck[0], 100); Test.AssertEquals(toCheck[1], 200); Test.AssertEquals(toCheck[2], 300); v.Dispose(); }
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); }