public void CreateReturnsValueWithoutCache() { var type = typeof(FactoryItem); ConstructorInfo?constructorInfo = null; var parameters = Array.Empty <object>(); var executeStrategy = Substitute.For <IExecuteStrategy>(); var configuration = Substitute.For <IBuildConfiguration>(); var typeResolver = Substitute.For <ITypeResolver>(); var constructorResolver = Substitute.For <IConstructorResolver>(); var buildChain = Substitute.For <IBuildChain>(); executeStrategy.Configuration.Returns(configuration); executeStrategy.BuildChain.Returns(buildChain); configuration.TypeResolver.Returns(typeResolver); configuration.ConstructorResolver.Returns(constructorResolver); typeResolver.GetBuildType(configuration, type).Returns(type); constructorResolver.Resolve(type, Arg.Any <object?[]?>()).Returns(constructorInfo); executeStrategy.CreateParameters(Arg.Any <MethodInfo>()).Returns(parameters); var sut = new FactoryTypeCreator(CacheLevel.None); var actual = sut.Create(executeStrategy, type); actual.Should().BeOfType <FactoryItem>(); actual.As <FactoryItem>().Value.Should().NotBeEmpty(); }
public void CreateReturnsValueFromFactoryWithProvidedParameters() { var type = typeof(FactoryWithValue); ConstructorInfo?constructorInfo = null; var parameters = new object[] { Guid.NewGuid() }; var executeStrategy = Substitute.For <IExecuteStrategy>(); var configuration = Substitute.For <IBuildConfiguration>(); var typeResolver = Substitute.For <ITypeResolver>(); var constructorResolver = Substitute.For <IConstructorResolver>(); var buildChain = Substitute.For <IBuildChain>(); executeStrategy.Configuration.Returns(configuration); executeStrategy.BuildChain.Returns(buildChain); 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.Create(executeStrategy, type, parameters); actual.Should().BeOfType <FactoryWithValue>(); actual.As <FactoryWithValue>().Value.Should().Be((Guid)parameters[0]); }