コード例 #1
0
        public void OverrideClassMethods()
        {
            BaseType1 bt1 = CreateMixedObject <BaseType1> (typeof(BT1Mixin1));

            Assert.That(bt1.VirtualMethod(), Is.EqualTo("BT1Mixin1.VirtualMethod"));
            Assert.IsNotNull(bt1.GetType().GetMethod("VirtualMethod", Type.EmptyTypes), "overridden member is public and has the same name");
            Assert.That(bt1.GetType().GetMethod("VirtualMethod", Type.EmptyTypes).GetBaseDefinition().DeclaringType, Is.EqualTo(typeof(BaseType1)));
        }
コード例 #2
0
        public void ThisAccessInCtorAndInitialize()
        {
            BaseType1 bt1 = CreateMixedObject <BaseType1> (typeof(MixinWithOnInitialize1));
            MixinWithOnInitialize1 mixin = Mixin.Get <MixinWithOnInitialize1> (bt1);

            Assert.That(mixin, Is.Not.Null);
            Assert.That(mixin.ThisValue, Is.Not.Null);
        }
コード例 #3
0
        public void MixinWithProtectedOverrider()
        {
            BaseType1 obj = CreateMixedObject <BaseType1> (typeof(MixinWithProtectedOverrider));

            Assert.That(obj.VirtualMethod(), Is.EqualTo("MixinWithProtectedOverrider.VirtualMethod-BaseType1.VirtualMethod"));
            Assert.That(obj.VirtualProperty, Is.EqualTo("MixinWithProtectedOverrider.VirtualProperty-BaseType1.BackingField"));

            Assert.That(obj.GetVirtualEventInvocationList(), Is.EqualTo(null));
            obj.VirtualEvent += delegate { };
            Assert.That(obj.GetVirtualEventInvocationList().Length, Is.EqualTo(2));
        }
コード例 #4
0
        public void OverrideClassEvents()
        {
            BaseType1 bt1 = CreateMixedObject <BaseType1> (typeof(BT1Mixin1));

            EventHandler eventHandler = delegate { };

            Assert.That(Mixin.Get <BT1Mixin1> (bt1).VirtualEventAddCalled, Is.False);
            bt1.VirtualEvent += eventHandler;
            Assert.That(Mixin.Get <BT1Mixin1> (bt1).VirtualEventAddCalled, Is.True);

            Assert.That(Mixin.Get <BT1Mixin1> (bt1).VirtualEventRemoveCalled, Is.False);
            bt1.VirtualEvent -= eventHandler;
            Assert.That(Mixin.Get <BT1Mixin1> (bt1).VirtualEventRemoveCalled, Is.True);

            Assert.IsNotNull(bt1.GetType().GetEvent("VirtualEvent"), "overridden member is public and has the same name");
        }
コード例 #5
0
        public void OverrideClassProperties()
        {
            BaseType1 bt1 = CreateMixedObject <BaseType1> (typeof(BT1Mixin1));

            Assert.That(bt1.VirtualProperty, Is.EqualTo("BaseType1.BackingField"));
            Assert.That(Mixin.Get <BT1Mixin1> (bt1).BackingField, Is.Not.EqualTo("FooBar"));

            bt1.VirtualProperty = "FooBar";
            Assert.That(bt1.VirtualProperty, Is.EqualTo("BaseType1.BackingField"));
            Assert.That(Mixin.Get <BT1Mixin1> (bt1).BackingField, Is.EqualTo("FooBar"));

            Assert.IsNotNull(bt1.GetType().GetProperty("VirtualProperty"), "overridden member is public and has the same name");

            bt1 = CreateMixedObject <BaseType1> (typeof(BT1Mixin2));

            Assert.That(bt1.VirtualProperty, Is.EqualTo("Mixin2ForBT1.VirtualProperty"));
            bt1.VirtualProperty = "Foobar";
            Assert.That(bt1.VirtualProperty, Is.EqualTo("Mixin2ForBT1.VirtualProperty"));
        }
コード例 #6
0
        public void ExtensionsAndConfigurationSerialized()
        {
            var bt1         = ObjectFactory.Create <BaseType1> (ParamList.Empty);
            var mixinTarget = (IMixinTarget)bt1;

            BaseType1 deserializedBT1         = Serializer.SerializeAndDeserialize(bt1);
            var       deserializedMixinTarget = (IMixinTarget)deserializedBT1;

            Assert.That(deserializedMixinTarget.ClassContext, Is.EqualTo(mixinTarget.ClassContext));

            Assert.That(deserializedMixinTarget.Mixins, Is.Not.Null);
            Assert.That(deserializedMixinTarget.Mixins.Length, Is.EqualTo(mixinTarget.Mixins.Length));
            Assert.That(deserializedMixinTarget.Mixins[0].GetType(), Is.EqualTo(mixinTarget.Mixins[0].GetType()));

            Assert.That(deserializedMixinTarget.FirstNextCallProxy, Is.Not.Null);
            Assert.That(deserializedMixinTarget.FirstNextCallProxy, Is.Not.EqualTo(mixinTarget.FirstNextCallProxy));
            Assert.That(deserializedMixinTarget.FirstNextCallProxy.GetType(), Is.EqualTo(deserializedMixinTarget.GetType().GetNestedType("NextCallProxy")));
            Assert.That(deserializedMixinTarget.FirstNextCallProxy.GetType().GetField("__depth").GetValue(deserializedMixinTarget.FirstNextCallProxy), Is.EqualTo(0));
            Assert.That(deserializedMixinTarget.FirstNextCallProxy.GetType().GetField("__this").GetValue(deserializedMixinTarget.FirstNextCallProxy), Is.SameAs(deserializedMixinTarget));
        }
コード例 #7
0
        public void AttributesReplicatedFromMixinViaIntroduction()
        {
            BaseType1 bt1 = CreateMixedObject <BaseType1> (typeof(MixinWithPropsEventAtts));

            Assert.That(bt1.GetType().IsDefined(typeof(BT1Attribute), false), Is.False);
            Assert.IsTrue(bt1.GetType().IsDefined(typeof(BT1Attribute), true), "Attribute is inherited");
            Assert.That(bt1.GetType().IsDefined(typeof(ReplicatableAttribute), false), Is.True);

            var atts = (ReplicatableAttribute[])bt1.GetType().GetCustomAttributes(typeof(ReplicatableAttribute), false);

            Assert.That(atts.Length, Is.EqualTo(1));
            Assert.That(atts[0].I, Is.EqualTo(4));

            PropertyInfo property = bt1.GetType().GetProperty(typeof(IMixinWithPropsEventsAtts).FullName + ".Property",
                                                              BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(property, Is.Not.Null);
            atts = (ReplicatableAttribute[])property.GetCustomAttributes(typeof(ReplicatableAttribute), false);
            Assert.That(atts.Length, Is.EqualTo(1));
            Assert.That(atts[0].S, Is.EqualTo("bla"));
            Assert.That(property.GetGetMethod(true).IsSpecialName, Is.True);
            atts = (ReplicatableAttribute[])property.GetGetMethod(true).GetCustomAttributes(typeof(ReplicatableAttribute), false);
            Assert.That(atts[0].Named2, Is.EqualTo(1.0));

            Assert.That(property.GetSetMethod(true).IsSpecialName, Is.True);
            atts = (ReplicatableAttribute[])property.GetSetMethod(true).GetCustomAttributes(typeof(ReplicatableAttribute), false);
            Assert.That(atts[0].Named2, Is.EqualTo(2.0));

            EventInfo eventInfo = bt1.GetType().GetEvent(typeof(IMixinWithPropsEventsAtts).FullName + ".Event",
                                                         BindingFlags.NonPublic | BindingFlags.Instance);

            Assert.That(eventInfo, Is.Not.Null);
            atts = (ReplicatableAttribute[])eventInfo.GetCustomAttributes(typeof(ReplicatableAttribute), false);
            Assert.That(atts.Length, Is.EqualTo(1));
            Assert.That(atts[0].S, Is.EqualTo("blo"));
            Assert.That(eventInfo.GetAddMethod(true).IsSpecialName, Is.True);
            Assert.That(eventInfo.GetAddMethod(true).IsDefined(typeof(ReplicatableAttribute), false), Is.True);
            Assert.That(eventInfo.GetRemoveMethod(true).IsSpecialName, Is.True);
            Assert.That(eventInfo.GetRemoveMethod(true).IsDefined(typeof(ReplicatableAttribute), false), Is.True);
        }
コード例 #8
0
        public void DeserializedMembersFit()
        {
            var bt1 = ObjectFactory.Create <BaseType1> (ParamList.Empty);

            Assert.That(bt1.GetType().IsSerializable, Is.True);

            bt1.I = 25;
            BaseType1 bt1a = Serializer.SerializeAndDeserialize(bt1);

            Assert.That(bt1a, Is.Not.SameAs(bt1));
            Assert.That(bt1a.I, Is.EqualTo(bt1.I));

            var bt2 = CreateMixedObject <BaseType2> (typeof(BT2Mixin1));

            Assert.That(bt2.GetType().IsSerializable, Is.True);

            bt2.S = "Bla";
            BaseType2 bt2a = Serializer.SerializeAndDeserialize(bt2);

            Assert.That(bt2a, Is.Not.SameAs(bt2));
            Assert.That(bt2a.S, Is.EqualTo(bt2.S));
        }
コード例 #9
0
        public void ValueTypeMixin()
        {
            BaseType1 bt1 = CreateMixedObject <BaseType1>(typeof(ValueTypeMixin));

            Assert.That(bt1.VirtualMethod(), Is.EqualTo("ValueTypeMixin.VirtualMethod"));
        }