public void SetUp()
        {
            _classContextBuilderWithParent = new ClassContextBuilder(typeof(NullTarget));
            _classContextBuilderWithParent.AddMixin(typeof(NullMixin2));
            _parentContextWithBuilder = ClassContextObjectMother.Create(typeof(NullTarget), typeof(NullMixin));

            _classContextBuilderWithIndirectParent = new ClassContextBuilder(typeof(DerivedNullTarget));

            _classContextBuilderWithoutParent = new ClassContextBuilder(typeof(BaseType4));
            _classContextBuilderWithParent.AddMixin(typeof(BT4Mixin1));

            _buildersWithParentContexts = new Dictionary <Type, Tuple <ClassContextBuilder, ClassContext> > ();
            _buildersWithParentContexts.Add(_classContextBuilderWithParent.TargetType, Tuple.Create(_classContextBuilderWithParent, _parentContextWithBuilder));
            _buildersWithParentContexts.Add(_classContextBuilderWithoutParent.TargetType, Tuple.Create(_classContextBuilderWithoutParent, (ClassContext)null));

            _parentContextWithoutBuilder = ClassContextObjectMother.Create(typeof(BaseType1));
            _parentContexts = new ClassContextCollection(_parentContextWithoutBuilder, _parentContextWithBuilder);

            _inheritancePolicyMock = MockRepository.GenerateMock <IMixinInheritancePolicy> ();
            _inheritedContext      = ClassContextObjectMother.Create(typeof(object), typeof(NullMixin));

            var classContextBuilders = new[] { _classContextBuilderWithoutParent, _classContextBuilderWithIndirectParent, _classContextBuilderWithParent };

            _builder = new InheritanceResolvingClassContextBuilder(classContextBuilders, _parentContexts, _inheritancePolicyMock);
        }
コード例 #2
0
        public void GetWithInheritance_Simple()
        {
            var collection = new ClassContextCollection(_ccObjectWithMixin, _ccString, _ccListOfT, _ccListOfString);

            Assert.That(collection.GetWithInheritance(typeof(object)), Is.SameAs(_ccObjectWithMixin));
            Assert.That(collection.GetWithInheritance(typeof(string)), Is.SameAs(_ccString));
            Assert.That(collection.GetWithInheritance(typeof(List <>)), Is.SameAs(_ccListOfT));
            Assert.That(collection.GetWithInheritance(typeof(List <string>)), Is.SameAs(_ccListOfString));
        }
コード例 #3
0
        public void SetUp()
        {
            _ccObjectWithMixin             = ClassContextObjectMother.Create(typeof(object), typeof(NullMixin2));
            _ccString                      = ClassContextObjectMother.Create(typeof(string));
            _collectionWithObjectAndString = new ClassContextCollection(_ccObjectWithMixin, _ccString);

            _ccListOfT      = ClassContextObjectMother.Create(typeof(List <>));
            _ccListOfString = ClassContextObjectMother.Create(typeof(List <string>));

            _emptyCollection = new ClassContextCollection();
        }
コード例 #4
0
        public void GetExact()
        {
            var collection = new ClassContextCollection(_ccObjectWithMixin, _ccString, _ccListOfT, _ccListOfString);

            Assert.That(collection.GetExact(typeof(object)), Is.SameAs(_ccObjectWithMixin));
            Assert.That(collection.GetExact(typeof(string)), Is.SameAs(_ccString));
            Assert.That(collection.GetExact(typeof(int)), Is.Null);
            Assert.That(collection.GetExact(typeof(List <>)), Is.SameAs(_ccListOfT));
            Assert.That(collection.GetExact(typeof(List <int>)), Is.Null);
            Assert.That(collection.GetExact(typeof(List <string>)), Is.SameAs(_ccListOfString));
        }
コード例 #5
0
        public void ContainsExact()
        {
            var collection = new ClassContextCollection(_ccObjectWithMixin, _ccString, _ccListOfT, _ccListOfString);

            Assert.That(collection.ContainsExact(typeof(object)), Is.True);
            Assert.That(collection.ContainsExact(typeof(string)), Is.True);
            Assert.That(collection.ContainsExact(typeof(int)), Is.False);
            Assert.That(collection.ContainsExact(typeof(List <>)), Is.True);
            Assert.That(collection.ContainsExact(typeof(List <int>)), Is.False);
            Assert.That(collection.ContainsExact(typeof(List <string>)), Is.True);
        }
コード例 #6
0
        public void GetWithInheritance_Inheritance_FromInterface()
        {
            var classContext = ClassContextObjectMother.Create(typeof(IMixedInterface), typeof(NullMixin), typeof(NullMixin2));
            var collection   = new ClassContextCollection(classContext);

            ClassContext inherited = collection.GetWithInheritance(typeof(ClassWithMixedInterface));

            Assert.That(inherited, Is.Not.Null);
            Assert.That(inherited.Type, Is.EqualTo(typeof(ClassWithMixedInterface)));
            Assert.That(inherited.Mixins.ContainsKey(typeof(NullMixin)), Is.True);
            Assert.That(inherited.Mixins.ContainsKey(typeof(NullMixin2)), Is.True);
        }
コード例 #7
0
        public void GetWithInheritance_Inheritance_FromGenericTypeDefinition()
        {
            var classContext1 = ClassContextObjectMother.Create(typeof(List <>), typeof(NullMixin3));
            var classContext2 = ClassContextObjectMother.Create(typeof(List <string>), typeof(NullMixin4));

            var collection = new ClassContextCollection(classContext1, classContext2);

            ClassContext inherited4 = collection.GetWithInheritance(typeof(List <int>));

            Assert.That(inherited4, Is.Not.Null);
            Assert.That(inherited4.Type, Is.EqualTo(typeof(List <int>)));
            Assert.That(inherited4.Mixins.ContainsKey(typeof(NullMixin3)), Is.True);
            Assert.That(inherited4.Mixins.ContainsKey(typeof(NullMixin4)), Is.False);
        }
コード例 #8
0
        public void SetUp()
        {
            _configuredClassContext1 = ClassContextObjectMother.Create(typeof(BaseType1), typeof(NullMixin));
            _configuredClassContext2 = ClassContextObjectMother.Create(typeof(NullTarget), typeof(NullMixin));
            _genericClassContext     = ClassContextObjectMother.Create(typeof(GenericTargetClass <>), typeof(NullMixin));
            _interfaceClassContext   = ClassContextObjectMother.Create(typeof(IBaseType2), typeof(NullMixin));

            var classContexts = new ClassContextCollection(_configuredClassContext1, _configuredClassContext2, _genericClassContext, _interfaceClassContext);

            _configuration = new MixinConfiguration(classContexts);

            _configuredTypeDiscoveryServiceStub = CreateTypeDiscoveryServiceStub(
                _configuredClassContext1.Type,
                _configuredClassContext2.Type,
                _genericClassContext.Type,
                _interfaceClassContext.Type);
        }
コード例 #9
0
        /// <summary>
        /// Builds a configuration object with the data gathered so far.
        /// </summary>
        /// <returns>A new <see cref="MixinConfiguration"/> instance incorporating all the data acquired so far.</returns>
        public virtual MixinConfiguration BuildConfiguration()
        {
            using (StopwatchScope.CreateScope(s_log, LogLevel.Info, "Time needed to build mixin configuration from fluent builders: {elapsed}."))
            {
                var parentContexts = ParentConfiguration != null ? ParentConfiguration.ClassContexts : new ClassContextCollection();
                s_log.DebugFormat("Building a mixin configuration with {0} parent class contexts from fluent builders...", parentContexts.Count);

                var builder = new InheritanceResolvingClassContextBuilder(ClassContextBuilders, parentContexts, DefaultMixinInheritancePolicy.Instance);

                var allContexts            = builder.BuildAllAndCombineWithParentContexts();
                var classContextCollection = new ClassContextCollection(allContexts);
                return(new MixinConfiguration(classContextCollection)
                       .LogAndReturnValue(
                           s_log,
                           LogLevel.Info,
                           conf => string.Format("Built mixin configuration from fluent builders with {0} class contexts.", conf.ClassContexts.Count)));
            }
        }
コード例 #10
0
 /// <summary>
 /// Initializes a non-empty mixin configuration.
 /// </summary>
 /// <param name="classContexts">The class contexts to be held by this <see cref="MixinConfiguration"/>.</param>
 public MixinConfiguration(ClassContextCollection classContexts)
 {
     _classContexts = classContexts;
 }
コード例 #11
0
        public void Initialization_Enumerable()
        {
            var collection = new ClassContextCollection(((IEnumerable <ClassContext>) new[] { _ccObjectWithMixin, _ccString }));

            Assert.That(collection, Is.EquivalentTo(new[] { _ccObjectWithMixin, _ccString }));
        }
コード例 #12
0
        public void Initialization_ParamsArray()
        {
            var collection = new ClassContextCollection(_ccObjectWithMixin, _ccString);

            Assert.That(collection, Is.EquivalentTo(new[] { _ccObjectWithMixin, _ccString }));
        }