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>()); }
public void CanRegisterTypeMappingOnRootContainer() { TestableRootCompositionContainer root = new TestableRootCompositionContainer(); root.RegisterTypeMapping<IFoo, Foo>(); Type mappedType = root.GetMappedType<IFoo>(); Assert.AreEqual(typeof (Foo), mappedType); }
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); }
public void CanRegisterTypeMappingViaTypeObjects() { TestableRootCompositionContainer root = new TestableRootCompositionContainer(); root.RegisterTypeMapping(typeof (IFoo), typeof (Foo)); Type mappedType = root.GetMappedType(typeof (IFoo)); Assert.AreEqual(typeof (Foo), mappedType); }
public void TypeMappingsMustBeTypeCompatible() { TestableRootCompositionContainer root = new TestableRootCompositionContainer(); root.RegisterTypeMapping(typeof (IBar), typeof (Foo)); }
public void RequestingTypeMappingOnChildReadsFromParent() { TestableRootCompositionContainer parent = new TestableRootCompositionContainer(); CompositionContainer child = parent.Containers.AddNew<CompositionContainer>(); parent.RegisterTypeMapping<IFoo, Foo>(); Assert.AreEqual(typeof (Foo), child.GetMappedType<IFoo>()); }
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>()); }