Documentation

The following example shows how to save the setup of ObjectFiller.NET. In the fluent setup API you can call the Property .Result which holds the setup of your ObjectFiller.NET configuration.

In the example the .Result of the filler setup is saved to a private field with the name "_fillerSetup". This setup is then reused in the method FillPerson() by calling .Setup(_fillerSetup) with the setup of this private field!

This is really good if you want to reuse your setup at another place.

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
{
  private FillerSetup _fillerSetup;
  
  public HelloFiller()
  {
    Filler<Person> pFiller = new Filler<Person>();

    _fillerSetup = pFiller.Setup()
    .OnProperty(x => x.LastName).Use("Miller")
    .OnProperty(x => x.Name).Use("John")
    .OnType<int>().Use(new IntRange(18, 75))
    .Result;
  }
  
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup(_fillerSetup);

    Person filledPerson = pFiller.Create();
  }
}

Another way to create reusable setups is the Create method of the static FillerSetup class.
In this case you do not need a specific ´Filler` when setting up the configuration. Fillersetups can also be used with the Randomizer .

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
{
  private FillerSetup _fillerSetup;

  public HelloFiller()
  {
    var setup = FillerSetup.Create<Person>();
    _fillerSetup = setup.OnProperty(x => x.LastName).Use("Miller")
      .OnProperty(x => x.Name).Use("John")
      .OnType<int>().Use(new IntRange(18, 75))
      .Result;
  }

  public void FillPerson()
  {
    Person filledPerson = Randomizer<Person>.Create(_fillerSetup);
  }
}