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)); }
public void OverriddenMixinMethod() { TargetClassDefinition overrider = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassOverridingMixinMembers)); MixinDefinition mixin = overrider.Mixins[typeof(MixinWithAbstractMembers)]; Assert.That(mixin, Is.Not.Null); Assert.That(mixin.HasOverriddenMembers(), Is.True); MethodDefinition method = mixin.Methods[typeof(MixinWithAbstractMembers).GetMethod("AbstractMethod", BindingFlags.Instance | BindingFlags.NonPublic)]; Assert.That(method, Is.Not.Null); MethodDefinition overridingMethod = overrider.Methods[typeof(ClassOverridingMixinMembers).GetMethod("AbstractMethod")]; Assert.That(overridingMethod, Is.Not.Null); Assert.That(overridingMethod.Base, Is.SameAs(method)); Assert.That(method.Overrides.ContainsKey(typeof(ClassOverridingMixinMembers)), Is.True); Assert.That(method.Overrides[typeof(ClassOverridingMixinMembers)], Is.SameAs(overridingMethod)); }