Exemplo n.º 1
0
        public void MixinsIntroduceAttributes_InheritedFromBase()
        {
            TargetClassDefinition target = DefinitionObjectMother.GetTargetClassDefinition(typeof(NullTarget), typeof(MixinInheritingAttributes));

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

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

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

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

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

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

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

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

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

            Assert.That(member.Base.ReceivedAttributes, Has.Member(memberAttributeIntroduction));
        }
Exemplo n.º 2
0
        public void IndirectAttributeIntroduction_ViaCopy_OfAttributesInheritedFromCopyBase()
        {
            var mixinType = typeof(MixinIndirectlyAddingAttributeInheritedFromAttributeSourceBase);
            var target    = DefinitionObjectMother.GetTargetClassDefinition(typeof(NullTarget), mixinType);

            var mixin = target.Mixins[mixinType];

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

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

            Assert.That(target.ReceivedAttributes.Keys, Has.Member(typeof(InheritableAttribute)));
            Assert.That(target.ReceivedAttributes.Keys, Has.No.Member(typeof(NonInheritableAttribute)));
            Assert.That(target.ReceivedAttributes[typeof(InheritableAttribute)].Single().Attribute, Is.SameAs(mixinAttribute));

            var member = mixin.Methods[mixinType.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.Base.ReceivedAttributes.Keys, Has.Member(typeof(InheritableAttribute)));
            Assert.That(member.Base.ReceivedAttributes.Keys, Has.No.Member(typeof(NonInheritableAttribute)));
            Assert.That(member.Base.ReceivedAttributes[typeof(InheritableAttribute)].Single().Attribute, Is.SameAs(memberAttribute));
        }
        public void SetUp()
        {
            _serializationInfo = new SerializationInfo(typeof(object), new FormatterConverter());
            _context           = new StreamingContext();
            _concreteMixin     = new FakeConcreteMixinType();
            var classContext = ClassContextObjectMother.Create(typeof(ClassOverridingMixinMembers), typeof(FakeConcreteMixinType));

            _identifier = DefinitionObjectMother.GetTargetClassDefinition(classContext).Mixins[0].GetConcreteMixinTypeIdentifier();

            _pipeline = SafeServiceLocator.Current.GetInstance <IPipelineFactory>().Create("MixinSerializationHelper", new MixinParticipant());
            SafeServiceLocator.Current.GetInstance <IPipelineRegistry>().Register(_pipeline);
        }
        public void IdentifierMember_HoldsIdentifier()
        {
            var requestingClass = MixinConfiguration.ActiveConfiguration.GetContext(typeof(ClassOverridingMixinMembers));

            MixinDefinition mixinDefinition = DefinitionObjectMother.GetTargetClassDefinition(requestingClass).Mixins[typeof(MixinWithAbstractMembers)];

            Assert.That(mixinDefinition, Is.Not.Null);
            Type generatedType = CodeGenerationTypeMother.GetGeneratedMixinType(requestingClass, typeof(MixinWithAbstractMembers));

            var identifier = generatedType.GetField("__identifier").GetValue(null);

            Assert.That(identifier, Is.EqualTo(mixinDefinition.GetConcreteMixinTypeIdentifier()));
        }
        public void MixinTypeAttribute_CanBeUsedToGetIdentifier()
        {
            var requestingClass = MixinConfiguration.ActiveConfiguration.GetContext(typeof(ClassOverridingMixinMembers));

            MixinDefinition mixinDefinition = DefinitionObjectMother.GetTargetClassDefinition(requestingClass).Mixins[typeof(MixinWithAbstractMembers)];

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

            Type generatedType = CodeGenerationTypeMother.GetGeneratedMixinType(requestingClass, typeof(MixinWithAbstractMembers));

            Assert.That(generatedType.IsDefined(typeof(ConcreteMixinTypeAttribute), false), Is.True);

            var attributes = (ConcreteMixinTypeAttribute[])generatedType.GetCustomAttributes(typeof(ConcreteMixinTypeAttribute), false);

            Assert.That(attributes[0].GetIdentifier(), Is.EqualTo(mixinDefinition.GetConcreteMixinTypeIdentifier()));
        }