public void UsesAttributeIsInheritedOnNonGenericTypesInheritingFromGeneric() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(NonGenericDerivedWithInheritedMixinFromGeneric)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(NonGenericDerivedWithInheritedMixinFromGeneric)).Mixins.ContainsKey(typeof(NullMixin)), Is.True); Assert.That(configuration.GetContext(typeof(NonGenericDerivedWithInheritedMixinFromGeneric)).Mixins.Count, Is.EqualTo(1)); }
public void InheritedUsesCanBeOverridden() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(DerivedWithMoreSpecificUses)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(DerivedWithMoreSpecificUses)).Mixins.ContainsKey(typeof(DerivedNullMixin)), Is.True); Assert.That(configuration.GetContext(typeof(DerivedWithMoreSpecificUses)).Mixins.ContainsKey(typeof(NullMixin)), Is.False); Assert.That(configuration.GetContext(typeof(DerivedWithMoreSpecificUses)).Mixins.Count, Is.EqualTo(1)); }
public void UsesAttributeIsInherited() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(DerivedWithoutUses)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(DerivedWithoutUses)).Mixins.ContainsKey(typeof(NullMixin)), Is.True); Assert.That(configuration.GetContext(typeof(DerivedWithoutUses)).Mixins[typeof(NullMixin)].ExplicitDependencies, Has.Member(typeof(object))); Assert.That(configuration.GetContext(typeof(DerivedWithoutUses)).Mixins.Count, Is.EqualTo(1)); }
public void InheritedDuplicateExtensionIsIgnored() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(ExtendingMixin)) .AddType(typeof(ExtendsTargetDerivedWithExtends)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithExtends)).Mixins.ContainsKey(typeof(ExtendingMixin)), Is.True); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithExtends)).Mixins.Count, Is.EqualTo(1)); }
public void ExtendsAttributeAppliesToInheritanceChain() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(ExtendingMixin)) .AddType(typeof(ExtendsTargetDerivedWithoutExtends)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithoutExtends)).Mixins.ContainsKey(typeof(ExtendingMixin)), Is.True); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithoutExtends)).Mixins.Count, Is.EqualTo(1)); }
public void ExtendsAppliedToSpecificGenericClass() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(MixinExtendingSpecificGenericClass)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(GenericClassExtendedByMixin <int>)), Is.Not.Null); Assert.That(configuration.GetContext(typeof(GenericClassExtendedByMixin <string>)), Is.Null); Assert.That(configuration.GetContext(typeof(GenericClassExtendedByMixin <>)), Is.Null); }
public void DuplicateExtendsForSameClassInInheritanceHierarchyIsIgnored() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(MixinExtendingBaseAndDerived)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(ExtendsTargetBase)).Mixins.ContainsKey(typeof(MixinExtendingBaseAndDerived)), Is.True); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithoutExtends)).Mixins.ContainsKey(typeof(MixinExtendingBaseAndDerived)), Is.True); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithoutExtends)).Mixins.Count, Is.EqualTo(1)); }
public void AdditionalDependencies() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(UserWithoutDependencies)).AddType(typeof(UserWithDependencies)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(UserWithoutDependencies)).Mixins[typeof(NullMixin)].ExplicitDependencies.Count, Is.EqualTo(0)); Assert.That(configuration.GetContext(typeof(UserWithDependencies)).Mixins[typeof(NullMixin)].ExplicitDependencies.Count, Is.EqualTo(1)); Assert.That(configuration.GetContext(typeof(UserWithDependencies)).Mixins[typeof(NullMixin)].ExplicitDependencies, Has.Member(typeof(string))); }
public void ExplicitApplicationOfBaseAndDerivedMixinToSameClass() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(ExtendingMixin)).AddType(typeof(DerivedExtendingMixin)) .AddType(typeof(DerivedExtendingMixin2)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithDerivedExtends)).Mixins.ContainsKey(typeof(ExtendingMixin)), Is.False); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithDerivedExtends)).Mixins.ContainsKey(typeof(DerivedExtendingMixin)), Is.True); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithDerivedExtends)).Mixins.ContainsKey(typeof(DerivedExtendingMixin2)), Is.True); Assert.That(configuration.GetContext(typeof(ExtendsTargetDerivedWithDerivedExtends)).Mixins.Count, Is.EqualTo(2)); }
public void UsesAttributeIsInherited_AndAugmentedWithOwn() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(DerivedWithOwnUses)).BuildConfiguration(); Assert.That(configuration.GetContext(typeof(DerivedWithOwnUses)).Mixins.ContainsKey(typeof(NullMixin)), Is.True); Assert.That(configuration.GetContext(typeof(DerivedWithOwnUses)).Mixins.ContainsKey(typeof(DedicatedMixin)), Is.True); Type[] mixinTypes = configuration.GetContext(typeof(DerivedWithOwnUses)).Mixins.Select(mixin => mixin.MixinType).ToArray(); Assert.That(mixinTypes, Is.EquivalentTo(new[] { typeof(NullMixin), typeof(DedicatedMixin) })); Assert.That(configuration.GetContext(typeof(DerivedWithOwnUses)).Mixins.Count, Is.EqualTo(2)); }
public void ComposedInterface_ViaIHasComposedInterface_Derived() { var result = new DeclarativeConfigurationBuilder(null) .AddType(typeof(ClassDerivedFromBaseClassWithHasComleteInterface)) .AddType(typeof(DerivedClassDerivedFromBaseClassWithHasComleteInterface)).BuildConfiguration(); var baseClassContext = result.GetContext(typeof(ClassDerivedFromBaseClassWithHasComleteInterface)); Assert.That(baseClassContext.ComposedInterfaces, Has.Member(typeof(ClassDerivedFromBaseClassWithHasComleteInterface.IComposedInterface))); var derivedClassContext = result.GetContext(typeof(DerivedClassDerivedFromBaseClassWithHasComleteInterface)); Assert.That(derivedClassContext.ComposedInterfaces, Has.Member(typeof(ClassDerivedFromBaseClassWithHasComleteInterface.IComposedInterface))); }
public void ComposedInterface_ViaIHasComposedInterface() { var result = new DeclarativeConfigurationBuilder(null).AddType(typeof(ClassWithHasComposedInterfaces)).BuildConfiguration(); var classContext = result.GetContext(typeof(ClassWithHasComposedInterfaces)); Assert.That(classContext.ComposedInterfaces, Has.Member(typeof(ClassWithHasComposedInterfaces.IComposedInterface1))); Assert.That(classContext.ComposedInterfaces, Has.Member(typeof(ClassWithHasComposedInterfaces.IComposedInterface2))); }
public void ClosedGenericSuppressingMixin() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null) .AddType(typeof(GenericMixinWithSpecialization <,>)) .AddType(typeof(MixinSuppressingClosedGenericMixin)).BuildConfiguration(); ClassContext classContext = configuration.GetContext(typeof(ClassWithMixins)); Assert.That(classContext.Mixins.ContainsKey(typeof(GenericMixinWithSpecialization <List <int>, IList <int> >)), Is.False); }
public void ExtendsCanSpecializeGenericMixin() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(GenericMixinWithSpecialization <,>)).BuildConfiguration(); MixinContext mixinContext = new List <MixinContext> (configuration.GetContext(typeof(ExtendsTargetBase)).Mixins)[0]; Assert.That(Reflection.TypeExtensions.CanAscribeTo(mixinContext.MixinType, typeof(GenericMixinWithSpecialization <,>)), Is.True); Assert.That(mixinContext.MixinType.IsGenericTypeDefinition, Is.False); Assert.That(mixinContext.MixinType.ContainsGenericParameters, Is.False); Assert.That(mixinContext.MixinType.GetGenericArguments(), Is.EqualTo(new[] { typeof(List <int>), typeof(IList <int>) })); }
public void SubclassExtensionOverridesBaseExtends() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null) .AddType(typeof(ExtendingMixin)) .AddType(typeof(DerivedExtendingMixin)) .BuildConfiguration(); var classContext = configuration.GetContext(typeof(ExtendsTargetDerivedWithDerivedExtends)); Assert.That(classContext.Mixins.ContainsKey(typeof(ExtendingMixin)), Is.False); Assert.That(classContext.Mixins.ContainsKey(typeof(DerivedExtendingMixin)), Is.True); Assert.That(classContext.Mixins.Count, Is.EqualTo(1)); }
public void Origin() { var configuration = new DeclarativeConfigurationBuilder(null).AddType(typeof(User)).BuildConfiguration(); var context = configuration.GetContext(typeof(User)); var mixinContext = context.Mixins.Single(); var expectedOrigin = new MixinContextOrigin( "UsesAttribute", typeof(User).Assembly, "Remotion.Mixins.UnitTests.Core.Context.DeclarativeConfigurationBuilder_IntegrationTests.UsesAnalysisTest+User"); Assert.That(mixinContext.Origin, Is.EqualTo(expectedOrigin)); }
public void DuplicateTypesAreIgnored() { MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null) .AddType(typeof(BaseType1)) .AddType(typeof(BaseType1)) .AddType(typeof(BT1Mixin1)) .AddType(typeof(BT1Mixin1)) .AddType(typeof(BT1Mixin2)) .AddType(typeof(BT1Mixin2)) .BuildConfiguration(); ClassContext classContext = configuration.GetContext(typeof(BaseType1)); Assert.That(classContext.Mixins.Count, Is.EqualTo(2)); Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True); Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.True); }