public void Apply(MixinConfigurationBuilder configurationBuilder, Assembly attributeTarget)
        {
            ArgumentUtility.CheckNotNull("configurationBuilder", configurationBuilder);
            ArgumentUtility.CheckNotNull("attributeTarget", attributeTarget);

            configurationBuilder.ForClass(TargetType).AddMixinDependency(DependentMixin, Dependency);
        }
        public void SetUp()
        {
            _mockRepository           = new MockRepository();
            _configurationBuilderMock = _mockRepository.StrictMock <MixinConfigurationBuilder>((MixinConfiguration)null);

            _analyzer = new HasComposedInterfaceMarkerAnalyzer();
        }
Exemplo n.º 3
0
 private void AnalyzeAssembly(MixinConfigurationBuilder configurationBuilder, Assembly assembly)
 {
     foreach (var assemblyAnalyzer in _assemblyAnalyzers)
     {
         assemblyAnalyzer.Analyze(assembly, configurationBuilder);
     }
 }
Exemplo n.º 4
0
        public void Apply(MixinConfigurationBuilder mixinConfigurationBuilder, Type interfaceType)
        {
            ArgumentUtility.CheckNotNull("mixinConfigurationBuilder", mixinConfigurationBuilder);
            ArgumentUtility.CheckNotNull("interfaceType", interfaceType);

            mixinConfigurationBuilder.ForClass(TargetType).AddComposedInterface(interfaceType);
        }
        public void SetUp()
        {
            _mockRepository           = new MockRepository();
            _configurationBuilderMock = _mockRepository.StrictMock <MixinConfigurationBuilder> ((MixinConfiguration)null);

            _assembly = GetType().Assembly;
        }
        public void Apply(MixinConfigurationBuilder mixinConfigurationBuilder, Type targetClassType)
        {
            ArgumentUtility.CheckNotNull("mixinConfigurationBuilder", mixinConfigurationBuilder);
            ArgumentUtility.CheckNotNull("targetClassType", targetClassType);

            mixinConfigurationBuilder.ForClass(targetClassType).SuppressMixin(MixinToIgnore);
        }
Exemplo n.º 7
0
        public void AddMixinToClass_WithSelfSuppressor()
        {
            var builder = new MixinConfigurationBuilder(null);

            builder.AddMixinToClass(
                MixinKind.Extending, typeof(object), typeof(int), MemberVisibility.Private, new Type[0], new[] { typeof(int) }, _mixinContextOrigin);
        }
Exemplo n.º 8
0
 private void AnalyzeType(MixinConfigurationBuilder configurationBuilder, Type type)
 {
     foreach (var typeAnalyzer in _typeAnalyzers)
     {
         typeAnalyzer.Analyze(type, configurationBuilder);
     }
 }
 public void SetUp()
 {
     _mockRepository    = new MockRepository();
     _parentBuilderMock = _mockRepository.StrictMock <MixinConfigurationBuilder> ((MixinConfiguration)null);
     _classBuilder      = new ClassContextBuilder(_parentBuilderMock, typeof(BaseType2));
     _classBuilderMock  = _mockRepository.StrictMock <ClassContextBuilder> (_parentBuilderMock, typeof(BaseType2));
     _mixinBuilderMock  = _mockRepository.StrictMock <MixinContextBuilder> (_classBuilderMock, typeof(BT2Mixin1), MixinContextOriginObjectMother.Create());
 }
Exemplo n.º 10
0
        public void ForClass_Twice()
        {
            var builder = new MixinConfigurationBuilder(null);
            ClassContextBuilder classBuilder  = builder.ForClass(typeof(BaseType1));
            ClassContextBuilder classBuilder2 = builder.ForClass(typeof(BaseType1));

            Assert.That(classBuilder2, Is.SameAs(classBuilder));
        }
Exemplo n.º 11
0
        public void Apply(MixinConfigurationBuilder configurationBuilder, Assembly attributeTarget)
        {
            ArgumentUtility.CheckNotNull("configurationBuilder", configurationBuilder);
            ArgumentUtility.CheckNotNull("attributeTarget", attributeTarget);

            var origin = MixinContextOrigin.CreateForCustomAttribute(this, attributeTarget);

            Apply(configurationBuilder, MixinKind, TargetType, MixinType, origin);
        }
Exemplo n.º 12
0
        public void ForClass_Generic()
        {
            var builder = new MixinConfigurationBuilder(null);
            ClassContextBuilder classBuilder = builder.ForClass <BaseType1> ();

            Assert.That(classBuilder.TargetType, Is.SameAs(typeof(BaseType1)));
            Assert.That(classBuilder.Parent, Is.SameAs(builder));
            Assert.That(builder.ClassContextBuilders, Has.Member(classBuilder));
        }
        public void SetUp()
        {
            _mockRepository = new MockRepository();

            _typeAnalyzerMock     = _mockRepository.StrictMock <IMixinDeclarationAnalyzer <Type> > ();
            _assemblyAnalyzerMock = _mockRepository.StrictMock <IMixinDeclarationAnalyzer <Assembly> > ();

            _fakeConfigurationBuilder = _mockRepository.Stub <MixinConfigurationBuilder> ((MixinConfiguration)null);
        }
Exemplo n.º 14
0
        public void BuildConfiguration()
        {
            var builder = new MixinConfigurationBuilder(null);

            builder.ForClass <BaseType1> ();
            MixinConfiguration configuration = builder.BuildConfiguration();

            Assert.That(configuration.ClassContexts.Count, Is.EqualTo(1));
            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(BaseType1)), Is.True);
        }
Exemplo n.º 15
0
        public void Apply(MixinConfigurationBuilder configurationBuilder, Type attributeTarget)
        {
            ArgumentUtility.CheckNotNull("configurationBuilder", configurationBuilder);
            ArgumentUtility.CheckNotNull("attributeTarget", attributeTarget);

            Type mixinType = CloseOverMixinTypeArguments(attributeTarget);
            var  origin    = MixinContextOrigin.CreateForCustomAttribute(this, attributeTarget);

            Apply(configurationBuilder, MixinKind.Extending, TargetType, mixinType, origin);
        }
Exemplo n.º 16
0
        public void Intitialization_WithoutParent()
        {
            var builder = new MixinConfigurationBuilder(null);

            Assert.That(builder.ParentConfiguration, Is.Null);
            Assert.That(builder.ClassContextBuilders, Is.Empty);
            MixinConfiguration configuration = builder.BuildConfiguration();

            Assert.That(configuration.ClassContexts.Count, Is.EqualTo(0));
        }
Exemplo n.º 17
0
 public void Apply(MixinConfigurationBuilder configurationBuilder, Type attributeTarget)
 {
     try
     {
         configurationBuilder.ForClass(attributeTarget).AddMixin <NullMixin> ();
     }
     catch (Exception ex)
     {
         throw new ConfigurationException(ex.Message, ex);
     }
 }
Exemplo n.º 18
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.º 19
0
        public void ClassContextInheritance_Base_FromSameConfiguration()
        {
            MixinConfiguration configuration = new MixinConfigurationBuilder(null)
                                               .ForClass <DerivedNullTarget> ().AddMixin(typeof(NullMixin2))
                                               .ForClass <NullTarget> ().AddMixin(typeof(NullMixin))
                                               .BuildConfiguration();
            ClassContext derivedContext = configuration.GetContext(typeof(DerivedNullTarget));

            Assert.That(derivedContext.Mixins.Count, Is.EqualTo(2));
            Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin)), Is.True);
            Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin2)), Is.True);
        }
Exemplo n.º 20
0
        public void ClassContextInheritance_TypeDefinition_FromSameConfiguration()
        {
            MixinConfiguration configuration = new MixinConfigurationBuilder(null)
                                               .ForClass <GenericTargetClass <int> > ().AddMixin(typeof(NullMixin2))
                                               .ForClass(typeof(GenericTargetClass <>)).AddMixin(typeof(NullMixin))
                                               .BuildConfiguration();
            ClassContext derivedContext = configuration.GetContext(typeof(GenericTargetClass <int>));

            Assert.That(derivedContext.Mixins.Count, Is.EqualTo(2));
            Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin)), Is.True);
            Assert.That(derivedContext.Mixins.ContainsKey(typeof(NullMixin2)), Is.True);
        }
        public virtual void Analyze(TAnalyzedEntity entity, MixinConfigurationBuilder configurationBuilder)
        {
            ArgumentUtility.CheckNotNull("entity", entity);
            ArgumentUtility.CheckNotNull("configurationBuilder", configurationBuilder);

            var attributes = _attributeProvider(entity);

            foreach (var attribute in attributes)
            {
                attribute.Apply(configurationBuilder, entity);
            }
        }
Exemplo n.º 22
0
        public void Intitialization_WithParent()
        {
            var parent = new MixinConfiguration(new ClassContextCollection(ClassContextObjectMother.Create(typeof(string))));

            var builder = new MixinConfigurationBuilder(parent);

            Assert.That(builder.ParentConfiguration, Is.SameAs(parent));
            Assert.That(builder.ClassContextBuilders, Is.Empty);

            MixinConfiguration configuration = builder.BuildConfiguration();

            Assert.That(configuration.ClassContexts.Count, Is.EqualTo(1));
            Assert.That(configuration.ClassContexts.ContainsWithInheritance(typeof(string)), Is.True);
        }
        /// <summary>
        /// Analyzes the information added so far to this builder and creates a new <see cref="MixinConfiguration"/> from that data.
        /// </summary>
        /// <returns>An <see cref="MixinConfiguration"/> derived from the configuration specified in the builder's constructor containing
        /// <see cref="ClassContext"/> and <see cref="MixinContext"/> objects based on the information added so far.</returns>
        public MixinConfiguration BuildConfiguration()
        {
            s_log.InfoFormat("Building mixin configuration from {0} types.", _allTypes.Count);

            using (StopwatchScope.CreateScope(s_log, LogLevel.Info, "Time needed to build mixin configuration: {elapsed}."))
            {
                var typeAnalyzers     = new IMixinDeclarationAnalyzer <Type>[] { CreateAttributeAnalyzer <Type>(), new HasComposedInterfaceMarkerAnalyzer() };
                var assemblyAnalyzers = new IMixinDeclarationAnalyzer <Assembly>[] { CreateAttributeAnalyzer <Assembly> () };

                var configurationAnalyzer = new DeclarativeConfigurationAnalyzer(typeAnalyzers, assemblyAnalyzers);

                var configurationBuilder = new MixinConfigurationBuilder(_parentConfiguration);
                configurationAnalyzer.Analyze(_allTypes, configurationBuilder);
                return(configurationBuilder.BuildConfiguration());
            }
        }
Exemplo n.º 24
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.º 25
0
        public void Analyze(Type type, MixinConfigurationBuilder configurationBuilder)
        {
            ArgumentUtility.CheckNotNull("type", type);
            ArgumentUtility.CheckNotNull("configurationBuilder", configurationBuilder);

            var composedInterfaceMarkers = (from ifc in type.GetInterfaces()
                                            where ifc.IsGenericType
                                            let genericTypeDef = ifc.GetGenericTypeDefinition()
                                                                 where genericTypeDef == typeof(IHasComposedInterface <>)
                                                                 let composedInterface = ifc.GetGenericArguments().Single()
                                                                                         where !composedInterface.ContainsGenericParameters
                                                                                         select composedInterface).ToArray();

            if (composedInterfaceMarkers.Length > 0)
            {
                configurationBuilder.ForClass(type).AddComposedInterfaces(composedInterfaceMarkers);
            }
        }
Exemplo n.º 26
0
        public void Analyze(IEnumerable <Type> types, MixinConfigurationBuilder configurationBuilder)
        {
            ArgumentUtility.CheckNotNull("types", types);
            ArgumentUtility.CheckNotNull("configurationBuilder", configurationBuilder);

            var assemblies = new HashSet <Assembly>();

            foreach (var type in types)
            {
                AnalyzeType(configurationBuilder, type);

                if (!assemblies.Contains(type.Assembly))
                {
                    assemblies.Add(type.Assembly);
                    AnalyzeAssembly(configurationBuilder, type.Assembly);
                }
            }
        }
Exemplo n.º 27
0
        public void BuildFrom()
        {
            MixinConfiguration previousConfiguration = MixinConfiguration.ActiveConfiguration;
            MixinConfiguration parentConfiguration   = new MixinConfigurationBuilder(null)
                                                       .ForClass <BaseType2>().AddMixin(typeof(BT2Mixin1)).BuildConfiguration();

            Assert.That(MixinConfiguration.ActiveConfiguration.ClassContexts.ContainsWithInheritance(typeof(BaseType1)), Is.True);
            using (MixinConfiguration.BuildFrom(parentConfiguration).ForClass <BaseType7> ().AddMixin <BT7Mixin0> ().EnterScope())
            {
                Assert.That(MixinConfiguration.ActiveConfiguration, Is.Not.SameAs(previousConfiguration));
                Assert.That(MixinConfiguration.ActiveConfiguration, Is.Not.SameAs(parentConfiguration));
                Assert.That(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType7)), Is.Not.Null);
                Assert.That(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType7)).Mixins.ContainsKey(typeof(BT7Mixin0)), Is.True);
                Assert.That(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType1)), Is.Null);
                Assert.That(MixinConfiguration.ActiveConfiguration.GetContext(typeof(BaseType2)), Is.Not.Null);
            }
            Assert.That(MixinConfiguration.ActiveConfiguration, Is.SameAs(previousConfiguration));
        }
Exemplo n.º 28
0
        protected void Apply(
            MixinConfigurationBuilder configurationBuilder,
            MixinKind mixinKind,
            Type targetType,
            Type mixinType,
            MixinContextOrigin origin)
        {
            ArgumentUtility.CheckNotNull("targetType", targetType);
            ArgumentUtility.CheckNotNull("mixinType", mixinType);
            ArgumentUtility.CheckNotNull("origin", origin);

            try
            {
                configurationBuilder.AddMixinToClass(
                    mixinKind, targetType, mixinType, IntroducedMemberVisibility, AdditionalDependencies, SuppressedMixins, origin);
            }
            catch (Exception ex)
            {
                throw new ConfigurationException(ex.Message, ex);
            }
        }
Exemplo n.º 29
0
        public void ClassContextInheritance_WithOverrides_FromSameConfiguration()
        {
            MixinConfiguration configuration = new MixinConfigurationBuilder(null)
                                               .ForClass(typeof(NullTarget)).AddMixin(typeof(NullMixin))
                                               .ForClass(typeof(GenericTargetClass <>)).AddMixin(typeof(NullMixin))
                                               .ForClass <DerivedNullTarget> ().AddMixin(typeof(DerivedNullMixin))
                                               .ForClass <GenericTargetClass <int> > ().AddMixin(typeof(DerivedNullMixin))
                                               .BuildConfiguration();

            ClassContext derivedContext1 = configuration.GetContext(typeof(DerivedNullTarget));

            Assert.That(derivedContext1.Mixins.Count, Is.EqualTo(1));
            Assert.That(derivedContext1.Mixins.ContainsKey(typeof(DerivedNullMixin)), Is.True);
            Assert.That(derivedContext1.Mixins.ContainsKey(typeof(NullMixin)), Is.False);

            ClassContext derivedContext2 = configuration.GetContext(typeof(GenericTargetClass <int>));

            Assert.That(derivedContext2.Mixins.Count, Is.EqualTo(1));
            Assert.That(derivedContext2.Mixins.ContainsKey(typeof(DerivedNullMixin)), Is.True);
            Assert.That(derivedContext2.Mixins.ContainsKey(typeof(NullMixin)), Is.False);
        }
Exemplo n.º 30
0
 public void SetUp()
 {
     _mockRepository           = new MockRepository();
     _configurationBuilderMock = _mockRepository.StrictMock <MixinConfigurationBuilder>((MixinConfiguration)null);
 }