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)); }
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 ThrowsOnDoublyIntroducedInterface() { using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(BT1Mixin1), typeof(BT1Mixin1A)).EnterScope()) { DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1)); } }
public void GetAdjustedInterfaceMap_MethodDeclaredOnBaseType() { var classDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(DerivedImplementingInterface)); var mapping = classDefinition.GetAdjustedInterfaceMap(typeof(InterfaceImplementedByDerived)); Assert.That(GetTargetMethod(mapping, "Void Foo()"), Is.EqualTo(typeof(BaseWithDerivedImplementingInterface).GetMethod("Foo"))); }
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 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); }
public void IndirectNextCallDependencies() { TargetClassDefinition targetClass = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(ClassImplementingIndirectRequirements)); MixinDefinition mixin = targetClass.Mixins[typeof(MixinWithIndirectRequirements)]; Assert.That(mixin, Is.Not.Null); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectBaseAggregator)), Is.True); Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectBaseAggregator)].IsAggregatorInterface, Is.True); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirement1)), Is.True); Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirement1)].IsAggregatorInterface, Is.False); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirementBase1)), Is.True); Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirementBase1)].IsAggregatorInterface, Is.False); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirement2)), Is.False); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirementBase2)), Is.False); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirement3)), Is.True); Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirement3)].IsAggregatorInterface, Is.True); Assert.That(targetClass.RequiredNextCallTypes.ContainsKey(typeof(IIndirectRequirementBase3)), Is.True); Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirementBase3)].IsAggregatorInterface, Is.False); Assert.That(targetClass.RequiredNextCallTypes[typeof(IIndirectRequirementBase3)].IsEmptyInterface, Is.False); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectBaseAggregator)), Is.True); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirement1)), Is.True); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirement2)), Is.False); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirement3)), Is.True); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirementBase1)), Is.True); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirementBase2)), Is.False); Assert.That(mixin.NextCallDependencies.ContainsKey(typeof(IIndirectRequirementBase3)), Is.True); }
public void 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 SucceedsIfEmptyAggregateTargetCallDependencyIsNotAvailable() { TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(NullTarget), typeof(MixinWithUnsatisfiedEmptyAggregateTargetCallDependency)); var log = Validator.Validate(definition); AssertSuccess(log); }
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); }
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); }
public void GeneratedTypeImplementsRequiredNextCallInterfaces2() { using (MixinConfiguration.BuildFromActive().ForClass <BaseType3> ().Clear().AddMixins(typeof(BT3Mixin7Base), typeof(BT3Mixin4)).EnterScope()) { Type t = TypeFactory.GetConcreteType(typeof(BaseType3)); Type proxyType = t.GetNestedType("NextCallProxy"); RequiredNextCallTypeDefinition bt3Mixin4Req = DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).RequiredNextCallTypes[typeof(IBT3Mixin4)]; Assert.That(bt3Mixin4Req, Is.Not.Null); Assert.That(bt3Mixin4Req.Type.IsAssignableFrom(proxyType), Is.True); foreach (RequiredNextCallTypeDefinition req in DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType3)).RequiredNextCallTypes) { Assert.That(req.Type.IsAssignableFrom(proxyType), Is.True); } MethodInfo methodImplementdByMixin = proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.IBT3Mixin4.Foo", BindingFlags.NonPublic | BindingFlags.Instance); Assert.That(methodImplementdByMixin, Is.Not.Null); MethodInfo methodImplementdByBCOverridden = proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.IBaseType31.IfcMethod", BindingFlags.NonPublic | BindingFlags.Instance); Assert.That(methodImplementdByBCOverridden, Is.Not.Null); MethodInfo methodImplementdByBCNotOverridden = proxyType.GetMethod("Remotion.Mixins.UnitTests.Core.TestDomain.IBaseType35.IfcMethod2", BindingFlags.NonPublic | BindingFlags.Instance); Assert.That(methodImplementdByBCNotOverridden, Is.Not.Null); } }
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 SucceedsIfAbstractTargetClass() { TargetClassDefinition bc = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(MixinWithAbstractMembers)); var log = Validator.Validate(bc); AssertSuccess(log); }
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)]); }
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 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 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 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)); }
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 GetAllMethods_FindsMethods() { var methodDefinition1 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo1); var methodDefinition2 = DefinitionObjectMother.CreateMethodDefinition(_classDefinition1, _methodInfo2); Assert.That(_classDefinition1.GetAllMethods().ToArray(), Is.EquivalentTo(new[] { methodDefinition1, methodDefinition2 })); }
public void SucceedsIfNestedPublicMixin() { TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType1), typeof(PublicNester.PublicNested)); var log = Validator.Validate(definition); AssertSuccess(log); }
public void SucceedsIfAggregateNextCallDependencyIsFullyImplemented() { TargetClassDefinition definition = DefinitionObjectMother.BuildUnvalidatedDefinition(typeof(BaseType3), typeof(BT3Mixin4), typeof(BT3Mixin7Base)); var log = Validator.Validate(definition); AssertSuccess(log); }
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 CreateRequiredMethodDefinitions_BaseWithSameMembers() { var targetClassDefinition = DefinitionObjectMother.CreateTargetClassDefinition(typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers)); DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTyping).GetMethod("Method1")); DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTyping).GetMethod("Method2")); var m1b = DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers).GetMethod("Method1")); var m2b = DefinitionObjectMother.CreateMethodDefinition( targetClassDefinition, typeof(ClassImplementingInterfaceWithDuckTypingWithBaseWithSameMembers).GetMethod("Method2")); var requirement = DefinitionObjectMother.CreateRequiredTargetCallTypeDefinition(targetClassDefinition, typeof(IInterface)); var builder = new DuckTypingRequiredMethodDefinitionCollector(targetClassDefinition); var definitions = builder.CreateRequiredMethodDefinitions(requirement).OrderBy(def => def.FullName).ToArray(); Assert.That(definitions.Length, Is.EqualTo(2)); Assert.That(definitions[0].DeclaringRequirement, Is.SameAs(requirement)); Assert.That(definitions[0].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method1"))); Assert.That(definitions[0].ImplementingMethod, Is.SameAs(m1b)); Assert.That(definitions[1].DeclaringRequirement, Is.SameAs(requirement)); Assert.That(definitions[1].InterfaceMethod, Is.EqualTo(typeof(IInterface).GetMethod("Method2"))); Assert.That(definitions[1].ImplementingMethod, Is.SameAs(m2b)); }
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 IDeserializationCallbackIsNotIntroduced() { using (MixinConfiguration.BuildFromActive().ForClass <BaseType1> ().Clear().AddMixins(typeof(MixinImplementingISerializable)).EnterScope()) { Assert.That(DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(BaseType1)).Mixins[typeof(MixinImplementingISerializable)].InterfaceIntroductions[typeof(IDeserializationCallback)], Is.Null); } }
public void ThrowsWhenUnfulfilledDuckBase() { using (MixinConfiguration.BuildFromActive().ForClass <NullTarget> ().Clear().AddMixins(typeof(DuckBaseMixinWithoutOverrides)).EnterScope()) { DefinitionObjectMother.GetActiveTargetClassDefinition(typeof(NullTarget)); } }
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)])); } }
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)); }