Complex Example

Now let us mix all up! What happens here? Well, we say: Ok ObjectFiller, the IAddress interface will be implemented by the Address class. The Name and LastName of a person will be generated by the RealNamesPlugin. The age of the person should be somewhere between 10 and 32. When you generate a city use the MnemonicStringPlugin and finally ignore the Street in the Address. Quite a lot. But it works!

public class Person
{
  public Person(IAddress address)
  {
    Address = address;
  }
  public string Name { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  public DateTime Birthday { get; set; }
  public IAddress Address { get; set; }

  public Dictionary<string, List<Address>>
    SenselessDictionary
  { get; set; }

  public List<IAddress> SenselessList { get; set; }
}

public class Address : IAddress
{
  public string Street { get; set; }
  public string City { get; set; }
}

public interface IAddress { }

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnType<IAddress>()
      .CreateInstanceOf<Address>()
      .OnProperty(p => p.LastName, p => p.Name)
      .Use(new RealNames(NameStyle.FirstName))
      .OnProperty(p => p.Age)
      .Use(() => new Random().Next(10, 32))
      .SetupFor<Address>()
      .OnProperty(p => p.City)
      .Use(new MnemonicString(1))
      .OnProperty(x => x.Street).IgnoreIt();

    Person filledPerson = pFiller.Create();
  }
}