With
.Setup()
you start configure the ObjectFiller. With OnType<T>()
you define which type will be configured and with .Use( ... )
you define what the ObjectFiller.NET should do with the type.
You are able to write your own .Func<T>()
, implement your own IRandomizerPlugin<T>
, use a fixed value or you just use one of the provided plugins ObjectFiller.NET comes with.
The ObjectFiller.NET is very flexible and easy to extend! In this example we say to the ObjectFiller: Hey ObjectFiller, whenever there will be a property of type string, just fill it with the word "SomeString". And when there is a DateTime set it always to 1.4.2014! Easy! Isn't it?
public class Person
{
public string Name { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public DateTime Birthday { get; set; }
}
public class HelloFiller
{
public void FillPerson()
{
Filler<Person> pFiller = new Filler<Person>();
pFiller.Setup()
.OnType<string>().Use("SomeString")
.OnType<DateTime>().Use(new DateTime(2014, 4, 1));
Person p = pFiller.Create();
}
}
The object Person which will be created will have the Name and LastName filled with the fixed word "SomeString". The Age will be some random number. The Birthdate of the person will be of the fixed value 01.04.2014.