Beispiel #1
0
        public void CanRegisterMultipleTypeMappings()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping <IFoo, Foo>();
            root.RegisterTypeMapping <IBar, Bar>();

            Assert.AreEqual(typeof(Bar), root.GetMappedType <IBar>());
            Assert.AreEqual(typeof(Foo), root.GetMappedType <IFoo>());
        }
Beispiel #2
0
        public void RequestingTypeMappingOnChildReadsFromParent()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            parent.RegisterTypeMapping <IFoo, Foo>();

            Assert.AreEqual(typeof(Foo), child.GetMappedType <IFoo>());
        }
Beispiel #3
0
        public void CanRegisterTypeMappingViaTypeObjects()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping(typeof(IFoo), typeof(Foo));

            Type mappedType = root.GetMappedType(typeof(IFoo));

            Assert.AreEqual(typeof(Foo), mappedType);
        }
Beispiel #4
0
        public void CanRegisterTypeMappingOnRootContainer()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping <IFoo, Foo>();

            Type mappedType = root.GetMappedType <IFoo>();

            Assert.AreEqual(typeof(Foo), mappedType);
        }
Beispiel #5
0
        public void ChildContainersCanOverrideParentTypeMapping()
        {
            TestableRootCompositionContainer parent = new TestableRootCompositionContainer();
            CompositionContainer             child  = parent.Containers.AddNew <CompositionContainer>();

            parent.RegisterTypeMapping <IFoo, Foo>();
            child.RegisterTypeMapping <IFoo, Foo2>();

            Assert.AreEqual(typeof(Foo), parent.GetMappedType <IFoo>());
            Assert.AreEqual(typeof(Foo2), child.GetMappedType <IFoo>());
        }
        public void PolicyShouldRequestTypeMappingFromContainer()
        {
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            container.RegisterTypeMapping <IFoo, Foo>();

            ContainerAwareTypeMappingPolicy policy = new ContainerAwareTypeMappingPolicy();

            string requestId = "My mapped object";
            DependencyResolutionLocatorKey requestKey =
                new DependencyResolutionLocatorKey(typeof(IFoo), requestId);
            DependencyResolutionLocatorKey result = policy.Map(container.Locator, requestKey);

            Assert.AreEqual(typeof(Foo), result.Type);
            Assert.AreEqual(requestId, result.ID);
        }
        public void PolicyCallsUpToParentContainerToGetMapping()
        {
            TestableRootCompositionContainer container = new TestableRootCompositionContainer();

            container.RegisterTypeMapping <IFoo, Foo>();
            CompositionContainer child = container.Containers.AddNew <CompositionContainer>();

            ContainerAwareTypeMappingPolicy policy = new ContainerAwareTypeMappingPolicy();

            string requestId = "My mapped object";
            DependencyResolutionLocatorKey requestKey =
                new DependencyResolutionLocatorKey(typeof(IFoo), requestId);
            DependencyResolutionLocatorKey result = policy.Map(child.Locator, requestKey);

            Assert.AreEqual(typeof(Foo), result.Type);
            Assert.AreEqual(requestId, result.ID);
        }
        public void StrategyShouldDoTypeMapping()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping <IFoo, Foo>();

            ContainerAwareTypeMappingStrategy strategy = new ContainerAwareTypeMappingStrategy();
            MockBuilderContext builderContext          =
                new MockBuilderContext(strategy, new ReturnRequestedTypeStrategy());

            builderContext.Policies.SetDefault <IContainerAwareTypeMappingPolicy>(
                new ContainerAwareTypeMappingPolicy());
            builderContext.Locator = root.Locator;

            object result = strategy.BuildUp(builderContext, typeof(IFoo), null, "Test object");
            DependencyResolutionLocatorKey key = result as DependencyResolutionLocatorKey;

            Assert.IsNotNull(key);
            Assert.AreEqual(typeof(Foo), key.Type);
        }
Beispiel #9
0
        public void TypeMappingsMustBeTypeCompatible()
        {
            TestableRootCompositionContainer root = new TestableRootCompositionContainer();

            root.RegisterTypeMapping(typeof(IBar), typeof(Foo));
        }