public void PopulatePushesNestedInstanceIntoBuildChainWhileCreatingTest() { var office = new Office(); var address = new Address(); var testPassed = false; var creator = Substitute.For<ITypeCreator>(); var generator = Substitute.For<IValueGenerator>(); var buildStrategy = Substitute.For<IBuildStrategy>(); var target = new DefaultExecuteStrategy(); target.Initialize(buildStrategy, buildStrategy.GetBuildLog()); buildStrategy.CreationRules.Returns(new List<CreationRule>().AsReadOnly()); buildStrategy.ValueGenerators.Returns( new List<IValueGenerator> { generator }.AsReadOnly()); buildStrategy.TypeCreators.Returns( new List<ITypeCreator> { creator }.AsReadOnly()); creator.CanCreate(Arg.Any<Type>(), Arg.Any<string>(), Arg.Any<LinkedList<object>>()).Returns(true); creator.Create(typeof(Office), null, Arg.Any<LinkedList<object>>()).Returns(office); creator.Create(typeof(Address), "Address", Arg.Is<LinkedList<object>>(x => x.Last.Value == office)) .Returns(address); creator.AutoPopulate.Returns(true); generator.When( x => x.Generate( typeof(string), Arg.Any<string>(), Arg.Is<LinkedList<object>>(y => y.Last.Value == address))).Do( x => { target.BuildChain.Should().HaveCount(2); target.BuildChain.First.Value.Should().Be(office); target.BuildChain.Last.Value.Should().Be(address); testPassed = true; }); generator.IsSupported(typeof(string), Arg.Any<string>(), Arg.Any<LinkedList<object>>()).Returns(true); generator.Generate(typeof(string), Arg.Any<string>(), Arg.Any<LinkedList<object>>()) .Returns(Guid.NewGuid().ToString()); target.Create(typeof(Office)); testPassed.Should().BeTrue(); }