public void CanCreateThrowsExceptionWithNullTypeTest()
        {
            var target = new DefaultTypeCreator();

            Action action = () => target.CanCreate(null, null, null);

            action.ShouldThrow<ArgumentNullException>();
        }
        public void CanCreateReturnsWhetherTypeCanBeCreatedTest(Type targetType, bool expected)
        {
            var target = new DefaultTypeCreator();

            var actual = target.CanCreate(targetType, null, null);

            actual.Should().Be(expected);
        }
예제 #3
0
        public void CanCreateReturnsWhetherTypeCanBeCreatedTest(Type targetType, bool expected)
        {
            var constructorInfo = targetType.GetConstructors().FirstOrDefault();

            var typeResolver        = Substitute.For <ITypeResolver>();
            var constructorResolver = Substitute.For <IConstructorResolver>();
            var configuration       = Substitute.For <IBuildConfiguration>();

            configuration.TypeResolver.Returns(typeResolver);
            configuration.ConstructorResolver.Returns(constructorResolver);
            typeResolver.GetBuildType(configuration, targetType).Returns(targetType);
            constructorResolver.Resolve(targetType, null).Returns(constructorInfo);

            var sut = new DefaultTypeCreator();

            var actual = sut.CanCreate(configuration, null !, targetType);

            actual.Should().Be(expected);
        }
        public void CanCreateReturnsTrueWhenTypeHasPublicConstructor()
        {
            var type            = typeof(Person);
            var constructorInfo = typeof(Person).GetConstructors().First();

            var configuration       = Substitute.For <IBuildConfiguration>();
            var typeResolver        = Substitute.For <ITypeResolver>();
            var constructorResolver = Substitute.For <IConstructorResolver>();
            var buildChain          = Substitute.For <IBuildChain>();

            configuration.TypeResolver.Returns(typeResolver);
            configuration.ConstructorResolver.Returns(constructorResolver);
            typeResolver.GetBuildType(configuration, type).Returns(type);
            constructorResolver.Resolve(type, Arg.Any <object?[]?>()).Returns(constructorInfo);

            var sut = new DefaultTypeCreator();

            var actual = sut.CanCreate(configuration, buildChain, type);

            actual.Should().BeTrue();
        }
        public void CanCreateReturnsFalseWhenNoPublicConstructorFound()
        {
            var             type            = typeof(FactoryItem);
            ConstructorInfo?constructorInfo = null;

            var configuration       = Substitute.For <IBuildConfiguration>();
            var typeResolver        = Substitute.For <ITypeResolver>();
            var constructorResolver = Substitute.For <IConstructorResolver>();
            var buildChain          = Substitute.For <IBuildChain>();

            configuration.TypeResolver.Returns(typeResolver);
            configuration.ConstructorResolver.Returns(constructorResolver);
            typeResolver.GetBuildType(configuration, type).Returns(type);
            constructorResolver.Resolve(type, Arg.Any <object?[]?>()).Returns(constructorInfo);

            var sut = new DefaultTypeCreator();

            var actual = sut.CanCreate(configuration, buildChain, type);

            actual.Should().BeFalse();
        }