Esempio n. 1
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);
        }
Esempio n. 2
0
        public static NextCallDependencyDefinition CreateNextCallDependencyDefinition(MixinDefinition definition)
        {
            ArgumentUtility.CheckNotNull("definition", definition);

            var nextCallDependency = new NextCallDependencyDefinition(new RequiredNextCallTypeDefinition(definition.TargetClass, typeof(IBaseType2)), definition, null);

            PrivateInvoke.InvokeNonPublicMethod(definition.NextCallDependencies, "Add", nextCallDependency);
            return(nextCallDependency);
        }
Esempio n. 3
0
 public void EmptyInterface()
 {
     using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(MixinWithEmptyInterface), typeof(MixinRequiringEmptyInterface)).EnterScope())
     {
         TargetClassDefinition          bt1         = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));
         MixinDefinition                m1          = bt1.Mixins[typeof(MixinWithEmptyInterface)];
         MixinDefinition                m2          = bt1.Mixins[typeof(MixinRequiringEmptyInterface)];
         NextCallDependencyDefinition   dependency  = m2.NextCallDependencies[0];
         RequiredNextCallTypeDefinition requirement = dependency.RequiredType;
         Assert.That(requirement.IsEmptyInterface, Is.True);
         Assert.That(requirement.IsAggregatorInterface, Is.False);
         Assert.That(dependency.GetImplementer(), Is.SameAs(m1));
     }
 }
 public void Visit(NextCallDependencyDefinition dependency)
 {
     ArgumentUtility.CheckNotNull("dependency", dependency);
     CheckRules(_nextCallDependencyRules, dependency);
 }
        public void DefaultConfiguration_EverythingIsVisitedOnce()
        {
            var activeConfiguration = MixinConfiguration.ActiveConfiguration;

            ValidationLogData log;

            using (MixinConfiguration.BuildNew().EnterScope())
            {
                log = activeConfiguration.Validate();
            }

            var validationResults  = log.GetResults();
            var visitedDefinitions = new HashSet <IVisitableDefinition>();

            foreach (ValidationResult result in validationResults)
            {
                var definition = result.ValidatedDefinition;
                Assert.That(visitedDefinitions.Contains(definition), Is.False, definition.ToString());
                visitedDefinitions.Add(definition);
            }

            TargetClassDefinition bt1 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1));

            AssertVisitedEquivalent(validationResults, bt1);
            TargetClassDefinition bt3 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3));

            AssertVisitedEquivalent(validationResults, bt3);
            TargetClassDefinition bt6 = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType6));

            AssertVisitedEquivalent(validationResults, bt6);
            TargetClassDefinition btWithAdditionalDependencies =
                DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(TargetClassWithAdditionalDependencies));

            AssertVisitedEquivalent(validationResults, btWithAdditionalDependencies);
            TargetClassDefinition targetWithSuppressAttribute =
                DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(TargetClassSuppressingBT1Attribute));

            AssertVisitedEquivalent(validationResults, targetWithSuppressAttribute);
            TargetClassDefinition targetWithNonIntroducedAttribute =
                DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(TargetClassWithMixinNonIntroducingSimpleAttribute));

            AssertVisitedEquivalent(validationResults, targetWithSuppressAttribute);
            TargetClassDefinition targetClassWinningOverMixinAddingBT1AttributeToMember =
                DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(TargetClassWinningOverMixinAddingBT1AttributeToMember));

            AssertVisitedEquivalent(validationResults, targetClassWinningOverMixinAddingBT1AttributeToMember);

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

            AssertVisitedEquivalent(validationResults, bt1m1);
            MixinDefinition bt1m2 = bt1.Mixins[typeof(BT1Mixin2)];

            AssertVisitedEquivalent(validationResults, bt1m2);
            MixinDefinition bt3m1 = bt3.Mixins[typeof(BT3Mixin1)];

            AssertVisitedEquivalent(validationResults, bt3m1);
            MixinDefinition bt3m2 = bt3.Mixins[typeof(BT3Mixin2)];

            AssertVisitedEquivalent(validationResults, bt3m2);
            MixinDefinition bt3m3 = bt3.GetMixinByConfiguredType(typeof(BT3Mixin3 <,>));

            AssertVisitedEquivalent(validationResults, bt3m3);
            MixinDefinition bt3m4 = bt3.Mixins[typeof(BT3Mixin4)];

            AssertVisitedEquivalent(validationResults, bt3m4);
            MixinDefinition bt3m5 = bt3.Mixins[typeof(BT3Mixin5)];

            AssertVisitedEquivalent(validationResults, bt3m5);
            MixinDefinition mixinWithSuppressedAttribute = targetWithSuppressAttribute.Mixins[typeof(MixinAddingBT1Attribute)];

            AssertVisitedEquivalent(validationResults, mixinWithSuppressedAttribute);
            MixinDefinition mixinWithNonIntroducedAttribute = targetWithNonIntroducedAttribute.Mixins[typeof(MixinNonIntroducingSimpleAttribute)];

            AssertVisitedEquivalent(validationResults, mixinWithNonIntroducedAttribute);

            MethodDefinition m1 = bt1.Methods[typeof(BaseType1).GetMethod("VirtualMethod", Type.EmptyTypes)];

            AssertVisitedEquivalent(validationResults, m1);
            MethodDefinition m2 = bt1.Methods[typeof(BaseType1).GetMethod("VirtualMethod", new[] { typeof(string) })];

            AssertVisitedEquivalent(validationResults, m2);
            MethodDefinition m3 = bt1m1.Methods[typeof(BT1Mixin1).GetMethod("VirtualMethod")];

            AssertVisitedEquivalent(validationResults, m3);
            MethodDefinition m4 = bt1m1.Methods[typeof(BT1Mixin1).GetMethod("IntroducedMethod")];

            AssertVisitedEquivalent(validationResults, m4);
            MethodDefinition memberWinningOverMixinAddingAttribute =
                targetClassWinningOverMixinAddingBT1AttributeToMember.Methods[
                    typeof(TargetClassWinningOverMixinAddingBT1AttributeToMember).GetMethod("VirtualMethod")];

            AssertVisitedEquivalent(validationResults, memberWinningOverMixinAddingAttribute);

            PropertyDefinition p1 = bt1.Properties[typeof(BaseType1).GetProperty("VirtualProperty")];

            AssertVisitedEquivalent(validationResults, p1);
            MethodDefinition m5 = p1.GetMethod;

            AssertVisitedEquivalent(validationResults, m5);
            MethodDefinition m6 = p1.SetMethod;

            AssertVisitedEquivalent(validationResults, m6);
            PropertyDefinition p2 = bt1m1.Properties[typeof(BT1Mixin1).GetProperty("VirtualProperty")];

            AssertVisitedEquivalent(validationResults, p2);

            EventDefinition e1 = bt1.Events[typeof(BaseType1).GetEvent("VirtualEvent")];

            AssertVisitedEquivalent(validationResults, e1);
            MethodDefinition m7 = e1.AddMethod;

            AssertVisitedEquivalent(validationResults, m7);
            MethodDefinition m8 = e1.RemoveMethod;

            AssertVisitedEquivalent(validationResults, m8);
            EventDefinition e2 = bt1m1.Events[typeof(BT1Mixin1).GetEvent("VirtualEvent")];

            AssertVisitedEquivalent(validationResults, e2);

            InterfaceIntroductionDefinition i1 = bt1m1.InterfaceIntroductions[typeof(IBT1Mixin1)];

            AssertVisitedEquivalent(validationResults, i1);
            MethodIntroductionDefinition im1 = i1.IntroducedMethods[typeof(IBT1Mixin1).GetMethod("IntroducedMethod")];

            AssertVisitedEquivalent(validationResults, im1);
            PropertyIntroductionDefinition im2 = i1.IntroducedProperties[typeof(IBT1Mixin1).GetProperty("IntroducedProperty")];

            AssertVisitedEquivalent(validationResults, im2);
            EventIntroductionDefinition im3 = i1.IntroducedEvents[typeof(IBT1Mixin1).GetEvent("IntroducedEvent")];

            AssertVisitedEquivalent(validationResults, im3);

            AttributeDefinition a1 = bt1.CustomAttributes.GetFirstItem(typeof(BT1Attribute));

            AssertVisitedEquivalent(validationResults, a1);
            AttributeDefinition a2 = bt1m1.CustomAttributes.GetFirstItem(typeof(BT1M1Attribute));

            AssertVisitedEquivalent(validationResults, a2);
            AttributeDefinition a3 = m1.CustomAttributes.GetFirstItem(typeof(BT1Attribute));

            AssertVisitedEquivalent(validationResults, a3);
            AttributeDefinition a4 = p1.CustomAttributes.GetFirstItem(typeof(BT1Attribute));

            AssertVisitedEquivalent(validationResults, a4);
            AttributeDefinition a5 = e1.CustomAttributes.GetFirstItem(typeof(BT1Attribute));

            AssertVisitedEquivalent(validationResults, a5);
            AttributeDefinition a6 = im1.ImplementingMember.CustomAttributes.GetFirstItem(typeof(BT1M1Attribute));

            AssertVisitedEquivalent(validationResults, a6);
            AttributeDefinition a7 = im2.ImplementingMember.CustomAttributes.GetFirstItem(typeof(BT1M1Attribute));

            AssertVisitedEquivalent(validationResults, a7);
            AttributeDefinition a8 = im3.ImplementingMember.CustomAttributes.GetFirstItem(typeof(BT1M1Attribute));

            AssertVisitedEquivalent(validationResults, a8);

            AttributeIntroductionDefinition ai1 = bt1.ReceivedAttributes.GetFirstItem(typeof(BT1M1Attribute));

            AssertVisitedEquivalent(validationResults, ai1);
            AttributeIntroductionDefinition ai2 = m1.ReceivedAttributes.GetFirstItem(typeof(BT1M1Attribute));

            AssertVisitedEquivalent(validationResults, ai2);

            RequiredNextCallTypeDefinition bc1 = bt3.RequiredNextCallTypes[typeof(IBaseType34)];

            AssertVisitedEquivalent(validationResults, bc1);
            RequiredMethodDefinition bcm1 = bc1.Methods[typeof(IBaseType34).GetMethod("IfcMethod")];

            AssertVisitedEquivalent(validationResults, bcm1);

            RequiredTargetCallTypeDefinition ft1 = bt3.RequiredTargetCallTypes[typeof(IBaseType32)];

            AssertVisitedEquivalent(validationResults, ft1);
            RequiredMethodDefinition fm1 = ft1.Methods[typeof(IBaseType32).GetMethod("IfcMethod")];

            AssertVisitedEquivalent(validationResults, fm1);

            RequiredMixinTypeDefinition rmt1 = btWithAdditionalDependencies.RequiredMixinTypes[typeof(IMixinWithAdditionalClassDependency)];

            AssertVisitedEquivalent(validationResults, rmt1);
            RequiredMixinTypeDefinition rmt2 = btWithAdditionalDependencies.RequiredMixinTypes[typeof(MixinWithNoAdditionalDependency)];

            AssertVisitedEquivalent(validationResults, rmt2);

            ComposedInterfaceDependencyDefinition cid1 = bt6.ComposedInterfaceDependencies[typeof(ICBT6Mixin1)];

            AssertVisitedEquivalent(validationResults, cid1);

            TargetCallDependencyDefinition td1 = bt3m1.TargetCallDependencies[typeof(IBaseType31)];

            AssertVisitedEquivalent(validationResults, td1);

            NextCallDependencyDefinition bd1 = bt3m1.NextCallDependencies[typeof(IBaseType31)];

            AssertVisitedEquivalent(validationResults, bd1);

            MixinDependencyDefinition md1 =
                btWithAdditionalDependencies.Mixins[typeof(MixinWithAdditionalClassDependency)].MixinDependencies[typeof(MixinWithNoAdditionalDependency)];

            AssertVisitedEquivalent(validationResults, md1);

            SuppressedAttributeIntroductionDefinition suppressedAttribute1 =
                mixinWithSuppressedAttribute.SuppressedAttributeIntroductions.GetFirstItem(typeof(BT1Attribute));

            AssertVisitedEquivalent(validationResults, suppressedAttribute1);

            NonAttributeIntroductionDefinition nonIntroducedAttribute1 =
                mixinWithNonIntroducedAttribute.NonAttributeIntroductions.GetFirstItem(typeof(SimpleAttribute));

            AssertVisitedEquivalent(validationResults, nonIntroducedAttribute1);
            NonAttributeIntroductionDefinition nonIntroducedAttribute2 = memberWinningOverMixinAddingAttribute.Overrides[0].NonAttributeIntroductions[0];

            AssertVisitedEquivalent(validationResults, nonIntroducedAttribute2);
        }