public void StaticSelectConstructor_MultipleConstructors_ReturnNull()
        {
            //ARRANGE
            Type type     = typeof(MultipleConstructorsClass);
            var  resolver = new ConstructorResolverCache(new BestMatchConstructorResolver());

            //ACT
            var staticSelectedConstructor = resolver.StaticSelectConstructor(type);

            //ASSERT
            Assert.Null(staticSelectedConstructor);
        }
        public void SelectConstructor_MultipleConstructors_Throws()
        {
            Type type     = typeof(MultipleConstructorsClass);
            var  resolver = new ConstructorResolverCache(new DefaultConstructorResolver());

            Assert.Throws <CannotAutoResolveConstructorException>(() =>
            {
                resolver.StaticSelectConstructor(type);
            });

            Assert.Throws <CannotAutoResolveConstructorException>(() =>
            {
                resolver.StaticSelectConstructor(type);
            });
        }
        public void SelectConstructor_SingleConstructor_NoConstructors_Throws()
        {
            Type type     = typeof(NoPublicConstructorClass);
            var  resolver = new ConstructorResolverCache(new DefaultConstructorResolver());

            Assert.Throws <NoConstructorException>(() =>
            {
                resolver.StaticSelectConstructor(type);
            });

            Assert.Throws <NoConstructorException>(() =>
            {
                resolver.StaticSelectConstructor(type);
            });
        }
        public void DynamicSelectConstructor_MultipleConstructors_NotRegisteredArgument_PicksConstructorWithMostArgumentsThatCanBeResolved()
        {
            //ARRANGE
            Type type      = typeof(MultipleConstructorsClass);
            var  resolver  = new ConstructorResolverCache(new BestMatchConstructorResolver());
            var  container = new Container(b =>
            {
            });

            //ACT
            var dynamicSelectedConstructor = resolver.DynamicSelectConstructor(type, container.DependencyGraph);

            //ASSERT
            Assert.NotNull(dynamicSelectedConstructor);
            Assert.Empty(dynamicSelectedConstructor.GetParameters());
        }
        public void StaticSelectConstructor_SingleConstructor_NoConstructors_Throws()
        {
            //ARRANGE
            Type type     = typeof(NoPublicConstructorClass);
            var  resolver = new ConstructorResolverCache(new BestMatchConstructorResolver());

            //ACT
            //ASSERT
            Assert.Throws <NoConstructorException>(() =>
            {
                resolver.StaticSelectConstructor(type);
            });

            Assert.Throws <NoConstructorException>(() =>
            {
                resolver.StaticSelectConstructor(type);
            });
        }
        public void DynamicSelectConstructor_MultipleConstructors_RegisteredArgument_PicksConstructorWithMostArgumentsThatCanBeResolved()
        {
            //ARRANGE
            Type type      = typeof(MultipleConstructorsClass);
            var  resolver  = new ConstructorResolverCache(new BestMatchConstructorResolver());
            var  container = new Container(b =>
            {
                b.Register <ITestService10, TestService10>();
            });

            //ACT
            var dynamicSelectedConstructor = resolver.DynamicSelectConstructor(type, container.DependencyGraph);

            //ASSERT
            Assert.NotNull(dynamicSelectedConstructor);
            var parameter = Assert.Single(dynamicSelectedConstructor.GetParameters());

            Assert.Equal(typeof(ITestService10), parameter.ParameterType);
        }