Пример #1
0
        public void XmlSerialization()
        {
            ProxyObjectReference.ResetScope();

            GeneratorContext context = new GeneratorContext();
            SimpleMixin      mixin1  = new SimpleMixin();
            OtherMixin       mixin2  = new OtherMixin();

            context.AddMixinInstance(mixin1);
            context.AddMixinInstance(mixin2);

            object proxy = generator.CreateCustomClassProxy(
                typeof(SimpleClass), new StandardInterceptor(), context);

            System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(SimpleClass));
            MemoryStream stream = new MemoryStream();

            serializer.Serialize(stream, proxy);
            stream.Position = 0;
            SimpleClass otherProxy = (SimpleClass)serializer.Deserialize(stream);

            ISimpleMixin mixin = otherProxy as ISimpleMixin;

            Assert.AreEqual(1, mixin.DoSomething());

            IOtherMixin other = otherProxy as IOtherMixin;

            Assert.AreEqual(3, other.Sum(1, 2));
        }
 public void DeserializationWithSpecificModuleScope()
 {
     ProxyObjectReference.SetScope(generator.ProxyBuilder.ModuleScope);
     var first = generator.CreateClassProxy<MySerializableClass>(new StandardInterceptor());
     var second = SerializeAndDeserialize(first);
     Assert.AreSame(first.GetType(), second.GetType());
 }
Пример #3
0
        public void CreateSerializable()
        {
            ProxyObjectReference.ResetScope();

            MySerializableClass proxy = (MySerializableClass)
                                        generator.CreateClassProxy(typeof(MySerializableClass), new StandardInterceptor());

            Assert.IsTrue(proxy.GetType().IsSerializable);
        }
Пример #4
0
        public void SerializationDelegate()
        {
            ProxyObjectReference.ResetScope();

            MySerializableClass2 proxy = (MySerializableClass2)
                                         generator.CreateClassProxy(typeof(MySerializableClass2), new StandardInterceptor());

            DateTime current = proxy.Current;

            MySerializableClass2 otherProxy = (MySerializableClass2)SerializeAndDeserialize(proxy);

            Assert.AreEqual(current, otherProxy.Current);
        }
Пример #5
0
        public void HashtableSerialization()
        {
            ProxyObjectReference.ResetScope();

            object proxy = generator.CreateClassProxy(
                typeof(Hashtable), new StandardInterceptor());

            Assert.IsTrue(typeof(Hashtable).IsAssignableFrom(proxy.GetType()));

            (proxy as Hashtable).Add("key", "helloooo!");

            Hashtable otherProxy = (Hashtable)SerializeAndDeserialize(proxy);

            Assert.IsTrue(otherProxy.ContainsKey("key"));
            Assert.AreEqual("helloooo!", otherProxy["key"]);
        }
Пример #6
0
        public void CustomMarkerInterface()
        {
            ProxyObjectReference.ResetScope();

            ClassProxyGenerator classGenerator = new ClassProxyGenerator(
                new ModuleScope(), new GeneratorContext());

            Type proxyType = classGenerator.GenerateCode(typeof(ClassWithMarkerInterface), new Type[] { typeof(IMarkerInterface) });

            object proxy = Activator.CreateInstance(proxyType, new object[] { new StandardInterceptor() });

            Assert.IsNotNull(proxy);
            Assert.IsTrue(proxy is IMarkerInterface);

            object otherProxy = SerializeAndDeserialize(proxy);

            Assert.IsTrue(otherProxy is IMarkerInterface);
        }
Пример #7
0
        public void SimpleInterfaceProxy()
        {
            ProxyObjectReference.ResetScope();

            object proxy = generator.CreateProxy(
                typeof(IMyInterface), new StandardInterceptor( ), new MyInterfaceImpl());

            Assert.IsTrue(proxy.GetType().IsSerializable);

            IMyInterface inter = (IMyInterface)proxy;

            inter.Name = "opa";
            Assert.AreEqual("opa", inter.Name);
            inter.Started = true;
            Assert.AreEqual(true, inter.Started);

            IMyInterface otherProxy = (IMyInterface)SerializeAndDeserialize(proxy);

            Assert.AreEqual(inter.Name, otherProxy.Name);
            Assert.AreEqual(inter.Started, otherProxy.Started);
        }
Пример #8
0
        public void MixinSerialization()
        {
            ProxyObjectReference.ResetScope();

            GeneratorContext context = new GeneratorContext();
            SimpleMixin      mixin1  = new SimpleMixin();
            OtherMixin       mixin2  = new OtherMixin();

            context.AddMixinInstance(mixin1);
            context.AddMixinInstance(mixin2);

            object proxy = generator.CreateCustomClassProxy(
                typeof(SimpleClass), new StandardInterceptor(), context);

            Assert.IsTrue(typeof(SimpleClass).IsAssignableFrom(proxy.GetType()));

            (proxy as SimpleClass).DoSome();

            ISimpleMixin mixin = proxy as ISimpleMixin;

            Assert.AreEqual(1, mixin.DoSomething());

            IOtherMixin other = proxy as IOtherMixin;

            Assert.AreEqual(3, other.Sum(1, 2));

            SimpleClass otherProxy = (SimpleClass)SerializeAndDeserialize(proxy);

            otherProxy.DoSome();

            mixin = otherProxy as ISimpleMixin;
            Assert.AreEqual(1, mixin.DoSomething());

            other = otherProxy as IOtherMixin;
            Assert.AreEqual(3, other.Sum(1, 2));
        }
Пример #9
0
 public override void TearDown()
 {
     base.TearDown();
     ProxyObjectReference.ResetScope();
 }
Пример #10
0
 public override void Init()
 {
     base.Init();
     ProxyObjectReference.ResetScope();
 }