With SetupFor<T> you start a setup for another type. In the following example we define that the Name of the Person will be "John" and the City of an Address object will be a real city name, based on the CityName plugin.
SetupFor<T>
takes an bool parameter. If this is set to true
then all the settings which were made on the parent type will be set back to default.
When a property of the child object is not set up, then the filler will take the type setup of the parent object, except the settings which are made specially for this actual type.
public class Person
{
public string Name { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public DateTime Birthday { get; set; }
public Address Address { get; set; }
}
public class Address
{
public string Street { get; set; }
public string City { get; set; }
}
public class HelloFiller
{
public void FillPerson()
{
Filler<Person> pFiller = new Filler<Person>();
pFiller.Setup()
.OnProperty(x => x.Name).Use("John")
.SetupFor<Address>()
.OnProperty(x => x.City).Use(new CityName());
Person filledPerson = pFiller.Create();
}
}