public void CanCreateReturnsFalseForInterface() { var type = typeof(ITestItem); var configuration = Substitute.For <IBuildConfiguration>(); var typeResolver = Substitute.For <ITypeResolver>(); var buildChain = Substitute.For <IBuildChain>(); configuration.TypeResolver.Returns(typeResolver); typeResolver.GetBuildType(configuration, type).Returns(type); var sut = new FactoryTypeCreator(CacheLevel.PerInstance); var actual = sut.CanCreate(configuration, buildChain, type); actual.Should().BeFalse(); }
public void CanCreateReturnsFalseWhenNoPublicConstructorFoundAndStaticMethodContainsTypeParameter() { var type = typeof(NotFactoryItem); 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 FactoryTypeCreator(CacheLevel.PerInstance); var actual = sut.CanCreate(configuration, buildChain, type); actual.Should().BeFalse(); }
public void CanCreateReturnsFalseWhenDefaultConstructorFound() { var type = typeof(TestItem); var constructorInfo = type.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 FactoryTypeCreator(CacheLevel.PerInstance); var actual = sut.CanCreate(configuration, buildChain, type); actual.Should().BeFalse(); }
public void CanCreateReturnsTrueWhenNoPublicConstructorAndStaticFactoryMethodExistsWithParameters() { var type = typeof(FactoryWithValue); 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 FactoryTypeCreator(CacheLevel.PerInstance); var actual = sut.CanCreate(configuration, buildChain, type); actual.Should().BeTrue(); }