Ejemplo n.º 1
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));
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        private void LoadAspects()
        {
            XmlNodeList aspects = _node.SelectNodes("aspect");

            foreach (XmlNode node in aspects)
            {
                String           name   = GetRequiredAttribute(node, "name");
                AspectDefinition aspect = new AspectDefinition(LexicalInfo.Empty, name);
                Configuration.Aspects.Add(aspect);

                XmlNode singleType = node.SelectSingleNode("for/singletype");
                aspect.TargetType            = new TargetTypeDefinition();
                aspect.TargetType.SingleType = CreateTypeReference(singleType);

                XmlNodeList mixins = node.SelectNodes("mixin");
                foreach (XmlNode inner in mixins)
                {
                    MixinDefinition def = new MixinDefinition(LexicalInfo.Empty);
                    def.TypeReference = CreateTypeReference(inner);
                    aspect.Mixins.Add(def);
                }

                XmlNodeList pointcuts = node.SelectNodes("pointcut");
                foreach (XmlNode inner in pointcuts)
                {
                    PointCutDefinition def = CreatePointCutDefinition(inner);
                    aspect.PointCuts.Add(def);
                }
            }
        }
        public void ParsingAspectWithAFewMixinDeclarations()
        {
            AspectParser parser = CreateParser(
                "aspect XPTO for MyNamespace.MyType \r\n" +
                "" +
                "  include MyNamespace.Type1 in MyAssembly1 " +
                "  include MyNamespace.Type2 in MyAssembly2 " +
                "  include MyNamespace.Type3 in MyAssembly3 " +
                "" +
                "" +
                "end");
            EngineConfiguration conf = parser.Parse();
            AspectDefinition    def  = conf.Aspects[0];

            Assert.AreEqual(3, def.Mixins.Count);

            MixinDefinition typeName = def.Mixins[0];

            Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType);
            Assert.AreEqual("MyNamespace.Type1", typeName.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly1", typeName.TypeReference.AssemblyReference.AssemblyName);

            typeName = def.Mixins[1];
            Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType);
            Assert.AreEqual("MyNamespace.Type2", typeName.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly2", typeName.TypeReference.AssemblyReference.AssemblyName);

            typeName = def.Mixins[2];
            Assert.AreEqual(TargetTypeEnum.Type, typeName.TypeReference.TargetType);
            Assert.AreEqual("MyNamespace.Type3", typeName.TypeReference.TypeName);
            Assert.AreEqual("MyAssembly3", typeName.TypeReference.AssemblyReference.AssemblyName);
        }
Ejemplo n.º 8
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));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
    protected void include(
        AspectDefinition aspect
        ) //throws RecognitionException, TokenStreamException
    {
        Token i = null;

        TypeReference   tr = null;
        MixinDefinition md;


        try {              // for error handling
            i = LT(1);
            match(INCLUDE);

            md = new MixinDefinition(ToLexicalInfo(i));

            tr = type_name_or_ref();

            md.TypeReference = tr;
            aspect.Mixins.Add(md);
        }
        catch (RecognitionException ex)
        {
            reportError(ex);
            consume();
            consumeUntil(tokenSet_10_);
        }
    }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
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")]));
            }
        }
        public void GenericMixinsAreClosed()
        {
            MixinDefinition def = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin3 <,>))
                                  .GetMixinByConfiguredType(typeof(BT3Mixin3 <,>));

            Assert.That(def.Type.IsGenericTypeDefinition, Is.False);
        }
        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));
            }
        }
Ejemplo n.º 15
0
        private static void AssertEngineConfiguration(AspectEngine engine)
        {
            Assert.IsNotNull(engine);
            Assert.IsNotNull(engine.Configuration);
            Assert.AreEqual(1, engine.Configuration.Imports.Count);
            Assert.AreEqual(1, engine.Configuration.Mixins.Count);
            Assert.AreEqual(1, engine.Configuration.Interceptors.Count);
            Assert.AreEqual(1, engine.Configuration.Aspects.Count);

            AspectDefinition aspect = engine.Configuration.Aspects[0];

            Assert.AreEqual("McBrother", aspect.Name);
            Assert.AreEqual(typeof(DummyCustomer), aspect.TargetType.SingleType.ResolvedType);

            Assert.AreEqual(1, aspect.Mixins.Count);
            MixinDefinition mixin = aspect.Mixins[0];

            Assert.AreEqual(typeof(DummyMixin), mixin.TypeReference.ResolvedType);

            Assert.AreEqual(1, aspect.PointCuts.Count);
            PointCutDefinition pointcut = aspect.PointCuts[0];

            Assert.AreEqual(AllMethodSignature.Instance, pointcut.Method);

            Assert.AreEqual(1, pointcut.Advices.Count);
            InterceptorDefinition advice = pointcut.Advices[0];

            Assert.AreEqual(typeof(DummyInterceptor), advice.TypeReference.ResolvedType);
        }
Ejemplo n.º 16
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] }));
        }
Ejemplo n.º 17
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);
        }
        public void GenericMixinsAreSetToConstraintOrBaseType()
        {
            MixinDefinition def = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin3 <,>))
                                  .GetMixinByConfiguredType(typeof(BT3Mixin3 <,>));

            Assert.That(def.Type.GetGenericArguments()[0], Is.EqualTo(typeof(BaseType3)));
            Assert.That(def.Type.GetGenericArguments()[1], Is.EqualTo(typeof(IBaseType33)));
        }
 public void AcceptsAlphabeticOrdering_False()
 {
     using (MixinConfiguration.BuildNew().ForClass <NullTarget> ().AddMixin <NullMixin> ().EnterScope())
     {
         MixinDefinition accepter = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(NullMixin)];
         Assert.That(accepter.AcceptsAlphabeticOrdering, Is.False);
     }
 }
 public void MixinKind_Used()
 {
     using (MixinConfiguration.BuildNew().ForClass <NullTarget> ().AddMixin <NullMixin> ().OfKind(MixinKind.Used).EnterScope())
     {
         MixinDefinition mixin = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(NullMixin)];
         Assert.That(mixin.MixinKind, Is.EqualTo(MixinKind.Used));
     }
 }
        public void NotOverriddenAbstractMixinMethodSucceeds()
        {
            TargetClassDefinition bt1    = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(MixinWithAbstractMembers));
            MixinDefinition       mixin  = bt1.Mixins[typeof(MixinWithAbstractMembers)];
            MethodDefinition      method = mixin.Methods[typeof(MixinWithAbstractMembers).GetMethod("AbstractMethod", BindingFlags.Instance | BindingFlags.NonPublic)];

            Assert.That(method.Overrides.Count, Is.EqualTo(0));
        }
Ejemplo n.º 22
0
        public static MixinDependencyDefinition CreateMixinDependencyDefinition(MixinDefinition definition)
        {
            ArgumentUtility.CheckNotNull("definition", definition);

            var mixinDependency = new MixinDependencyDefinition(new RequiredMixinTypeDefinition(definition.TargetClass, typeof(IBaseType2)), definition, null);

            PrivateInvoke.InvokeNonPublicMethod(definition.MixinDependencies, "Add", mixinDependency);
            return(mixinDependency);
        }
 public void CopyNonInheritedAttributesFromSelf_DosntIntroduceDuplicates()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(MixinIndirectlyAddingInheritedAttributeFromSelf)).EnterScope())
     {
         MixinDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(MixinIndirectlyAddingInheritedAttributeFromSelf)];
         Assert.That(definition.CustomAttributes.ContainsKey(typeof(AttributeWithParameters)), Is.True);
         Assert.That(new List <AttributeDefinition> (definition.CustomAttributes[typeof(AttributeWithParameters)]).Count, Is.EqualTo(1));
     }
 }
 public void CopyNonInheritedAttributesFromSelf()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(MixinIndirectlyAddingNonInheritedAttributeFromSelf)).EnterScope())
     {
         MixinDefinition definition = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)).Mixins[typeof(MixinIndirectlyAddingNonInheritedAttributeFromSelf)];
         Assert.That(definition.CustomAttributes.ContainsKey(typeof(CopyCustomAttributesAttribute)), Is.False);
         Assert.That(definition.CustomAttributes.ContainsKey(typeof(NonInheritableAttribute)), Is.True);
     }
 }
 public InterfaceIntroductionDefinitionBuilder(MixinDefinition mixin, MemberVisibility defaultVisibility)
 {
     _mixin                   = mixin;
     _defaultVisibility       = defaultVisibility;
     _nonIntroducedInterfaces = new HashSet <Type> {
         typeof(ISerializable), typeof(IDeserializationCallback), typeof(IInitializableMixin)
     };
     AnalyzeNonIntroducedInterfaces();
 }
Ejemplo n.º 26
0
        private MixinDefinition CreateMixinDefinition(MixinContext mixinContext)
        {
            Type mixinType = TargetClass.MixinTypeCloser.GetClosedMixinType(mixinContext.MixinType);
            bool acceptsAlphabeticOrdering = AcceptsAlphabeticOrdering(mixinType);
            var  mixin = new MixinDefinition(mixinContext.MixinKind, mixinType, TargetClass, acceptsAlphabeticOrdering);

            TargetClass.Mixins.Add(mixin);
            return(mixin);
        }
Ejemplo n.º 27
0
        private void CheckSomeRequiringMixin(RequirementDefinitionBase requirement, MixinDefinition expectedRequiringMixin)
        {
            ArgumentUtility.CheckNotNull("requirement", requirement);
            ArgumentUtility.CheckNotNull("expectedRequiringMixin", expectedRequiringMixin);

            var requirers = requirement.GetRequiringEntityDescription().Split(new[] { ", " }, StringSplitOptions.None);

            Assert.That(requirers, Has.Member("mixin '" + expectedRequiringMixin.FullName + "'"));
        }
        private Expression GetMixinReference(MixinDefinition mixin, Type concreteMixinType)
        {
            // (ConcreteMixinType) __this.__extensions[mixin.MixinIndex]

            return(Expression.Convert(
                       Expression.ArrayAccess(
                           Expression.Field(_thisField, _targetTypeForNextCall.ExtensionsField),
                           Expression.Constant(mixin.MixinIndex)),
                       concreteMixinType));
        }
Ejemplo n.º 29
0
        public static MixinDefinition CreateMixinDefinition(TargetClassDefinition targetClassDefinition, Type mixinType, bool acceptsAlphabeticOrdering = true)
        {
            ArgumentUtility.CheckNotNull("targetClassDefinition", targetClassDefinition);
            ArgumentUtility.CheckNotNull("mixinType", mixinType);

            var mixinDefinition = new MixinDefinition(MixinKind.Used, mixinType, targetClassDefinition, acceptsAlphabeticOrdering);

            PrivateInvoke.InvokeNonPublicMethod(targetClassDefinition.Mixins, "Add", mixinDefinition);
            return(mixinDefinition);
        }
Ejemplo n.º 30
0
        public static MixinDependencyDefinition CreateMixinDependencyDefinition(MixinDefinition from, MixinDefinition to)
        {
            ArgumentUtility.CheckNotNull("from", from);
            ArgumentUtility.CheckNotNull("to", to);

            var mixinDependency = new MixinDependencyDefinition(new RequiredMixinTypeDefinition(from.TargetClass, to.Type), from, null);

            PrivateInvoke.InvokeNonPublicMethod(from.MixinDependencies, "Add", mixinDependency);
            return(mixinDependency);
        }
        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.NewMixinDependenciesReflector ();

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

              _targetClassDefinition = TargetClassDefinitionFactory.CreateTargetClassDefinition (mixinConfiguration.ClassContexts.First ());
              _mixinDefinition = _targetClassDefinition.GetMixinByConfiguredType (typeof (Mixin1));
        }
Ejemplo n.º 33
0
		public override void OnMixinDefinition(MixinDefinition mixin)
		{
			Push( Document.CreateNode(XmlNodeType.Element, "mixin", null) );
			SerializeTypeReference(mixin.TypeReference);
			Pop();
		}
Ejemplo n.º 34
0
		public virtual void OnMixinDefinition(MixinDefinition mixin)
		{
			OnTypeReferenceDefinition(mixin.TypeReference);
		}
        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));
        }