Documentation

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 RealNames plugin.

The Ageof the Personshould be somewhere between 10 and 32.

When the property City gets filled the MnemonicString plugin shall be used.

The property Streetin the Address shall be ignored .

Quite a lot. But it works! Try it out!

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();
  }
}