Пример #1
0
        public void SelectConstructor_raises_exception_when_only_ambiguous_constructors_found()
        {
            // Arrange
            var sut = new ConstructorWithMostParametersSelector();

            // Act & assert
            Assert.That(() => sut.SelectConstructor(typeof(SampleServiceWithAmbiguousCtors)),
                        Throws.TypeOf <AmbiguousConstructorException>());
        }
Пример #2
0
        public void SelectConstructor_raises_exception_when_no_public_constructors_found()
        {
            // Arrange
            var sut = new ConstructorWithMostParametersSelector();

            // Act & assert
            Assert.That(() => sut.SelectConstructor(typeof(SampleServiceWithOnlyPrivateConstructors)),
                        Throws.TypeOf <CannotInstantiateTypeWithoutAnyConstructorsException>());
        }
Пример #3
0
        public void SelectConstructor_can_use_private_constructor_when_configured_for_it()
        {
            // Arrange
            var sut = new ConstructorWithMostParametersSelector(true);
            var expectedParamNames = new [] { "one", "two", "intOne" };

            // Act
            var result = sut.SelectConstructor(typeof(SampleServiceWithAmbiguousCtors));

            // Assert
            Assert.That(result, Is.Not.Null);
            var actualParamNames = result.GetParameters().Select(x => x.Name).ToArray();

            Assert.That(actualParamNames, Is.EqualTo(expectedParamNames));
        }
Пример #4
0
        public void SelectConstructor_gets_correct_public_constructor()
        {
            // Arrange
            var sut = new ConstructorWithMostParametersSelector();
            var expectedParamNames = new [] { "one", "two", "intOne" };

            // Act
            var result = sut.SelectConstructor(typeof(SampleServiceWithConstructorParameters));

            // Assert
            Assert.That(result, Is.Not.Null);
            var actualParamNames = result.GetParameters().Select(x => x.Name).ToArray();

            Assert.That(actualParamNames, Is.EqualTo(expectedParamNames));
        }