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 SucceedsIfPublicIntroducedMethod_DoesNotHaveSameNameAsOther() { TargetClassDefinition classDefinition = DefinitionObjectMother.BuildUnvalidatedDefinition( typeof(NullTarget), typeof(MixinIntroducingMembersWithDifferentVisibilities)); MethodIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedMethods[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetMethod("MethodWithPublicVisibility")]; var log = Validator.Validate(definition); AssertSuccess(log); }
public void FailsIfPublicIntroducedMethod_HasSameNameAndSignatureAsTargetClassMethod() { TargetClassDefinition classDefinition = DefinitionObjectMother.BuildUnvalidatedDefinition( typeof(TargetClassWithSameNamesAsIntroducedMembers), typeof(MixinIntroducingMembersWithDifferentVisibilities)); MethodIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedMethods[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetMethod("MethodWithPublicVisibility")]; var log = Validator.Validate(definition); Assert.That(HasFailure("Remotion.Mixins.Validation.Rules.DefaultMethodIntroductionRules.PublicMethodNameMustBeUniqueInTargetClass", log), Is.True); }
public void SucceedsIfPublicIntroducedMethod_HasSameNameButDifferentSignatureFromTargetClassMethod() { TargetClassDefinition classDefinition = DefinitionObjectMother.BuildUnvalidatedDefinition( typeof(TargetClassWithSameNamesDifferentSignaturesAsIntroducedMembers), typeof(MixinIntroducingMembersWithDifferentVisibilities)); MethodIntroductionDefinition definition = classDefinition.ReceivedInterfaces[typeof(IMixinIntroducingMembersWithDifferentVisibilities)].IntroducedMethods[typeof(IMixinIntroducingMembersWithDifferentVisibilities).GetMethod("MethodWithPublicVisibility")]; var log = Validator.Validate(definition); AssertSuccess(log); }
public void Visit(MethodIntroductionDefinition methodIntroduction) { ArgumentUtility.CheckNotNull("methodIntroduction", methodIntroduction); CheckRules(_methodIntroductionRules, methodIntroduction); }
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); }