コード例 #1
0
        public void Register_InterfaceRegisteredToDifferentType_ThrowArgumentException()
        {
            var interfaceType        = typeof(ITestedInterface);
            var firstInheritingType  = typeof(TestedInheritingClass);
            var secondInheritingType = typeof(TestedOtherInheritingClass);
            var registry             = new DependancyRegistry();

            registry.Register(interfaceType, firstInheritingType);

            void testAction() => registry.Register(interfaceType, secondInheritingType);

            Assert.ThrowsException <ArgumentException>(testAction);
        }
コード例 #2
0
        public void Instanciate_InterfaceIsRegistered_ReturnsNewImplementation()
        {
            var registry = new DependancyRegistry();

            registry.Register(typeof(ITestedInterface), typeof(TestedInheritingClass));

            var instance = registry.Instantiate <ITestedInterface>();

            Assert.IsTrue(instance is TestedInheritingClass);
        }
コード例 #3
0
        public void Register_InterfaceWithNonInheritingClass_ThrowArgumentException()
        {
            var interfaceType     = typeof(ITestedInterface);
            var nonInheritingType = typeof(TestedNonInheritingClass);
            var registry          = new DependancyRegistry();

            void testAction() => registry.Register(interfaceType, nonInheritingType);

            Assert.ThrowsException <ArgumentException>(testAction);
        }
コード例 #4
0
        public void Register_InterfaceWithInheritingClass_AddsToRegistry()
        {
            var interfaceType  = typeof(ITestedInterface);
            var inheritingType = typeof(TestedInheritingClass);
            var registry       = new DependancyRegistry();

            registry.Register(interfaceType, inheritingType);

            Assert.IsTrue(registry.Clone().ContainsKey(interfaceType));
        }