Beispiel #1
0
        public void GetAllOverrides()
        {
            var definition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(BaseType1), typeof(BT1Mixin1)).Mixins[0];

            var methodOverride   = DefinitionObjectMother.CreateMethodDefinition(definition, definition.Type.GetMethod("ToString"));
            var overriddenMethod = DefinitionObjectMother.CreateMethodDefinition(definition.TargetClass, definition.Type.GetMethod("ToString"));

            DefinitionObjectMother.DeclareOverride(methodOverride, overriddenMethod);

            var propertyOverride   = DefinitionObjectMother.CreatePropertyDefinition(definition, typeof(DateTime).GetProperty("Now"));
            var overriddenProperty = DefinitionObjectMother.CreatePropertyDefinition(definition.TargetClass, typeof(DateTime).GetProperty("Now"));

            DefinitionObjectMother.DeclareOverride(propertyOverride, overriddenProperty);

            var eventOverride   = DefinitionObjectMother.CreateEventDefinition(definition, typeof(AppDomain).GetEvent("ProcessExit"));
            var overriddenEvent = DefinitionObjectMother.CreateEventDefinition(definition.TargetClass, typeof(AppDomain).GetEvent("ProcessExit"));

            DefinitionObjectMother.DeclareOverride(eventOverride, overriddenEvent);

            var nonOverride = DefinitionObjectMother.CreateMethodDefinition(definition, definition.Type.GetMethod("GetHashCode"));

            var overrides = definition.GetAllOverrides().ToArray();

            Assert.That(overrides, Is.EquivalentTo(new MemberDefinitionBase[] { methodOverride, propertyOverride, eventOverride }));
            Assert.That(overrides, Has.No.Member(nonOverride));
        }
        public void GetProtectedOverriders_False()
        {
            var overrider  = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1);
            var overridden = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2);

            DefinitionObjectMother.DeclareOverride(overrider, overridden);

            Assert.That(_classDefinition1.GetProtectedOverriders().ToArray(), Is.Empty);
        }
        public void GetProtectedOverriders_True_ProtectedInternal()
        {
            var overrider  = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfoProtectedInternal);
            var overridden = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2);

            DefinitionObjectMother.DeclareOverride(overrider, overridden);

            Assert.That(_classDefinition1.GetProtectedOverriders().ToArray(), Is.EqualTo(new[] { overrider }));
        }
        public void HasProtectedOverriders_True_ProtectedInternal()
        {
            var overrider  = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfoProtectedInternal);
            var overridden = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2);

            DefinitionObjectMother.DeclareOverride(overrider, overridden);

            Assert.That(_classDefinition1.HasProtectedOverriders(), Is.True);
        }
        public void HasOverriddenMembers_True()
        {
            var overriddenMember = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1);
            var overriderMember  = DefinitionObjectMother.CreateMethodDefinition(_classDefinition2, _methodInfo2);

            DefinitionObjectMother.DeclareOverride(overriderMember, overriddenMember);

            Assert.That(_classDefinition1.HasOverriddenMembers(), Is.True);
        }
        public void GetProtectedOverriders_True()
        {
            var overrider1  = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfoProtected);
            var overrider2  = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1);
            var overridden1 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2);
            var overridden2 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo3);

            DefinitionObjectMother.DeclareOverride(overrider1, overridden1);
            DefinitionObjectMother.DeclareOverride(overrider2, overridden2);

            Assert.That(_classDefinition1.GetProtectedOverriders().ToArray(), Is.EqualTo(new[] { overrider1 }));
        }
        private void AddOverride(TargetClassDefinition targetClassDefinition, Type mixinType, string methodName)
        {
            var baseMember = targetClassDefinition.GetAllMethods().SingleOrDefault(m => m.Name == methodName);

            if (baseMember == null)
            {
                baseMember = DefinitionObjectMother.CreateMethodDefinition(targetClassDefinition, targetClassDefinition.Type.GetMethod(methodName));
            }

            var mixinDefinition  = targetClassDefinition.Mixins.Single(m => m.Type == mixinType);
            var overridingMember = DefinitionObjectMother.CreateMethodDefinition(mixinDefinition, mixinType.GetMethod(methodName));

            DefinitionObjectMother.DeclareOverride(overridingMember, baseMember);
        }