Exemple #1
0
        public void PropertyOverrides()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
            MixinDefinition       mixin1      = targetClass.Mixins[typeof(BT1Mixin1)];
            MixinDefinition       mixin2      = targetClass.Mixins[typeof(BT1Mixin2)];

            PropertyInfo baseProperty1  = typeof(BaseType1).GetProperty("VirtualProperty");
            PropertyInfo baseProperty2  = typeof(BaseType1).GetProperty("Item", new[] { typeof(string) });
            PropertyInfo mixinProperty1 = typeof(BT1Mixin1).GetProperty("VirtualProperty");

            PropertyDefinition overridden = targetClass.Properties[baseProperty1];

            Assert.That(overridden.Overrides.ContainsKey(typeof(BT1Mixin1)), Is.True);

            PropertyDefinition overrider = overridden.Overrides[typeof(BT1Mixin1)];

            Assert.That(mixin1.Properties[mixinProperty1], Is.SameAs(overrider));
            Assert.That(overrider.Base, Is.Not.Null);
            Assert.That(overrider.Base, Is.SameAs(overridden));
            Assert.That(overrider.SetMethod.Base, Is.SameAs(overridden.SetMethod));

            PropertyDefinition notOverridden = targetClass.Properties[baseProperty2];

            Assert.That(notOverridden.Overrides.Count, Is.EqualTo(0));

            Assert.That(overridden.Overrides.ContainsKey(typeof(BT1Mixin2)), Is.True);
            overrider = overridden.Overrides[typeof(BT1Mixin2)];

            Assert.That(new List <MemberDefinitionBase> (mixin2.GetAllOverrides()).Contains(overrider), Is.True);
            Assert.That(overrider.Base, Is.SameAs(overridden));
            Assert.That(overrider.GetMethod.Base, Is.SameAs(overridden.GetMethod));
        }
Exemple #2
0
        public void EventOverrides()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
            MixinDefinition       mixin1      = targetClass.Mixins[typeof(BT1Mixin1)];
            MixinDefinition       mixin2      = targetClass.Mixins[typeof(BT1Mixin2)];

            EventInfo baseEvent1  = typeof(BaseType1).GetEvent("VirtualEvent");
            EventInfo baseEvent2  = typeof(BaseType1).GetEvent("ExplicitEvent");
            EventInfo mixinEvent1 = typeof(BT1Mixin1).GetEvent("VirtualEvent");

            EventDefinition overridden = targetClass.Events[baseEvent1];

            Assert.That(overridden.Overrides.ContainsKey(typeof(BT1Mixin1)), Is.True);

            EventDefinition overrider = overridden.Overrides[typeof(BT1Mixin1)];

            Assert.That(mixin1.Events[mixinEvent1], Is.SameAs(overrider));
            Assert.That(overrider.Base, Is.Not.Null);
            Assert.That(overrider.Base, Is.SameAs(overridden));
            Assert.That(overrider.RemoveMethod.Base, Is.SameAs(overridden.RemoveMethod));
            Assert.That(overrider.AddMethod.Base, Is.SameAs(overridden.AddMethod));

            EventDefinition notOverridden = targetClass.Events[baseEvent2];

            Assert.That(notOverridden.Overrides.Count, Is.EqualTo(0));

            Assert.That(overridden.Overrides.ContainsKey(typeof(BT1Mixin2)), Is.True);
            overrider = overridden.Overrides[typeof(BT1Mixin2)];

            Assert.That(new List <MemberDefinitionBase> (mixin2.GetAllOverrides()).Contains(overrider), Is.True);
            Assert.That(overrider.Base, Is.SameAs(overridden));
            Assert.That(overrider.AddMethod.Base, Is.SameAs(overridden.AddMethod));
            Assert.That(overrider.RemoveMethod.Base, Is.SameAs(overridden.RemoveMethod));
        }
Exemple #3
0
        public void MethodOverrides()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
            MixinDefinition       mixin1      = targetClass.Mixins[typeof(BT1Mixin1)];
            MixinDefinition       mixin2      = targetClass.Mixins[typeof(BT1Mixin2)];

            Assert.That(mixin1.HasOverriddenMembers(), Is.False);
            Assert.That(mixin2.HasOverriddenMembers(), Is.False);
            Assert.That(targetClass.HasOverriddenMembers(), Is.True);

            MethodInfo baseMethod1  = typeof(BaseType1).GetMethod("VirtualMethod", new Type[0]);
            MethodInfo baseMethod2  = typeof(BaseType1).GetMethod("VirtualMethod", new[] { typeof(string) });
            MethodInfo mixinMethod1 = typeof(BT1Mixin1).GetMethod("VirtualMethod", new Type[0]);

            MethodDefinition overridden = targetClass.Methods[baseMethod1];

            Assert.That(overridden.Overrides.ContainsKey(typeof(BT1Mixin1)), Is.True);
            MethodDefinition overrider = overridden.Overrides[typeof(BT1Mixin1)];

            Assert.That(mixin1.Methods[mixinMethod1], Is.SameAs(overrider));
            Assert.That(overrider.Base, Is.Not.Null);
            Assert.That(overrider.Base, Is.SameAs(overridden));

            MethodDefinition notOverridden = targetClass.Methods[baseMethod2];

            Assert.That(notOverridden.Overrides.Count, Is.EqualTo(0));

            Assert.That(overridden.Overrides.ContainsKey(typeof(BT1Mixin2)), Is.True);
            overrider = overridden.Overrides[typeof(BT1Mixin2)];

            Assert.That(new List <MemberDefinitionBase> (mixin2.GetAllOverrides()).Contains(overrider), Is.True);
            Assert.That(overrider.Base, Is.SameAs(overridden));
        }