Пример #1
0
        public void MultipleContainersCanExist()
        {
            // Get the containers
            var containerA = CommonProvider.Container;
            var containerB = new CommonContainer();

            // Register the same type for both containers with different implementations
            var t = typeof(TestClassBase);
            containerA.Register(t, typeof(TestClass));
            containerB.Register(t,
                                (Func<object[], object>)PrivateTestClass.CreateInstanceWithParams);

            // Build our instances
            var instanceA = containerA.Provide<TestClassBase>(35);
            var instanceB = containerB.Provide<TestClassBase>(1, 1);

            // Assert we have different strokes for different folks
            containerA.ShouldNotBeSameAs(containerB);
            instanceA.ShouldNotBeSameAs(instanceB);

            instanceA.ShouldNotBeNull("A was null");
            instanceB.ShouldNotBeNull("B was null");

            instanceA.ShouldBeOfType<TestClass>("A was not expected type");
            instanceB.ShouldBeOfType<PrivateTestClass>("B was not expected type");
        }
Пример #2
0
        public void ContainersCanGetMappingsFromTheirParent()
        {
            // Get the containers
            var parent = CommonProvider.Container;
            var child = new CommonContainer(parent);

            // Register the same type for both containers with different implementations
            var t = typeof(TestClassBase);
            parent.Register(t, typeof(TestClass));

            // Build our instances
            var instance = child.Provide<TestClassBase>();

            // Check that the item was provided
            instance.ShouldNotBeNull();
        }