People who uses the ObjectFiller.NET asked me very often, is it also possible to use the data generators from the ObjectFiller.NET in a easy way for generating simple types like integer or double? Now you can do it, thanks to the static class Randomizer<T>. You can use it like that:

public int GiveMeSomeRandomInt()
        {
            return Randomizer<int>.Create();
        }

This will create a random integer. This will work with all types (like int, string, double, bool, etc...). Its also possible to generate a complex types, like an Address. The Randomizer<T> uses always the default data generators of the ObjectFiller.NET.

But you can also customize the usage of the Randomizer<T> with the same plugins which you can use for the ObjectFiller. For example you can do something like that:

public int GiveMeSomeRandomIntBetween100And200()
        {
            return Randomizer<int>.Create(new IntRange(100, 200));
        }

It will use the IntRange plugin and returns an integer between 100 and 200.

Here is another example where the Randomizer generates a random string based on the Lipsum plugin:

public string GiveMeSomeRandomLoremIpsumText()
        {
            return Randomizer<string>.Create(new Lipsum(LipsumFlavor.LoremIpsum));
        }

You are also able to specifiy a count of objects to create. The following example will generate 100 strings based on the CityName plugin.

IEnumerable<string> cityNames = Randomizer<string>.Create(new CityName(), 100);

You can also use a predefined FillerSetup with the method Create in the static Randomizer class. Read more about in the chapter Export and reuse Setup

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