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)); }
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)); }
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); }
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)); }
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)); }
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)); }
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)); }
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); }
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(); }
private ConcreteMixedTypeAttribute CreateAttribute(ClassContext context) { return(ConcreteMixedTypeAttribute.FromClassContext(context, context.Mixins.Select(m => m.MixinType).ToArray())); }