Example #1
0
        public void SucceedsIfAbstractTargetClass()
        {
            TargetClassDefinition bc = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(MixinWithAbstractMembers));
            var log = Validator.Validate(bc);

            AssertSuccess(log);
        }
Example #2
0
        public void MixinsIntroduceAttributes_InheritedFromBase()
        {
            TargetClassDefinition target = DefinitionObjectMother.GetTargetClassDefinition(typeof(NullTarget), typeof(MixinInheritingAttributes));

            var mixin = target.Mixins[typeof(MixinInheritingAttributes)];

            Assert.That(mixin.CustomAttributes.Keys, Has.Member(typeof(InheritableAttribute)));
            Assert.That(mixin.CustomAttributes.Keys, Has.No.Member(typeof(NonInheritableAttribute)));

            var attribute = mixin.CustomAttributes[typeof(InheritableAttribute)].Single();

            Assert.That(mixin.AttributeIntroductions.Select(i => i.Attribute), Has.Member(attribute));
            var attributeIntroduction = mixin.AttributeIntroductions[typeof(InheritableAttribute)].Single();

            Assert.That(target.ReceivedAttributes, Has.Member(attributeIntroduction));

            var member = mixin.Methods[typeof(MixinInheritingAttributes).GetMethod("ToString")];

            Assert.That(member.CustomAttributes.Keys, Has.Member(typeof(InheritableAttribute)));
            Assert.That(member.CustomAttributes.Keys, Has.No.Member(typeof(NonInheritableAttribute)));

            var memberAttribute = member.CustomAttributes[typeof(InheritableAttribute)].Single();

            Assert.That(member.AttributeIntroductions.Select(i => i.Attribute), Has.Member(memberAttribute));
            var memberAttributeIntroduction = member.AttributeIntroductions[typeof(InheritableAttribute)].Single();

            Assert.That(member.Base.ReceivedAttributes, Has.Member(memberAttributeIntroduction));
        }
Example #3
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 #4
0
        public void NonInheritedAttributesAreNotIntroduced()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(
                typeof(BaseType1), typeof(MixinAddingNonInheritedAttribute));

            Assert.That(definition.ReceivedAttributes.GetItemCount(typeof(NonInheritableAttribute)), Is.EqualTo(0));
        }
Example #5
0
        public void FailsIfTargetClassDefinitionIsInterface()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(IBaseType2));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultTargetClassRules.TargetClassMustNotBeAnInterface", log), Is.True);
        }
        public void FailsIfNestedPrivateMixinInNonPublic()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(InternalNester.InternalNested));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMixinRules.MixinMustBePublic", log), Is.True);
        }
        public void ModifyTargetType(
            MutableType concreteTarget,
            TargetClassDefinition targetClassDefinition,
            IEnumerable <Type> interfacesToImplement,
            IList <IMixinInfo> mixinInfos)
        {
            ArgumentUtility.CheckNotNull("concreteTarget", concreteTarget);
            ArgumentUtility.CheckNotNull("targetClassDefinition", targetClassDefinition);
            ArgumentUtility.CheckNotNull("interfacesToImplement", interfacesToImplement);
            ArgumentUtility.CheckNotNull("mixinInfos", mixinInfos);

            var targetTypeGenerator = new TargetTypeGenerator(concreteTarget, new ExpressionBuilder(), new AttributeGenerator(), _nextCallProxyGenerator);
            var mixinTypes          = mixinInfos.Select(t => t.MixinType).ToList();

            targetTypeGenerator.AddInterfaces(interfacesToImplement);
            targetTypeGenerator.AddExtensionsField();
            targetTypeGenerator.AddNextCallProxy(targetClassDefinition, mixinInfos);
            targetTypeGenerator.AddFields();
            targetTypeGenerator.AddTypeInitializations(targetClassDefinition.ConfigurationContext, mixinTypes);
            targetTypeGenerator.AddInitializations(mixinTypes);

            targetTypeGenerator.ImplementIMixinTarget(targetClassDefinition.Name);
            targetTypeGenerator.ImplementIntroducedInterfaces(targetClassDefinition.ReceivedInterfaces);
            targetTypeGenerator.ImplementRequiredDuckMethods(targetClassDefinition);
            targetTypeGenerator.ImplementAttributes(targetClassDefinition);

            targetTypeGenerator.AddMixedTypeAttribute(targetClassDefinition);
            targetTypeGenerator.AddDebuggerDisplayAttribute(targetClassDefinition);

            targetTypeGenerator.ImplementOverrides(targetClassDefinition);
            targetTypeGenerator.ImplementOverridingMethods(targetClassDefinition, mixinInfos);
        }
Example #8
0
        public void ComposedInterfaces()
        {
            TargetClassDefinition bt3 = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), Type.EmptyTypes, new[] { typeof(ICBaseType3) });

            var dependency = bt3.ComposedInterfaceDependencies[typeof(ICBaseType3)];

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

            var requirement = dependency.RequiredType;

            Assert.That(requirement, Is.Not.Null);
            Assert.That(requirement, Is.SameAs(bt3.RequiredTargetCallTypes[typeof(ICBaseType3)]));
            Assert.That(requirement.RequiringDependencies, Is.EqualTo(new[] { dependency }));

            Assert.That(dependency, Is.TypeOf <ComposedInterfaceDependencyDefinition> ());
            Assert.That(dependency.RequiredType, Is.SameAs(requirement));
            Assert.That(dependency.TargetClass, Is.SameAs(bt3));
            Assert.That(dependency.Depender, Is.SameAs(bt3));
            Assert.That(dependency.FullName, Is.EqualTo(typeof(ICBaseType3).FullName));
            Assert.That(dependency.Parent, Is.SameAs(dependency.Depender));
            Assert.That(dependency.ComposedInterface, Is.SameAs(typeof(ICBaseType3)));

            CheckSomeRequiringComposedInterface(requirement, typeof(ICBaseType3));

            Assert.That(dependency.IsAggregate, Is.True);
            Assert.That(dependency.AggregatedDependencies[typeof(IBaseType31)], Is.Not.Null);
            Assert.That(dependency.AggregatedDependencies[typeof(IBaseType31)], Is.TypeOf <ComposedInterfaceDependencyDefinition> ());
            Assert.That(
                ((ComposedInterfaceDependencyDefinition)dependency.AggregatedDependencies[typeof(IBaseType31)]).ComposedInterface,
                Is.SameAs(typeof(ICBaseType3)));
            Assert.That(bt3.RequiredTargetCallTypes[typeof(IBaseType31)], Is.Not.Null);
            Assert.That(bt3.RequiredTargetCallTypes[typeof(IBaseType31)], Is.SameAs(dependency.AggregatedDependencies[typeof(IBaseType31)].RequiredType));
        }
Example #9
0
        public void WarnsIfPropertyOverrideAddsMethods()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseWithGetterOnly), typeof(MixinOverridingSetterOnly));
            var log = Validator.Validate(definition.Properties[typeof(BaseWithGetterOnly).GetProperty("Property")].Overrides[0]);

            Assert.That(HasWarning("Remotion.Mixins.Validation.Rules.DefaultPropertyRules.NewMemberAddedByOverride", log), Is.True);
        }
Example #10
0
        public void ComposedInterfacesAndDependenciesForBase()
        {
            TargetClassDefinition bt3 =
                DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin4), typeof(BT3Mixin7Base));

            MixinDefinition m4 = bt3.Mixins[typeof(BT3Mixin4)];
            MixinDefinition m7 = bt3.Mixins[typeof(BT3Mixin7Base)];

            NextCallDependencyDefinition d2 = m7.NextCallDependencies[typeof(ICBaseType3BT3Mixin4)];

            Assert.That(d2.GetImplementer(), Is.Null);

            Assert.That(d2.IsAggregate, Is.True);

            Assert.That(d2.AggregatedDependencies[typeof(ICBaseType3)].IsAggregate, Is.True);
            Assert.That(d2.AggregatedDependencies[typeof(ICBaseType3)].Parent, Is.SameAs(d2));

            Assert.That(d2.AggregatedDependencies[typeof(ICBaseType3)]
                        .AggregatedDependencies[typeof(IBaseType31)].IsAggregate, Is.False);
            Assert.That(d2.AggregatedDependencies[typeof(ICBaseType3)]
                        .AggregatedDependencies[typeof(IBaseType31)].GetImplementer(), Is.SameAs(bt3));

            Assert.That(d2.AggregatedDependencies[typeof(IBT3Mixin4)].IsAggregate, Is.False);
            Assert.That(d2.AggregatedDependencies[typeof(IBT3Mixin4)].GetImplementer(), Is.SameAs(m4));

            Assert.That(d2.AggregatedDependencies[typeof(IBT3Mixin4)].Aggregator, Is.SameAs(d2));

            Assert.That(bt3.RequiredNextCallTypes[typeof(ICBaseType3)].IsEmptyInterface, Is.True);
            Assert.That(bt3.RequiredNextCallTypes[typeof(ICBaseType3)].IsAggregatorInterface, Is.True);

            Assert.That(bt3.RequiredNextCallTypes.ContainsKey(typeof(ICBaseType3BT3Mixin4)), Is.True);
            Assert.That(bt3.RequiredNextCallTypes.ContainsKey(typeof(ICBaseType3)), Is.True);
            Assert.That(bt3.RequiredNextCallTypes.ContainsKey(typeof(IBaseType31)), Is.True);
            Assert.That(bt3.RequiredNextCallTypes.ContainsKey(typeof(IBT3Mixin4)), Is.True);
        }
Example #11
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 #12
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 #13
0
        public TargetClassDefinition Build(ClassContext classContext)
        {
            ArgumentUtility.CheckNotNull("classContext", classContext);

            if (classContext.Type.ContainsGenericParameters)
            {
                string message = string.Format("The base class {0} contains generic parameters. This is not supported.", classContext.Type.FullName);
                throw new ConfigurationException(message);
            }

            var classDefinition = new TargetClassDefinition(classContext);

            var membersBuilder = new MemberDefinitionBuilder(classDefinition, ReflectionUtility.IsPublicOrProtectedOrExplicit);

            membersBuilder.Apply(classDefinition.Type);

            var attributesBuilder = new AttributeDefinitionBuilder(classDefinition);

            attributesBuilder.Apply(classDefinition.Type);

            ApplyComposedInterfaces(classDefinition, classContext);
            ApplyMixins(classDefinition, classContext);
            ApplyMethodRequirements(classDefinition);

            AnalyzeOverrides(classDefinition);
            AnalyzeAttributeIntroductions(classDefinition);
            AnalyzeMemberAttributeIntroductions(classDefinition);
            return(classDefinition);
        }
Example #14
0
        public void FailsIfEmptyAggregateNextCallDependencyIsNotAvailable()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(NullTarget), typeof(MixinWithUnsatisfiedEmptyAggregateNextCallDependency));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultNextCallDependencyRules.DependencyMustBeSatisfied", log), Is.True);
        }
        public void FailsIfMixinNonPublic()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType5), typeof(BT5Mixin2));
            var log = Validator.Validate(definition.Mixins[typeof(BT5Mixin2)]);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMixinRules.MixinMustBePublic", log), Is.True);
        }
        public void SucceedsIfNestedPublicMixin()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(PublicNester.PublicNested));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
        public void FailsIfMixinAppliedToItsBase()
        {
            TargetClassDefinition bc = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(object), typeof(NullMixin));
            var log = Validator.Validate(bc);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMixinRules.MixinCannotMixItsBase", log), Is.True);
        }
        public void FailsIfMixinIsInterface()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(IBT1Mixin1));
            var log = Validator.Validate(definition.Mixins[typeof(IBT1Mixin1)]);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMixinRules.MixinCannotBeInterface", log), Is.True);
        }
        public void SucceedsIfEmptyAggregateTargetCallDependencyIsNotAvailable()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(NullTarget), typeof(MixinWithUnsatisfiedEmptyAggregateTargetCallDependency));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
        public void FailsIfIntroducedInterfaceNotVisible()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType2), typeof(MixinIntroducingInternalInterface));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultInterfaceIntroductionRules.IntroducedInterfaceMustBePublic", log), Is.True);
        }
        public void FailsIfImplementingIMixinTarget()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(MixinImplementingIMixinTarget));
            var log = Validator.Validate(definition);

            Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultInterfaceIntroductionRules.IMixinTargetCannotBeIntroduced", log), Is.True);
        }
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);
        }
Example #23
0
        public void MultipleAttributesOnMembers()
        {
            TargetClassDefinition bt1 =
                DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseTypeWithAllowMultiple),
                                                                  typeof(MixinAddingAllowMultipleToClassAndMember), typeof(MixinAddingAllowMultipleToClassAndMember2));
            MethodDefinition member = bt1.Methods[typeof(BaseTypeWithAllowMultiple).GetMethod("Foo")];

            Assert.That(member.CustomAttributes.Count, Is.EqualTo(1));
            Assert.That(member.Overrides.Count, Is.EqualTo(2));
            Assert.That(member.ReceivedAttributes.Count, Is.EqualTo(2));

            MixinDefinition  mixin1       = bt1.Mixins[typeof(MixinAddingAllowMultipleToClassAndMember)];
            MethodDefinition mixinMember1 = mixin1.Methods[typeof(MixinAddingAllowMultipleToClassAndMember).GetMethod("Foo")];

            Assert.That(mixinMember1.CustomAttributes.Count, Is.EqualTo(1));

            MixinDefinition  mixin2       = bt1.Mixins[typeof(MixinAddingAllowMultipleToClassAndMember2)];
            MethodDefinition mixinMember2 = mixin2.Methods[typeof(MixinAddingAllowMultipleToClassAndMember).GetMethod("Foo")];

            Assert.That(mixinMember2.CustomAttributes.Count, Is.EqualTo(1));

            Assert.That(member.ReceivedAttributes.ContainsKey(typeof(MultiAttribute)), Is.True);
            Assert.That(member.ReceivedAttributes.GetItemCount(typeof(MultiAttribute)), Is.EqualTo(2));

            List <AttributeDefinition> attributes =
                new List <AttributeIntroductionDefinition> (member.ReceivedAttributes[typeof(MultiAttribute)])
                .ConvertAll <AttributeDefinition> (delegate(AttributeIntroductionDefinition intro) { return(intro.Attribute); });

            Assert.That(attributes, Is.EquivalentTo(new AttributeDefinition[] { mixinMember1.CustomAttributes[0], mixinMember2.CustomAttributes[0] }));
        }
Example #24
0
        private void AnalyzeOverrides(TargetClassDefinition definition)
        {
            var mixinMethods   = definition.Mixins.SelectMany(m => m.Methods);
            var methodAnalyzer = new OverridesAnalyzer <MethodDefinition> (typeof(OverrideMixinAttribute), mixinMethods);

            foreach (var methodOverride in methodAnalyzer.Analyze(definition.Methods))
            {
                InitializeOverride(methodOverride.Overrider, methodOverride.BaseMember);
            }

            var mixinProperties  = definition.Mixins.SelectMany(m => m.Properties);
            var propertyAnalyzer = new OverridesAnalyzer <PropertyDefinition> (typeof(OverrideMixinAttribute), mixinProperties);

            foreach (var propertyOverride in propertyAnalyzer.Analyze(definition.Properties))
            {
                InitializeOverride(propertyOverride.Overrider, propertyOverride.BaseMember);
            }

            var mixinEvents   = definition.Mixins.SelectMany(m => m.Events);
            var eventAnalyzer = new OverridesAnalyzer <EventDefinition> (typeof(OverrideMixinAttribute), mixinEvents);

            foreach (var eventOverride in eventAnalyzer.Analyze(definition.Events))
            {
                InitializeOverride(eventOverride.Overrider, eventOverride.BaseMember);
            }
        }
        public INextCallProxy Create(
            MutableType concreteTarget,
            FieldInfo extensionsField,
            TargetClassDefinition targetClassDefinition,
            IList <IMixinInfo> mixinInfos)
        {
            ArgumentUtility.CheckNotNull("concreteTarget", concreteTarget);
            ArgumentUtility.CheckNotNull("targetClassDefinition", targetClassDefinition);
            ArgumentUtility.CheckNotNull("mixinInfos", mixinInfos);

            var nextCallProxyType = CreateNextCallProxyType(concreteTarget, targetClassDefinition);

            var thisField  = AddPublicField(nextCallProxyType, "__this", concreteTarget);
            var depthField = AddPublicField(nextCallProxyType, "__depth", typeof(int));

            var constructor = AddConstructor(nextCallProxyType, concreteTarget, thisField, depthField);

            var targetTypeForNextCall   = GetTargetTypeWrapper(concreteTarget, extensionsField);
            var nextCallMethodGenerator = new NextCallMethodGenerator(
                targetClassDefinition, targetTypeForNextCall, thisField, depthField, mixinInfos);
            var nextCallProxy = new NextCallProxy(nextCallProxyType, constructor, targetClassDefinition, nextCallMethodGenerator);

            nextCallProxy.ImplementBaseCallsForOverriddenMethodsOnTarget();
            nextCallProxy.ImplementBaseCallsForRequirements();

            return(nextCallProxy);
        }
Example #26
0
        public void SucceedsIfAggregateNextCallDependencyIsFullyImplemented()
        {
            TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin4), typeof(BT3Mixin7Base));
            var log = Validator.Validate(definition);

            AssertSuccess(log);
        }
Example #27
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 #28
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));
        }
Example #29
0
 public MixinDefinitionBuilder(TargetClassDefinition targetClass)
 {
     ArgumentUtility.CheckNotNull("targetClass", targetClass);
     _targetClass = targetClass;
     _targetRequirementsAnalyzer = new RequirementsAnalyzer(MixinGenericArgumentFinder.TargetArgumentFinder);
     _nextRequirementsAnalyzer   = new RequirementsAnalyzer(MixinGenericArgumentFinder.NextArgumentFinder);
 }
Example #30
0
        public void ComposedInterfacesAndDependenciesForFace()
        {
            TargetClassDefinition bt3 = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin4), typeof(Bt3Mixin7TargetCall));

            MixinDefinition m4 = bt3.Mixins[typeof(BT3Mixin4)];
            MixinDefinition m7 = bt3.Mixins[typeof(Bt3Mixin7TargetCall)];

            TargetCallDependencyDefinition d1 = m7.TargetCallDependencies[typeof(ICBaseType3BT3Mixin4)];

            Assert.That(d1.GetImplementer(), Is.Null);
            Assert.That(d1.FullName, Is.EqualTo("Remotion.Mixins.UnitTests.Core.TestDomain.ICBaseType3BT3Mixin4"));
            Assert.That(d1.Parent, Is.SameAs(m7));

            Assert.That(d1.IsAggregate, Is.True);
            Assert.That(d1.AggregatedDependencies[typeof(ICBaseType3)].IsAggregate, Is.True);
            Assert.That(d1.AggregatedDependencies[typeof(ICBaseType3)]
                        .AggregatedDependencies[typeof(IBaseType31)].IsAggregate, Is.False);
            Assert.That(d1.AggregatedDependencies[typeof(ICBaseType3)]
                        .AggregatedDependencies[typeof(IBaseType31)].GetImplementer(), Is.SameAs(bt3));

            Assert.That(d1.AggregatedDependencies[typeof(IBT3Mixin4)].IsAggregate, Is.False);
            Assert.That(d1.AggregatedDependencies[typeof(IBT3Mixin4)].GetImplementer(), Is.SameAs(m4));

            Assert.That(d1.AggregatedDependencies[typeof(IBT3Mixin4)].Aggregator, Is.SameAs(d1));

            Assert.That(bt3.RequiredTargetCallTypes[typeof(ICBaseType3)].IsEmptyInterface, Is.True);
            Assert.That(bt3.RequiredTargetCallTypes[typeof(ICBaseType3)].IsAggregatorInterface, Is.True);

            Assert.That(bt3.RequiredTargetCallTypes.ContainsKey(typeof(ICBaseType3BT3Mixin4)), Is.True);
            Assert.That(bt3.RequiredTargetCallTypes.ContainsKey(typeof(ICBaseType3)), Is.True);
            Assert.That(bt3.RequiredTargetCallTypes.ContainsKey(typeof(IBaseType31)), Is.True);
            Assert.That(bt3.RequiredTargetCallTypes.ContainsKey(typeof(IBT3Mixin4)), Is.True);
        }
        public void SetUp()
        {
            _remotionReflector = new Reflectors.NewMixinDependenciesReflector ();

              var mixinConfiguration = MixinConfiguration.BuildNew ()
              .ForClass<TargetClass1> ()
              .AddMixin<Mixin1> ()
              .BuildConfiguration ();

              _targetClassDefinition = TargetClassDefinitionFactory.CreateTargetClassDefinition (mixinConfiguration.ClassContexts.First ());
              _mixinDefinition = _targetClassDefinition.GetMixinByConfiguredType (typeof (Mixin1));
        }
        public void SetUp()
        {
            _remotionReflector = new Reflectors.OldMixinDependenciesReflector ();

              var mixinConfiguration = MixinConfiguration.BuildNew ()
              .ForClass<TargetClass1> ()
              .AddMixin<Mixin1> ()
              .BuildConfiguration ();

              _targetClassDefinition = TargetClassDefinitionUtility.GetConfiguration (typeof (TargetClass1), mixinConfiguration);
              _mixinDefinition = _targetClassDefinition.GetMixinByConfiguredType (typeof (Mixin1));
        }
        public void SetUp()
        {
            _remotionReflector = new Reflectors.Net4_5SupportReflector ().Initialize(".");

              var mixinConfiguration = MixinConfiguration.BuildNew ()
              .ForClass<TargetClass1> ()
              .AddMixin<Mixin1> ()
              .BuildConfiguration ();

              _targetClassDefinition = TargetClassDefinitionFactory.CreateAndValidate (mixinConfiguration.ClassContexts.First ());
              _mixinDefinition = _targetClassDefinition.GetMixinByConfiguredType (typeof (Mixin1));
        }