public void CreateRequiredMethodDefinitions_BaseWithSameMembers()
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers));

            DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTyping).GetMethod("Method1"));
            DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTyping).GetMethod("Method2"));
            var m1b = DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers).GetMethod("Method1"));
            var m2b = DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers).GetMethod("Method2"));

            var requirement = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IInterface));
            var builder     = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition);

            var definitions = builder.CreateRequiredMethodDefinitions(requirement).OrderBy(def => def.FullName).ToArray();

            Assert.That(definitions.Length, Is.EqualTo(2));

            Assert.That(definitions[0].DeclaringRequirement, Is.SameAs(requirement));
            Assert.That(definitions[0].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method1")));
            Assert.That(definitions[0].ImplementingMethod, Is.SameAs(m1b));

            Assert.That(definitions[1].DeclaringRequirement, Is.SameAs(requirement));
            Assert.That(definitions[1].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method2")));
            Assert.That(definitions[1].ImplementingMethod, Is.SameAs(m2b));
        }
        public void ChildSpecificAccept()
        {
            var targetClassDefinition                 = DefinitionObjectMother.CreateTargetClassDefinition(typeof(BaseType1), typeof(BT1Mixin1));
            var mixinDefinition                       = targetClassDefinition.Mixins[0];
            var requiredTargetCallTypeDefinition      = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IBT1Mixin1));
            var requiredNextCallTypeDefinition        = DefinitionObjectMother.CreateRequiredNextCallTypeDefinition(targetClassDefinition, typeof(IBT1Mixin1));
            var requiredMixinTypeDefinition           = DefinitionObjectMother.CreateRequiredMixinTypeDefinition(targetClassDefinition, typeof(BT1Mixin2));
            var composedInterfaceDependencyDefinition = DefinitionObjectMother.CreateComposedInterfaceDependencyDefinition(targetClassDefinition);

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

            using (visitorMock.GetMockRepository().Ordered())
            {
                visitorMock.Expect(mock => mock.Visit(targetClassDefinition));
                visitorMock.Expect(mock => mock.Visit(mixinDefinition));
                visitorMock.Expect(mock => mock.Visit(requiredTargetCallTypeDefinition));
                visitorMock.Expect(mock => mock.Visit(requiredNextCallTypeDefinition));
                visitorMock.Expect(mock => mock.Visit(requiredMixinTypeDefinition));
                visitorMock.Expect(mock => mock.Visit(composedInterfaceDependencyDefinition));
            }

            visitorMock.Replay();

            targetClassDefinition.Accept(visitorMock);

            visitorMock.VerifyAllExpectations();
        }
        public void CreateRequiredMethodDefinitions_NoMatch_NoRequiringMixin()
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(object));

            var requirement = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IInterface));
            var builder     = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition);

            builder.CreateRequiredMethodDefinitions(requirement).ToArray();
        }
Exemple #4
0
        public void Accept()
        {
            var targetClass = DefinitionObjectMother.CreateTargetClassDefinition(typeof(NullTarget));
            var requiredTargetCallTypeDefinition = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClass, typeof(ISimpleInterface));
            var dependency = new ComposedInterfaceDependencyDefinition(requiredTargetCallTypeDefinition, typeof(ISimpleInterface), null);

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

            dependency.Accept(visitorMock);

            visitorMock.AssertWasCalled(mock => mock.Visit(dependency));
        }
        public void CreateRequiredMethodDefinitions_WithOverloads()
        {
            var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads));

            DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads).GetMethod("Method1", new[] { typeof(string) }));
            var m1b = DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads).GetMethod("Method1", Type.EmptyTypes));

            DefinitionObjectMother.CreateMethodDefinition(
                targetClassDefinition,
                typeof(ClassImplementingInterfaceWithDuckTypingWithOverloads).GetMethod("Method2"));

            var requirement = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IInterface));
            var builder     = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition);

            var definitions = builder.CreateRequiredMethodDefinitions(requirement).OrderBy(def => def.FullName).ToArray();

            Assert.That(definitions[0].DeclaringRequirement, Is.SameAs(requirement));
            Assert.That(definitions[0].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method1")));
            Assert.That(definitions[0].ImplementingMethod, Is.SameAs(m1b));
        }