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 GetAllMembers()
        {
            var methodDefinition1   = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1);
            var propertyDefinition1 = DefinitionObjectMother.CreatePropertyDefinition(_classDefinition1, _propertyInfoWithGetAndSet);
            var eventDefinition1    = DefinitionObjectMother.CreateEventDefinition(_classDefinition1, _eventInfo1);

            Assert.That(_classDefinition1.GetAllMembers().ToArray(),
                        Is.EquivalentTo(new MemberDefinitionBase[] { methodDefinition1, propertyDefinition1, eventDefinition1 }));
        }
        public void GetAllMethods_FindsEventAccessors()
        {
            var eventDefinition1 = DefinitionObjectMother.CreateEventDefinition(_classDefinition1, _eventInfo1);
            var eventDefinition2 = DefinitionObjectMother.CreateEventDefinition(_classDefinition1, _eventInfo2);

            Assert.That(_classDefinition1.GetAllMethods().ToArray(), Is.EquivalentTo(new[] {
                eventDefinition1.AddMethod,
                eventDefinition1.RemoveMethod,
                eventDefinition2.AddMethod,
                eventDefinition2.RemoveMethod
            }));
        }
        public void Accept()
        {
            var methodDefinition    = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1);
            var propertyDefinition  = DefinitionObjectMother.CreatePropertyDefinition(_classDefinition1, _propertyInfoWithGetAndSet);
            var eventDefinition     = DefinitionObjectMother.CreateEventDefinition(_classDefinition1, _eventInfo1);
            var attributeDefinition = DefinitionObjectMother.CreateAttributeDefinition(_classDefinition1);

            var visitorMock = MockRepository.GenerateMock <IDefinitionVisitor> ();

            using (visitorMock.GetMockRepository().Ordered())
            {
                visitorMock.Expect(mock => mock.Visit(methodDefinition));
                visitorMock.Expect(mock => mock.Visit(propertyDefinition));
                visitorMock.Expect(mock => mock.Visit(eventDefinition));
                visitorMock.Expect(mock => mock.Visit(attributeDefinition));
            }

            visitorMock.Replay();

            _classDefinition1.Accept(visitorMock);
            Assert.That(_classDefinition1.ChildSpecificAcceptCalled, Is.True);

            visitorMock.VerifyAllExpectations();
        }