Ejemplo n.º 1
0
        public void FromClassContextSimple()
        {
            var simpleContext = ClassContextObjectMother.Create(typeof(object), typeof(string));
            ConcreteMixedTypeAttribute attribute = CreateAttribute(simpleContext);

            var deserializer = new AttributeClassContextDeserializer(attribute.ClassContextData);

            Assert.That(ClassContext.Deserialize(deserializer), Is.EqualTo(simpleContext));
        }
Ejemplo n.º 2
0
        public void GetClassContextSimple()
        {
            var simpleContext = ClassContextObjectMother.Create(typeof(object), typeof(string));
            ConcreteMixedTypeAttribute attribute = CreateAttribute(simpleContext);
            ClassContext regeneratedContext      = attribute.GetClassContext();

            Assert.That(simpleContext, Is.EqualTo(regeneratedContext));
            Assert.That(simpleContext, Is.Not.SameAs(regeneratedContext));
        }
Ejemplo n.º 3
0
        public void AttributeWithGenericType()
        {
            ClassContext context = ClassContextObjectMother.Create(typeof(List <>)).SpecializeWithTypeArguments(new[] { typeof(int) });

            Assert.That(context.Type, Is.EqualTo(typeof(List <int>)));
            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);

            ClassContext regeneratedContext = attribute.GetClassContext();

            Assert.That(regeneratedContext.Type, Is.EqualTo(typeof(List <int>)));
        }
        public void AddConcreteMixedTypeAttribute(IMutableMember member, ClassContext classContext, IEnumerable <Type> orderedMixinTypes)
        {
            ArgumentUtility.CheckNotNull("member", member);
            ArgumentUtility.CheckNotNull("classContext", classContext);
            ArgumentUtility.CheckNotNull("orderedMixinTypes", orderedMixinTypes);

            var attributeData = ConcreteMixedTypeAttribute.FromClassContext(classContext, orderedMixinTypes.ToArray());
            var attribute     = new CustomAttributeDeclaration(
                s_concreteMixedTypeAttributeConstructor, new object[] { attributeData.ClassContextData, attributeData.OrderedMixinTypes });

            member.AddCustomAttribute(attribute);
        }
Ejemplo n.º 5
0
        public void FromClassContext_MixinKinds()
        {
            ClassContext context = new ClassContextBuilder(typeof(int))
                                   .AddComposedInterface(typeof(uint))
                                   .AddMixin(typeof(string)).OfKind(MixinKind.Extending)
                                   .AddMixin(typeof(double)).OfKind(MixinKind.Used)
                                   .BuildClassContext();

            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);
            var deserializer = new AttributeClassContextDeserializer(attribute.ClassContextData);

            Assert.That(ClassContext.Deserialize(deserializer), Is.EqualTo(context));
        }
Ejemplo n.º 6
0
        public void FromClassContextComplex()
        {
            ClassContext context = new ClassContextBuilder(typeof(int))
                                   .AddComposedInterface(typeof(uint))
                                   .AddMixin(typeof(string)).WithDependency(typeof(bool))
                                   .AddMixin(typeof(double)).WithDependency(typeof(int))
                                   .BuildClassContext();

            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);

            var deserializer = new AttributeClassContextDeserializer(attribute.ClassContextData);

            Assert.That(ClassContext.Deserialize(deserializer), Is.EqualTo(context));
        }
Ejemplo n.º 7
0
        public void GetClassContext_MixinKinds()
        {
            ClassContext context = new ClassContextBuilder(typeof(int))
                                   .AddComposedInterface(typeof(uint))
                                   .AddMixin(typeof(string)).OfKind(MixinKind.Extending)
                                   .AddMixin(typeof(double)).OfKind(MixinKind.Used)
                                   .BuildClassContext();

            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);
            ClassContext regeneratedContext      = attribute.GetClassContext();

            Assert.That(regeneratedContext.Mixins[typeof(string)].MixinKind, Is.EqualTo(MixinKind.Extending));
            Assert.That(regeneratedContext.Mixins[typeof(double)].MixinKind, Is.EqualTo(MixinKind.Used));
        }
Ejemplo n.º 8
0
        public void GetClassContextComplex()
        {
            ClassContext context = new ClassContextBuilder(typeof(int))
                                   .AddMixin(typeof(double))
                                   .AddComposedInterface(typeof(uint))
                                   .AddMixin(typeof(string)).WithDependency(typeof(bool))
                                   .BuildClassContext();

            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);
            ClassContext regeneratedContext      = attribute.GetClassContext();

            Assert.That(context, Is.EqualTo(regeneratedContext));
            Assert.That(context, Is.Not.SameAs(regeneratedContext));
        }
Ejemplo n.º 9
0
        public void GetClassContext_Dependencies()
        {
            ClassContext context = new ClassContextBuilder(typeof(int))
                                   .AddMixin(typeof(object)).OfKind(MixinKind.Extending).WithDependencies(typeof(double), typeof(bool))
                                   .AddMixin(typeof(string)).OfKind(MixinKind.Extending).WithDependencies(typeof(bool))
                                   .AddMixin(typeof(int)).OfKind(MixinKind.Extending)
                                   .BuildClassContext();

            ConcreteMixedTypeAttribute attribute = CreateAttribute(context);
            ClassContext regeneratedContext      = attribute.GetClassContext();

            Assert.That(regeneratedContext.Mixins.Count, Is.EqualTo(3));

            Assert.That(regeneratedContext.Mixins[typeof(object)].ExplicitDependencies, Is.EqualTo(new object[] { typeof(double), typeof(bool) }));
            Assert.That(regeneratedContext.Mixins[typeof(string)].ExplicitDependencies, Is.EqualTo(new object[] { typeof(bool) }));
            Assert.That(regeneratedContext.Mixins[typeof(int)].ExplicitDependencies, Is.Empty);
        }
Ejemplo n.º 10
0
        public void GetMetadataForMixedType()
        {
            var classContext1 = ClassContextObjectMother.Create(typeof(object));

            var attribute1 = ConcreteMixedTypeAttribute.FromClassContext(classContext1, new Type[0]);

            var typeMock = MockRepository.GenerateMock <_Type> ();

            typeMock.Expect(mock => mock.GetCustomAttributes(typeof(ConcreteMixedTypeAttribute), false)).Return(new[] { attribute1 });
            typeMock.Replay();

            var importer = new AttributeBasedMetadataImporter();
            var result   = importer.GetMetadataForMixedType(typeMock);

            Assert.That(result, Is.EqualTo(classContext1));

            typeMock.VerifyAllExpectations();
        }
Ejemplo n.º 11
0
 private ConcreteMixedTypeAttribute CreateAttribute(ClassContext context)
 {
     return(ConcreteMixedTypeAttribute.FromClassContext(context, context.Mixins.Select(m => m.MixinType).ToArray()));
 }