public void ReturnsFalseWhenAResolvableConstructorDoesNotExist()
            {
                var sut = new ResolverConstructorSelector();

                ConstructorInfo dummy;
                Assert.That(sut.TryGetConstructor(typeof(Class1), MockResolver.Object, out dummy), Is.False);
            }
            public void ReturnsTrueWhenAResolvableConstructorExists()
            {
                var sut = new ResolverConstructorSelector();

                ConstructorInfo dummy;
                Assert.That(sut.TryGetConstructor(typeof(Class5), MockResolver.Object, out dummy), Is.True);
            }
            public void ReturnsFalseIfTheTypeIsAbstract(Type abstractType)
            {
                var sut = new ResolverConstructorSelector();

                ConstructorInfo ctor;
                var result = sut.TryGetConstructor(abstractType, MockResolver.Object, out ctor);

                Assert.That(result, Is.False);
            }
            public void SetsTheOutParameterToNullWhenNoResolvableConstructorExists()
            {
                var sut = new ResolverConstructorSelector();

                ConstructorInfo ctor;
                sut.TryGetConstructor(typeof(Class1), MockResolver.Object, out ctor);

                Assert.That(ctor, Is.Null);
            }
            public void ChoosesTheResolvableConstructorWithTheMostParameters()
            {
                SetResolvable(typeof(IInterface1));
                SetResolvable(typeof(IInterface2));
                SetResolvable(typeof(IInterface3));

                var sut = new ResolverConstructorSelector();

                var ctor = sut.GetConstructor(typeof(Class2), MockResolver.Object);

                Assert.That(ctor.GetParameters().Length, Is.EqualTo(2));
            }
            public void ChoosesTheResolvableConstructorWhenThereAreMoreThanOnceResolvableConstructorsAndOnlyOneIsResolvable()
            {
                SetResolvable(typeof(IInterface1));
                SetResolvable(typeof(IInterface2));

                var sut = new ResolverConstructorSelector();

                ConstructorInfo ctor;
                sut.TryGetConstructor(typeof(Class1), MockResolver.Object, out ctor);

                Assert.That(ctor.GetParameters().All(p => MockResolver.Object.CanGet(p.ParameterType) || p.HasDefaultValue), Is.True);
            }
                public void TheConstructorWithTheFewestParametersWithDefaultValuesIsSelected()
                {
                    SetResolvable(typeof(IInterface1));
                    SetResolvable(typeof(IInterface2));
                    SetResolvable(typeof(IInterface3));
                    SetResolvable(typeof(IInterface4));

                    var sut = new ResolverConstructorSelector();

                    ConstructorInfo ctor;
                    sut.TryGetConstructor(typeof(Class4), MockResolver.Object, out ctor);

                    Assert.That(ctor.GetParameters().Select(p => p.ParameterType), Is.EquivalentTo(new[] { typeof(IInterface1), typeof(IInterface2) }));
                }
                public void IfNoParametersAreDefaultOnEitherReturnsFalse()
                {
                    SetResolvable(typeof(IInterface1));
                    SetResolvable(typeof(IInterface2));
                    SetResolvable(typeof(IInterface3));
                    SetResolvable(typeof(IInterface4));

                    var sut = new ResolverConstructorSelector();

                    ConstructorInfo dummy;
                    Assert.That(sut.TryGetConstructor(typeof(Class1), MockResolver.Object, out dummy), Is.False);
                }
            public void NeverSelectsAConstructorWithANonDefaultPrimitivishParameter()
            {
                SetResolvable(typeof(IInterface1));
                SetResolvable(typeof(IInterface2));
                SetResolvable(typeof(IInterface3));

                var sut = new ResolverConstructorSelector();

                var ctor = sut.GetConstructor(typeof(Class3), MockResolver.Object);

                Assert.That(ctor.GetParameters().Length, Is.EqualTo(1));
            }