Exemplo n.º 1
0
 public void SetUp()
 {
     _builder            = new DeclarativeConfigurationBuilder(null);
     _globalClassContext = new ClassContextBuilder(typeof(TargetClassForGlobalMix))
                           .AddMixin(typeof(MixinForGlobalMix)).WithDependency(typeof(AdditionalDependencyForGlobalMix))
                           .AddMixin(typeof(AdditionalDependencyForGlobalMix)).BuildClassContext();
 }
Exemplo n.º 2
0
        public void BuildDefault()
        {
            MixinConfiguration ac = DeclarativeConfigurationBuilder.BuildDefaultConfiguration();

            Assert.That(ac, Is.Not.Null);
            Assert.That(ac.ClassContexts.Count, Is.Not.EqualTo(0));
        }
        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));
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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 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 ComposedInterface_ViaIHasComposedInterface_ViaGenericBaseClass()
        {
            var result = new DeclarativeConfigurationBuilder(null).AddType(typeof(ClassDerivedFromBaseClassWithHasComleteInterface)).BuildConfiguration();

            var classContext = result.GetContext(typeof(ClassDerivedFromBaseClassWithHasComleteInterface));

            Assert.That(classContext.ComposedInterfaces, Has.Member(typeof(ClassDerivedFromBaseClassWithHasComleteInterface.IComposedInterface)));
        }
Exemplo n.º 10
0
        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));
        }
 private static MixinConfiguration BuildMasterConfiguration()
 {
     s_log.Info("Building mixin master configuration...");
     using (StopwatchScope.CreateScope(s_log, LogLevel.Info, "Time needed to build mixin master configuration: {elapsed}."))
     {
         return(DeclarativeConfigurationBuilder.BuildDefaultConfiguration());
     }
 }
Exemplo n.º 12
0
        public void OverrideAlsoWorksForGenericsOpenOpen()
        {
            ClassContext ctx = new DeclarativeConfigurationBuilder(null).AddType(typeof(DerivedWithOpenOverridingOpen)).BuildConfiguration().GetContext(typeof(DerivedWithOpenOverridingOpen));

            Assert.That(ctx.Mixins.ContainsKey(typeof(DerivedGenericMixin <,>)), Is.True);
            Assert.That(ctx.Mixins.ContainsKey(typeof(BaseGenericMixin <,>)), Is.False);
            Assert.That(ctx.Mixins.Count, Is.EqualTo(1));
        }
Exemplo n.º 13
0
        public void OverrideAlsoWorksForGenericsRealClosedClosed()
        {
            ClassContext ctx = new DeclarativeConfigurationBuilder(null).AddType(typeof(DerivedWithRealClosedOverridingClosed)).BuildConfiguration().GetContext(typeof(DerivedWithRealClosedOverridingClosed));

            Assert.That(ctx.Mixins.ContainsKey(typeof(DerivedClosedMixin)), Is.True);
            Assert.That(ctx.Mixins.ContainsKey(typeof(BaseGenericMixin <BaseWithClosedGeneric, object>)), Is.False);
            Assert.That(ctx.Mixins.Count, Is.EqualTo(1));
        }
Exemplo n.º 14
0
        public void IgnoreForMixinConfiguration()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromTypes(
                null,
                new[] { typeof(BaseType1), typeof(BT1Mixin1), typeof(MixinWithIgnoreForMixinConfigurationAttribute) });

            Assert.That(configuration.GetContext(typeof(BaseType1)).Mixins.ContainsKey(typeof(MixinWithIgnoreForMixinConfigurationAttribute)), Is.False);
        }
Exemplo n.º 15
0
        public void BuildFromAssemblies()
        {
            var assemblies = new[] { typeof(BaseType1).Assembly, typeof(object).Assembly };
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(assemblies);

            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(BaseType1)), Is.True);
            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(object)), Is.False);
        }
Exemplo n.º 16
0
        public void BuildConfigurationFromAssemblies_Multiple()
        {
            var assemblies = new[] { typeof(BaseType1).Assembly, typeof(DisposableMixin).Assembly };
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(null, assemblies);

            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(BaseType1)), Is.True);
            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(DisposableMixinTest.C)), Is.True);
        }
Exemplo n.º 17
0
        public void BuildConfiguration_Duplicates_NotIgnoredInGeneral()
        {
            var builder = new DeclarativeConfigurationBuilder(null);

            builder.AddType(typeof(TypeWithDuplicateAttributeNotIgnoringDuplicates));

            Assert.That(() => builder.BuildConfiguration(), Throws.TypeOf <ConfigurationException>().With.Message.StringContaining("already configured"));
        }
Exemplo n.º 18
0
        public void ClosedGenericClassContext_Closed_NoOwnMixin()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());
            ClassContext       classContext  = configuration.GetContext(typeof(GenericClass <string>));

            Assert.That(classContext, Is.Not.Null);
            Assert.That(classContext.Mixins.ContainsKey(typeof(MixinForOpenGeneric)), Is.True);
            Assert.That(classContext.Mixins.Count, Is.EqualTo(1));
        }
Exemplo n.º 19
0
        public void BuildConfigurationFromAssemblies()
        {
            var assemblies = new[] { typeof(TargetClass1).Assembly, typeof(object).Assembly };

            var reflectedOuput = _remotionReflector.BuildConfigurationFromAssemblies(assemblies);
            var expectedOutput = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(assemblies);

            Assert.That(reflectedOuput.To <MixinConfiguration> ().ClassContexts, Is.EqualTo(expectedOutput.ClassContexts));
        }
Exemplo n.º 20
0
        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)));
        }
Exemplo n.º 21
0
        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);
        }
Exemplo n.º 22
0
        protected T BuildMixedInstanceWithDeclarativeConfiguration <T> (params Type[] additionalAnalyzedTypes)
        {
            var mixinConfiguration = DeclarativeConfigurationBuilder.BuildConfigurationFromTypes(null, additionalAnalyzedTypes.Concat(typeof(OrderingViaAttributeDependencyTest.C)));

            using (mixinConfiguration.EnterScope())
            {
                return(ObjectFactory.Create <T>());
            }
        }
        public void DerivedDerivedContext()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());
            ClassContext       classContext  = configuration.GetContext(typeof(DerivedDerived));

            Assert.That(classContext, Is.Not.Null);
            Assert.That(classContext.Mixins.ContainsKey(typeof(NullMixin)), Is.True);
            Assert.That(classContext.Mixins.Count, Is.EqualTo(1));
        }
        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 SetUp()
        {
            var validationTestDomainNamespace = typeof(AbstractMixinWithoutBase).Namespace;
            var globalTestDomainNamespace     = typeof(BaseType1).Namespace;
            var typeDiscoveryService          = FilteringTypeDiscoveryService.CreateFromNamespaceWhitelist(
                ContextAwareTypeUtility.GetTypeDiscoveryService(), validationTestDomainNamespace, globalTestDomainNamespace);
            var types = typeDiscoveryService.GetTypes(null, false);

            _configurationScope = DeclarativeConfigurationBuilder.BuildConfigurationFromTypes(null, types.Cast <Type>()).EnterScope();
        }
Exemplo n.º 26
0
        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>) }));
        }
Exemplo n.º 27
0
        public void DerivedGenericClassFromOpenContext_Open()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());
            ClassContext       classContext  = configuration.GetContext(typeof(DerivedGenericClassFromOpen <>));

            Assert.That(classContext, Is.Not.Null);
            Assert.That(classContext.Mixins.ContainsKey(typeof(MixinForOpenGeneric)), Is.True);
            Assert.That(classContext.Mixins.ContainsKey(typeof(MixinForDerivedOpenGeneric)), Is.True);
            Assert.That(classContext.Mixins.Count, Is.EqualTo(2));
        }
Exemplo n.º 28
0
        public void MixinAttributeOnMixinClass()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());

            ClassContext classContext = configuration.GetContext(typeof(BaseType1));

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

            Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True);
        }
Exemplo n.º 29
0
        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));
        }
Exemplo n.º 30
0
        public void CircularSuppressingMixins()
        {
            MixinConfiguration configuration = new DeclarativeConfigurationBuilder(null)
                                               .AddType(typeof(MixinWithCircularSuppress1))
                                               .AddType(typeof(MixinWithCircularSuppress2))
                                               .BuildConfiguration();
            ClassContext classContext = configuration.ClassContexts.GetExact(typeof(ClassWithMixins));

            Assert.That(classContext.IsEmpty(), Is.True);
        }