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)));
        }
        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");
        }
        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"));
        }
        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);
        }