public void GetMixinConfiguration_IncludeGac()
        {
            Expect.Call(_serviceProvider.GetService(typeof(ITypeDiscoveryService))).Return(_typeDiscoveryService);
            Expect.Call(_typeDiscoveryService.GetTypes(typeof(object), false))
            .Return(
                new object[]
            {
                typeof(DerivedBusinessObjectClassWithoutAttribute),
                typeof(SimpleBusinessObjectClass),
                typeof(ClassWithIdentity),
                typeof(ManualBusinessObject),
            });

            _mockRepository.ReplayAll();

            var finder = new BindableObjectTypeFinder(_serviceProvider);
            MixinConfiguration configuration = finder.GetMixinConfiguration(true);

            Assert.That(configuration.ClassContexts.Count, Is.EqualTo(3));
            Assert.That(configuration.ClassContexts.ContainsExact(typeof(BaseBusinessObjectClass)));
            Assert.That(configuration.ClassContexts.ContainsExact(typeof(DerivedBusinessObjectClassWithoutAttribute)), Is.False);
            Assert.That(configuration.ClassContexts.ContainsExact(typeof(SimpleBusinessObjectClass)));
            Assert.That(configuration.ClassContexts.ContainsExact(typeof(ClassWithIdentity)));

            Assert.That(configuration.GetContext(typeof(BaseBusinessObjectClass)).Mixins.ContainsKey(typeof(BindableObjectMixin)));
            Assert.That(configuration.GetContext(typeof(ClassWithIdentity)).Mixins.ContainsKey(typeof(BindableObjectWithIdentityMixin)));

            _mockRepository.VerifyAll();
        }
Exemplo n.º 2
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);
        }
        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));
        }
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
0
        public void MixinsOnInterface()
        {
            MixinConfiguration configuration = MixinConfiguration.BuildNew().ForClass <IBaseType2> ().AddMixin <BT2Mixin1> ().BuildConfiguration();

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

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

            Assert.That(classContext.Mixins.ContainsKey(typeof(BT2Mixin1)), Is.True);
        }
Exemplo n.º 8
0
        public void BuildFromAssemblies_WithParentConfiguration()
        {
            var parentConfiguration = new MixinConfiguration(new ClassContextCollection(ClassContextObjectMother.Create(typeof(object))));

            var assemblies = new[] { typeof(BaseType1).Assembly, typeof(object).Assembly };
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(parentConfiguration, assemblies);

            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(BaseType1)), Is.True);
            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(object)), Is.True);
            Assert.That(configuration.GetContext(typeof(BaseType6)).ComposedInterfaces, Has.Member(typeof(ICBT6Mixin1)));
        }
Exemplo n.º 9
0
        public void BuildConfiguration_IncludesParentConfiguration_WithComposedInterfaces()
        {
            var existingClassContext = new ClassContext(typeof(BaseType3), new MixinContext[0], new[] { typeof(IBaseType31) });
            var parentConfiguration  = new MixinConfiguration(new ClassContextCollection(existingClassContext));

            var builder = new MixinConfigurationBuilder(parentConfiguration);

            MixinConfiguration configuration = builder.BuildConfiguration();

            Assert.That(configuration.GetContext(typeof(BaseType3)).ComposedInterfaces, Has.Member(typeof(IBaseType31)));
        }
Exemplo n.º 10
0
        public void ComposedInterfaceConfiguredViaAttribute()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());

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

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

            Assert.That(classContext.ComposedInterfaces, Has.Member(typeof(ICBT6Mixin1)));
            Assert.That(classContext.ComposedInterfaces, Has.Member(typeof(ICBT6Mixin2)));
            Assert.That(classContext.ComposedInterfaces, Has.Member(typeof(ICBT6Mixin3)));
        }
Exemplo n.º 11
0
        public void MixinAttributeOnTargetClass()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());

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

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

            Assert.That(classContext.Mixins.ContainsKey(typeof(MixinWithAdditionalClassDependency)), Is.True);
            Assert.That(
                classContext.Mixins[typeof(MixinWithAdditionalClassDependency)].ExplicitDependencies, Has.Member(typeof(MixinWithNoAdditionalDependency)));
        }
Exemplo n.º 12
0
        public void BuildConfiguration_WithParentConfiguration()
        {
            MixinConfiguration parentConfiguration = MixinConfiguration.BuildNew().ForClass <int>().AddMixin <string>().BuildConfiguration();
            var builder = new DeclarativeConfigurationBuilder(parentConfiguration);

            builder.AddType(typeof(User));

            MixinConfiguration configuration = builder.BuildConfiguration();
            ClassContext       c1            = new ClassContextBuilder(typeof(User)).AddMixin(typeof(NullMixin)).OfKind(MixinKind.Used).BuildClassContext();

            Assert.That(configuration.ClassContexts,
                        Is.EquivalentTo(new object[] { c1, parentConfiguration.GetContext(typeof(int)), _globalClassContext }));
        }
Exemplo n.º 13
0
        public void DuplicateAssembliesAreIgnored()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(
                Assembly.GetExecutingAssembly(),
                Assembly.GetExecutingAssembly());

            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);
        }
Exemplo n.º 14
0
        public void BuildConfigurationFromAssemblies()
        {
            MixinConfiguration configuration = DeclarativeConfigurationBuilder.BuildConfigurationFromAssemblies(Assembly.GetExecutingAssembly());

            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(BaseType1)), Is.True);

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

            Assert.That(contextForBaseType1.Mixins.Count, Is.EqualTo(2));

            Assert.That(contextForBaseType1.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True);
            Assert.That(contextForBaseType1.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.True);
        }
        public void DerivedDerivedContextWithOwnMixin_Order2()
        {
            var builder = new DeclarativeConfigurationBuilder(null);

            builder.AddType(typeof(DerivedDerivedWithOwnMixin));
            builder.AddType(typeof(Derived));
            builder.AddType(typeof(Base));

            MixinConfiguration configuration = builder.BuildConfiguration();
            ClassContext       classContext  = configuration.GetContext(typeof(DerivedDerivedWithOwnMixin));

            Assert.That(classContext, Is.Not.Null);
            Assert.That(classContext.Mixins.ContainsKey(typeof(NullMixin)), Is.True);
            Assert.That(classContext.Mixins.ContainsKey(typeof(NullMixin2)), Is.True);
            Assert.That(classContext.Mixins.Count, Is.EqualTo(2));
        }
Exemplo n.º 16
0
        public void BuildConfiguration_IncludesParentConfiguration_WithClassContext_Unmodified()
        {
            var existingContext     = ClassContextObjectMother.Create(typeof(BaseType1), typeof(BT1Mixin1));
            var parentConfiguration = new MixinConfiguration(new ClassContextCollection(existingContext));

            var builder = new MixinConfigurationBuilder(parentConfiguration);

            MixinConfiguration configuration = builder.BuildConfiguration();

            Assert.That(configuration.ClassContexts.Count, Is.EqualTo(1));

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

            Assert.That(classContext, Is.Not.Null);
            Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin1)), Is.True);
            Assert.That(classContext.Mixins.ContainsKey(typeof(BT1Mixin2)), Is.False);
        }
Exemplo n.º 17
0
        public IEnumerable <Type> FindMixedTypes(MixinConfiguration configuration)
        {
            ArgumentUtility.CheckNotNull("configuration", configuration);

            var types = _typeDiscoveryService.GetTypes(null, false);

            s_log.InfoFormat(
                "Retrieving class contexts for {0} configured mixin targets and {1} loaded types.",
                configuration.ClassContexts.Count,
                types.Count);

            return(from t in types.Cast <Type>()
                   where !t.IsDefined(typeof(IgnoreForMixinConfigurationAttribute), false)
                   let context = configuration.GetContext(t)
                                 where context != null && !MixinTypeUtility.IsGeneratedConcreteMixedType(t) && ShouldProcessContext(context)
                                 select t);
        }