public void NoRequiredMethodsWhenFaceRequirementIsClass()
        {
            TargetClassDefinition            targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassWithStaticMethod));
            RequiredTargetCallTypeDefinition requirement = targetClass.RequiredTargetCallTypes[typeof(ClassWithStaticMethod)];

            Assert.That(requirement.Methods.Count, Is.EqualTo(0));
        }
        public void ProtectedInternalMembers()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassWithInheritedMethod));

            Assert.That(targetClass.Methods.ContainsKey(typeof(BaseClassWithInheritedMethod).GetMethod("ProtectedInternalInheritedMethod",
                                                                                                       BindingFlags.Instance | BindingFlags.NonPublic)), Is.True);
        }
 public void ThrowsIfRequiredMethodIsInternal()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <ClassFulfillingInternally> ().Clear().AddMixins(typeof(MixinRequiringAllMembersTargetCall)).EnterScope())
     {
         DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassFulfillingInternally));
     }
 }
Example #4
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));
        }
Example #5
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));
        }
Example #6
0
 public void TargetClassOverridingSpecificUnconfiguredMixinMethod()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <ClassOverridingSpecificMixinMember> ().Clear().AddMixins(typeof(MixinWithVirtualMethod2)).EnterScope())
     {
         DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassOverridingSpecificMixinMember));
     }
 }
Example #7
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));
        }
Example #8
0
 public void ThrowsOnTargetClassOverridingMultipleMixinMethods()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <ClassOverridingMixinMembers> ().Clear().AddMixins(typeof(MixinWithAbstractMembers), typeof(MixinWithSingleAbstractMethod2)).EnterScope())
     {
         DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassOverridingMixinMembers));
     }
 }
        public void HasProtectedOverridersFalse()
        {
            TargetClassDefinition bt1 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));

            Assert.That(bt1.HasProtectedOverriders(), Is.False);
            Assert.That(bt1.Mixins[0].HasProtectedOverriders(), Is.False);
        }
        public void ExplicitMixinDependenciesCorrectlyCopied()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(TargetClassWithAdditionalDependencies));

            Assert.That(targetClass.RequiredMixinTypes.ContainsKey(typeof(MixinWithNoAdditionalDependency)), Is.True);
            Assert.That(targetClass.Mixins[typeof(MixinWithAdditionalClassDependency)].MixinDependencies.ContainsKey(typeof(MixinWithNoAdditionalDependency)), Is.True);
        }
Example #11
0
        public void NeedsDerivedMixinType_True_OverriddenMember()
        {
            var definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassOverridingMixinMembers))
                             .Mixins[typeof(MixinWithAbstractMembers)];

            Assert.That(definition.NeedsDerivedMixinType(), Is.True);
        }
Example #12
0
        public void MixinsIntroduceAttributes()
        {
            TargetClassDefinition bt1 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));

            Assert.That(bt1.CustomAttributes.Count, Is.EqualTo(2));
            Assert.That(bt1.CustomAttributes.ContainsKey(typeof(BT1Attribute)), Is.True);
            Assert.That(bt1.CustomAttributes.ContainsKey(typeof(DefaultMemberAttribute)), Is.True);

            MixinDefinition mixin1 = bt1.Mixins[typeof(BT1Mixin1)];

            Assert.That(mixin1.CustomAttributes.Count, Is.EqualTo(1));
            Assert.That(mixin1.CustomAttributes.ContainsKey(typeof(BT1M1Attribute)), Is.True);
            Assert.That(mixin1.AttributeIntroductions.Count, Is.EqualTo(1));
            Assert.That(mixin1.AttributeIntroductions.ContainsKey(typeof(BT1M1Attribute)), Is.True);

            MixinDefinition mixin2 = bt1.Mixins[typeof(BT1Mixin2)];

            Assert.That(mixin2.CustomAttributes.Count, Is.EqualTo(0));
            Assert.That(mixin2.AttributeIntroductions.Count, Is.EqualTo(0));

            Assert.That(bt1.ReceivedAttributes.Count, Is.EqualTo(1));
            Assert.That(bt1.ReceivedAttributes[0].Attribute, Is.SameAs(mixin1.CustomAttributes[0]));
            Assert.That(bt1.ReceivedAttributes[0], Is.SameAs(mixin1.AttributeIntroductions[0]));
            Assert.That(bt1.ReceivedAttributes[0].Parent, Is.SameAs(mixin1));
            Assert.That(bt1.ReceivedAttributes[0].FullName, Is.EqualTo(mixin1.CustomAttributes[0].FullName));
            Assert.That(bt1.ReceivedAttributes[0].AttributeType, Is.EqualTo(mixin1.CustomAttributes[0].AttributeType));
        }
Example #13
0
        public void IntroducedInterfaceOverInheritance()
        {
            using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(DerivedIntroducer)).EnterScope())
            {
                TargetClassDefinition bt1 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
                Assert.That(bt1.ReceivedInterfaces.ContainsKey(typeof(IIntroducedDerived)), Is.True);
                Assert.That(bt1.ReceivedInterfaces.ContainsKey(typeof(IIntroducedBase)), Is.True);

                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedDerived)].IntroducedMethods.Count, Is.EqualTo(0));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedDerived)].IntroducedProperties.Count, Is.EqualTo(0));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedDerived)].IntroducedEvents.Count, Is.EqualTo(0));

                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedMethods.Count, Is.EqualTo(1));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedProperties.Count, Is.EqualTo(1));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedEvents.Count, Is.EqualTo(1));

                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedMethods[0].InterfaceMember, Is.EqualTo(typeof(IIntroducedBase).GetMethod("Foo")));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedProperties[0].InterfaceMember, Is.EqualTo(typeof(IIntroducedBase).GetProperty("FooP")));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedEvents[0].InterfaceMember, Is.EqualTo(typeof(IIntroducedBase).GetEvent("FooE")));

                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedMethods[0].ImplementingMember.DeclaringClass, Is.EqualTo(bt1.Mixins[typeof(DerivedIntroducer)]));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedProperties[0].ImplementingMember.DeclaringClass, Is.EqualTo(bt1.Mixins[typeof(DerivedIntroducer)]));
                Assert.That(bt1.ReceivedInterfaces[typeof(IIntroducedBase)].IntroducedEvents[0].ImplementingMember.DeclaringClass, Is.EqualTo(bt1.Mixins[typeof(DerivedIntroducer)]));
            }
        }
Example #14
0
        public void FaceInterfaces()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3));

            Assert.That(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(IBaseType31)), Is.True);
            Assert.That(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(IBaseType32)), Is.True);
            Assert.That(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(IBaseType33)), Is.True);
            Assert.That(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(IBaseType2)), Is.False);

            CheckAllRequiringEntities(
                targetClass.RequiredTargetCallTypes[typeof(IBaseType31)],
                targetClass.Mixins[typeof(BT3Mixin1)], targetClass.GetMixinByConfiguredType(typeof(BT3Mixin6 <,>)));

            Assert.That(targetClass.RequiredTargetCallTypes[typeof(IBaseType31)].IsEmptyInterface, Is.False);
            Assert.That(targetClass.RequiredTargetCallTypes[typeof(IBaseType31)].IsAggregatorInterface, Is.False);

            targetClass = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin4), typeof(Bt3Mixin7TargetCall));
            Assert.That(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(ICBaseType3BT3Mixin4)), Is.True);

            CheckAllRequiringEntities(
                targetClass.RequiredTargetCallTypes[typeof(ICBaseType3BT3Mixin4)],
                targetClass.Mixins[typeof(Bt3Mixin7TargetCall)]);
            CheckAllRequiringEntities(
                targetClass.RequiredTargetCallTypes[typeof(BaseType3)],
                targetClass.Mixins[typeof(BT3Mixin4)]);
        }
Example #15
0
 public void ThrowsWhenUnfulfilledDuckBase()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(DuckBaseMixinWithoutOverrides)).EnterScope())
     {
         DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget));
     }
 }
Example #16
0
        public void IntroducedMembers()
        {
            TargetClassDefinition           targetClass         = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
            MixinDefinition                 mixin1              = targetClass.Mixins[typeof(BT1Mixin1)];
            InterfaceIntroductionDefinition introducedInterface = mixin1.InterfaceIntroductions[typeof(IBT1Mixin1)];

            Assert.That(introducedInterface.IntroducedMethods.ContainsKey(typeof(IBT1Mixin1).GetMethod("IntroducedMethod")), Is.True);
            Assert.That(introducedInterface.IntroducedProperties.ContainsKey(typeof(IBT1Mixin1).GetProperty("IntroducedProperty")), Is.True);
            Assert.That(introducedInterface.IntroducedEvents.ContainsKey(typeof(IBT1Mixin1).GetEvent("IntroducedEvent")), Is.True);

            MethodIntroductionDefinition method = introducedInterface.IntroducedMethods[typeof(IBT1Mixin1).GetMethod("IntroducedMethod")];

            Assert.That(method, Is.Not.EqualTo(mixin1.Methods[typeof(BT1Mixin1).GetMethod("IntroducedMethod")]));
            Assert.That(method.ImplementingMember, Is.SameAs(mixin1.Methods[typeof(BT1Mixin1).GetMethod("IntroducedMethod")]));
            Assert.That(method.DeclaringInterface, Is.SameAs(introducedInterface));
            Assert.That(method.Parent, Is.SameAs(introducedInterface));

            PropertyIntroductionDefinition property = introducedInterface.IntroducedProperties[typeof(IBT1Mixin1).GetProperty("IntroducedProperty")];

            Assert.That(property, Is.Not.EqualTo(mixin1.Properties[typeof(BT1Mixin1).GetProperty("IntroducedProperty")]));
            Assert.That(property.ImplementingMember, Is.SameAs(mixin1.Properties[typeof(BT1Mixin1).GetProperty("IntroducedProperty")]));
            Assert.That(property.DeclaringInterface, Is.SameAs(introducedInterface));
            Assert.That(method.Parent, Is.SameAs(introducedInterface));

            EventIntroductionDefinition eventDefinition = introducedInterface.IntroducedEvents[typeof(IBT1Mixin1).GetEvent("IntroducedEvent")];

            Assert.That(eventDefinition, Is.Not.EqualTo(mixin1.Events[typeof(BT1Mixin1).GetEvent("IntroducedEvent")]));
            Assert.That(eventDefinition.ImplementingMember, Is.SameAs(mixin1.Events[typeof(BT1Mixin1).GetEvent("IntroducedEvent")]));
            Assert.That(eventDefinition.DeclaringInterface, Is.SameAs(introducedInterface));
            Assert.That(method.Parent, Is.SameAs(introducedInterface));
        }
        public void GeneratedTypeImplementsRequiredNextCallInterfaces2()
        {
            using (MixinConfiguration.BuildFromActive().ForClass <BaseType3> ().Clear().AddMixins(typeof(BT3Mixin7Base), typeof(BT3Mixin4)).EnterScope())
            {
                Type t         = TypeFactory.GetConcreteType(typeof(BaseType3));
                Type proxyType = t.GetNestedType("NextCallProxy");

                RequiredNextCallTypeDefinition bt3Mixin4Req =
                    DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).RequiredNextCallTypes[typeof(IBT3Mixin4)];
                Assert.That(bt3Mixin4Req, Is.Not.Null);
                Assert.That(bt3Mixin4Req.Type.IsAssignableFrom(proxyType), Is.True);

                foreach (RequiredNextCallTypeDefinition req in DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).RequiredNextCallTypes)
                {
                    Assert.That(req.Type.IsAssignableFrom(proxyType), Is.True);
                }

                MethodInfo methodImplementdByMixin =
                    proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.IBT3Mixin4.Foo", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.That(methodImplementdByMixin, Is.Not.Null);

                MethodInfo methodImplementdByBCOverridden =
                    proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.IBaseType31.IfcMethod", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.That(methodImplementdByBCOverridden, Is.Not.Null);

                MethodInfo methodImplementdByBCNotOverridden =
                    proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.IBaseType35.IfcMethod2", BindingFlags.NonPublic | BindingFlags.Instance);
                Assert.That(methodImplementdByBCNotOverridden, Is.Not.Null);
            }
        }
Example #18
0
        public void DuckTypingBaseInterface()
        {
            using (MixinConfiguration.BuildFromActive().ForClass <BaseTypeWithDuckBaseMixin> ().Clear().AddMixins(typeof(DuckBaseMixin)).EnterScope())
            {
                TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseTypeWithDuckBaseMixin));
                Assert.That(targetClass.Mixins.ContainsKey(typeof(DuckBaseMixin)), Is.True);
                MixinDefinition mixin = targetClass.Mixins[typeof(DuckBaseMixin)];
                Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IDuckBaseRequirements)), Is.True);
                CheckAllRequiringEntities(
                    targetClass.RequiredNextCallTypes[typeof(IDuckBaseRequirements)],
                    mixin);

                Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IDuckBaseRequirements)), Is.True);
                Assert.That(mixin.NextCallDependencies[typeof(IDuckBaseRequirements)].GetImplementer(), Is.SameAs(targetClass));

                Assert.That(mixin.NextCallDependencies[typeof(IDuckBaseRequirements)].Depender, Is.SameAs(mixin));
                Assert.That(mixin.NextCallDependencies[typeof(IDuckBaseRequirements)].Aggregator, Is.Null);
                Assert.That(mixin.NextCallDependencies[typeof(IDuckBaseRequirements)].AggregatedDependencies.Count, Is.EqualTo(0));

                Assert.That(mixin.NextCallDependencies[typeof(IDuckBaseRequirements)].RequiredType, Is.SameAs(targetClass.RequiredNextCallTypes[typeof(IDuckBaseRequirements)]));

                Assert.That(targetClass.RequiredNextCallTypes[typeof(IDuckBaseRequirements)].Methods.Count, Is.EqualTo(2));
                Assert.That(targetClass.RequiredNextCallTypes[typeof(IDuckBaseRequirements)].Methods[0].InterfaceMethod, Is.SameAs(typeof(IDuckBaseRequirements).GetMethod("MethodImplementedOnBase")));
                Assert.That(targetClass.RequiredNextCallTypes[typeof(IDuckBaseRequirements)].Methods[0].ImplementingMethod, Is.SameAs(targetClass.Methods[typeof(BaseTypeWithDuckBaseMixin).GetMethod("MethodImplementedOnBase")]));
            }
        }
Example #19
0
 public void IDeserializationCallbackIsNotIntroduced()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(MixinImplementingISerializable)).EnterScope())
     {
         Assert.That(DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1)).Mixins[typeof(MixinImplementingISerializable)].InterfaceIntroductions[typeof(IDeserializationCallback)], Is.Null);
     }
 }
Example #20
0
 public void ThrowsOnDoublyIntroducedInterface()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(BT1Mixin1), typeof(BT1Mixin1A)).EnterScope())
     {
         DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
     }
 }
        public void CopyAttributes_OnClass()
        {
            using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(MixinIndirectlyAddingAttribute)).EnterScope())
            {
                MixinDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(MixinIndirectlyAddingAttribute)];
                Assert.That(definition.CustomAttributes.ContainsKey(typeof(CopyCustomAttributesAttribute)), Is.False);
                Assert.That(definition.CustomAttributes.ContainsKey(typeof(AttributeWithParameters)), Is.True);

                var attributes = new List <AttributeDefinition> (definition.CustomAttributes[typeof(AttributeWithParameters)]);

                Assert.That(attributes.Count, Is.EqualTo(1));
                Assert.That(attributes[0].IsCopyTemplate, Is.True);

                Assert.That(attributes[0].AttributeType, Is.EqualTo(typeof(AttributeWithParameters)));
                Assert.That(
                    attributes[0].Data.Constructor, Is.EqualTo(typeof(AttributeWithParameters).GetConstructor(new[] { typeof(int), typeof(string) })));
                Assert.That(attributes[0].DeclaringDefinition, Is.EqualTo(definition));

                Assert.That(attributes[0].Data.ConstructorArguments.Count, Is.EqualTo(2));
                Assert.That(attributes[0].Data.ConstructorArguments[0], Is.EqualTo(1));
                Assert.That(attributes[0].Data.ConstructorArguments[1], Is.EqualTo("bla"));

                var namedArgumentData         = attributes[0].Data.NamedArguments.Select(n => new { n.MemberInfo, n.Value }).ToArray();
                var expectedNamedArgumentData =
                    new[]
                {
                    new { MemberInfo = (MemberInfo)typeof(AttributeWithParameters).GetField("Field"), Value = (object)5 },
                    new { MemberInfo = (MemberInfo)typeof(AttributeWithParameters).GetProperty("Property"), Value = (object)4 }
                };
                Assert.That(namedArgumentData, Is.EquivalentTo(expectedNamedArgumentData));
            }
        }
Example #22
0
        public void IndirectNextCallDependencies()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassImplementingIndirectRequirements));
            MixinDefinition       mixin       = targetClass.Mixins[typeof(MixinWithIndirectRequirements)];

            Assert.That(mixin, Is.Not.Null);

            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectBaseAggregator)), Is.True);
            Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectBaseAggregator)].IsAggregatorInterface, Is.True);

            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirement1)), Is.True);
            Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirement1)].IsAggregatorInterface, Is.False);
            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirementBase1)), Is.True);
            Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirementBase1)].IsAggregatorInterface, Is.False);

            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirement2)), Is.False);
            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirementBase2)), Is.False);

            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirement3)), Is.True);
            Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirement3)].IsAggregatorInterface, Is.True);
            Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirementBase3)), Is.True);
            Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirementBase3)].IsAggregatorInterface, Is.False);
            Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirementBase3)].IsEmptyInterface, Is.False);

            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectBaseAggregator)), Is.True);
            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirement1)), Is.True);
            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirement2)), Is.False);
            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirement3)), Is.True);
            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirementBase1)), Is.True);
            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirementBase2)), Is.False);
            Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirementBase3)), Is.True);
        }
 public void CopyAttributes_Invalid()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(MixinWithInvalidSourceType)).EnterScope())
     {
         DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget));
     }
 }
Example #24
0
        public void Dependencies()
        {
            MixinDefinition bt3Mixin1 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).Mixins[typeof(BT3Mixin1)];

            Assert.That(bt3Mixin1.TargetCallDependencies.ContainsKey(typeof(IBaseType31)), Is.True);
            Assert.That(bt3Mixin1.TargetCallDependencies.Count, Is.EqualTo(1));

            Assert.That(bt3Mixin1.NextCallDependencies.ContainsKey(typeof(IBaseType31)), Is.True);
            Assert.That(bt3Mixin1.NextCallDependencies.Count, Is.EqualTo(1));

            MixinDefinition bt3Mixin2 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).Mixins[typeof(BT3Mixin2)];

            Assert.That(bt3Mixin2.TargetCallDependencies.ContainsKey(typeof(IBaseType32)), Is.True);
            Assert.That(bt3Mixin2.TargetCallDependencies.Count, Is.EqualTo(1));

            Assert.That(bt3Mixin2.NextCallDependencies.Count, Is.EqualTo(0));

            MixinDefinition bt3Mixin6 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).GetMixinByConfiguredType(typeof(BT3Mixin6 <,>));

            Assert.That(bt3Mixin6.TargetCallDependencies.ContainsKey(typeof(IBaseType31)), Is.True);
            Assert.That(bt3Mixin6.TargetCallDependencies.ContainsKey(typeof(IBaseType32)), Is.True);
            Assert.That(bt3Mixin6.TargetCallDependencies.ContainsKey(typeof(IBaseType33)), Is.True);
            Assert.That(bt3Mixin6.TargetCallDependencies.ContainsKey(typeof(IBT3Mixin4)), Is.True);
            Assert.That(bt3Mixin6.TargetCallDependencies.ContainsKey(typeof(IBaseType34)), Is.False);

            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBaseType31)].IsAggregate, Is.False);
            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBT3Mixin4)].IsAggregate, Is.False);

            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBaseType31)].AggregatedDependencies.Count, Is.EqualTo(0));

            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBT3Mixin4)].RequiredType.RequiringDependencies.ContainsKey(
                            bt3Mixin6.TargetCallDependencies[typeof(IBT3Mixin4)]), Is.True);
            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBT3Mixin4)].Aggregator, Is.Null);

            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBaseType31)].RequiredType, Is.SameAs(bt3Mixin6.TargetClass.RequiredTargetCallTypes[typeof(IBaseType31)]));

            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBaseType32)].GetImplementer(), Is.SameAs(bt3Mixin6.TargetClass));
            Assert.That(bt3Mixin6.TargetCallDependencies[typeof(IBT3Mixin4)].GetImplementer(), Is.SameAs(bt3Mixin6.TargetClass.Mixins[typeof(BT3Mixin4)]));

            Assert.That(bt3Mixin6.NextCallDependencies.ContainsKey(typeof(IBaseType34)), Is.True);
            Assert.That(bt3Mixin6.NextCallDependencies.ContainsKey(typeof(IBT3Mixin4)), Is.True);
            Assert.That(bt3Mixin6.NextCallDependencies.ContainsKey(typeof(IBaseType31)), Is.False);
            Assert.That(bt3Mixin6.NextCallDependencies.ContainsKey(typeof(IBaseType32)), Is.False);
            Assert.IsTrue(bt3Mixin6.NextCallDependencies.ContainsKey(typeof(IBaseType33)), "indirect dependency");

            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBaseType34)].RequiredType, Is.SameAs(bt3Mixin6.TargetClass.RequiredNextCallTypes[typeof(IBaseType34)]));

            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBaseType34)].GetImplementer(), Is.SameAs(bt3Mixin6.TargetClass));
            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)].GetImplementer(), Is.SameAs(bt3Mixin6.TargetClass.Mixins[typeof(BT3Mixin4)]));

            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)].IsAggregate, Is.False);
            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)].IsAggregate, Is.False);

            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)].AggregatedDependencies.Count, Is.EqualTo(0));

            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)].RequiredType.RequiringDependencies.ContainsKey(
                            bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)]), Is.True);
            Assert.That(bt3Mixin6.NextCallDependencies[typeof(IBT3Mixin4)].Aggregator, Is.Null);
        }
Example #25
0
 public void NeedsDerivedMixinType_True_ProtectedOverrider()
 {
     using (MixinConfiguration.BuildNew().ForClass <BaseType1>().AddMixin <MixinWithProtectedOverrider>().EnterScope())
     {
         var definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1)).Mixins[typeof(MixinWithProtectedOverrider)];
         Assert.That(definition.NeedsDerivedMixinType(), Is.True);
     }
 }
Example #26
0
 public void IntroducedAttribute_NotSuppressedDueToType()
 {
     using (MixinConfiguration.BuildNew().ForClass <TargetClassSuppressingBT1Attribute> ().AddMixin <MixinAddingSimpleAttribute> ().EnterScope())
     {
         TargetClassDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(TargetClassSuppressingBT1Attribute));
         Assert.That(definition.ReceivedAttributes.ContainsKey(typeof(SimpleAttribute)), Is.True);
     }
 }
Example #27
0
 public void IntroducedAttribute_NoSelfSuppress()
 {
     using (MixinConfiguration.BuildNew().ForClass <NullTarget> ().AddMixin <MixinSuppressingAndAddingBT1Attribute> ().EnterScope())
     {
         TargetClassDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget));
         Assert.That(definition.ReceivedAttributes.ContainsKey(typeof(BT1Attribute)), Is.True);
     }
 }
Example #28
0
 public void NeedsDerivedMixinType_True_AbstractClass()
 {
     using (MixinConfiguration.BuildNew().ForClass <NullTarget> ().AddMixin <AbstractMixinWithoutAbstractMembers> ().EnterScope())
     {
         var definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(AbstractMixinWithoutAbstractMembers)];
         Assert.That(definition.NeedsDerivedMixinType(), Is.True);
     }
 }
Example #29
0
        public void FaceInterfacesAddedViaContext()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType6));

            Assert.IsTrue(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(ICBT6Mixin1)), "This is added via a dependency of BT6Mixin3.");
            Assert.IsTrue(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(ICBT6Mixin2)), "This is added via a dependency of BT6Mixin3.");
            Assert.IsTrue(targetClass.RequiredTargetCallTypes.ContainsKey(typeof(ICBT6Mixin3)), "This is added because of the ComposedInterfaceAttribute.");
        }
Example #30
0
        public void FaceInterfacesWithOpenGenericTypes()
        {
            TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3));

            Assert.That(targetClass.GetMixinByConfiguredType(typeof(BT3Mixin3 <,>)).TargetCallDependencies.ContainsKey(typeof(IBaseType31)), Is.False);
            Assert.That(targetClass.GetMixinByConfiguredType(typeof(BT3Mixin3 <,>)).TargetCallDependencies.ContainsKey(typeof(IBaseType33)), Is.False);
            Assert.That(targetClass.GetMixinByConfiguredType(typeof(BT3Mixin3 <,>)).TargetCallDependencies.ContainsKey(typeof(BaseType3)), Is.True);
        }