ObjectFiller.NET

Welcome to the ObjectFiller.NET developer hub. You'll find comprehensive guides and documentation to help you start working with ObjectFiller.NET as quickly as possible, as well as support if you get stuck. Let's jump right in!

Get Started    Welcome
Suggest Edits

Starting Setup

 

The ObjectFiller.NET has a fluent setup API. With that Setup API you are able to configure the ObjectFiller.NET very detailed. It is possible to configure how the ObjectFiller will handle concrete types or properties. You are also able to save and reuse setups.
The following chapters will show you the power of the fluent ObjectFiller.NET API.

The setup API can be started by calling the .Setup() method:

Filler<AnyType> pFiller = new Filler<AnyType>();
pFiller.Setup()...;   
AnyType filledObject = pFiller.Create();
Suggest Edits

Setup for Types

 
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.

Documentation

To setup a type you have to start the fluent API of ObjectFiller.NET. To do that .Setup() have to be called first.
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?

Suggest Edits

Setup for Sub-Types

 
public class Person
{
  public string Name { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  public DateTime Birthday { get; set; }
  public Address Address { get; set; }

}

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

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnProperty(x => x.Name).Use("John")
      .SetupFor<Address>()
      .OnProperty(x => x.City).Use(new CityName());

    Person filledPerson = pFiller.Create();
  }
}

Documentation

With SetupFor<T> you start a setup for another type. In the following example we define that the Name of the Person will be "John" and the City of an Address object will be a real city name, based on the CityName plugin.

SetupFor<T> takes an bool parameter. If this is set to true then all the settings which were made on the parent type will be set back to default.

When a property of the child object is not set up, then the filler will take the type setup of the parent object, except the settings which are made specially for this actual type.

Suggest Edits

Setup for Properties

 
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()
      .OnProperty(p => p.Name).Use("John")
      .OnProperty(p => p.LastName).Use(new RealNames(NameStyle.LastName));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

The setup for a property works very equal to the setup of a type. After we called .Setup() on the ObjectFiller.NET we can configure a property of the target object by calling .OnProperty(x=>x.Property).

In the following example we setup the property Name of the class Person to have the value "John" and fill the property LastName with some random real last name.

With .Use(new RealNames(NameStyle.LastName); we use the RealNames plugin.
The RealNames plugin is a plugin which comes with the ObjectFiller.NET assembly along.
You can use the plugins for types as well as for properties.

It is also really easy to write a plugin by yourself. You can read more about it in the chapter "Extend ObjectFiller.NET" .

Suggest Edits

Set random seed

 
public class Address
{
  public string Street { get; set; }
  public string PostalCode { get; set; }
  public string City { get; set; }
  public string Country { get; set; }
  public int HouseNumber { get; set; }
}        

[TestMethod]
public void SetRandomSeedShallGenerateSameData()
{
  var filler = new Filler<Address>();
  var address1 = filler.SetRandomSeed(1234).Create();

  var filler2 = new Filler<Address>();
  var address2 = filler2.SetRandomSeed(1234).Create();

  Assert.AreEqual(address1.City, address2.City);
  Assert.AreEqual(address1.Country, address2.Country);
  Assert.AreEqual(address1.HouseNumber, address2.HouseNumber);
  Assert.AreEqual(address1.PostalCode, address2.PostalCode);
  Assert.AreEqual(address1.Street, address2.Street);
}

Documentation

Did you ever played Minecraft? When you start a new world, you can choose a random number to generate the world. If you generate a new world and you take the same number again, the world will be also the same.
In ObjectFiller you also have this random seed number.
Sometimes you want to have random data, but always the same random data. You asking why? For example if you are using ObjectFiller.NET to generate mocked data for a distributed webservice. Imagine you have two webservices, which are round robbin distributed and each of them generates some random testdata with objectfiller. If you make your first api request you get data for the first webservice and random data from there. If you make your second api request you get data for the second webservice but with different random data.
With .SetRandomSeed(int seed) you can make objectfiller generate random data, but always the same if you choose the same integer value as seed.

Suggest Edits

Explicit 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
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup(true)
      .OnProperty(x=>x.LastName).Use<RealNames>();

    Person filledPerson = pFiller.Create();
  }
}

Documentation

When you call the .Setup(true) method, it will just fill properties which was explicit configured.
This is useful if you want to take full control about the object generation.

In the following example all properties gets ignored by the ObjectFiller.NET except the LastName property. This is because the Filler-Setup is called with parameter true which starts the Setup in explicit mode, so every property have to be configured explicit.

Suggest Edits

Ignore Properties/Types

 
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()
      .OnProperty(x=>x.LastName, x=>x.Name).IgnoreIt()
      .OnType<DateTime>().IgnoreIt();

    Person filledPerson = pFiller.Create();
  }
}

Documentation

Sometimes it is necessary that the ObjectFiller should NOT create or fill a property or type.
For example when it gets set from the constructor or it gets filled by another property or method.
In that case you can ignore the property or type by calling .IgnoreIt() in the setup.

In the following example we see, that the properties LastName and Name as well as the type DateTime of the person will be ignored by the ObjectFiller.NET.

When the ObjectFiller.NET creates the Person object the Name and LastName remaining null and the Birthday will be the default value of DateTime!

Suggest Edits

Ignore inheritance

 
public class Address
{
  public string City { get; set; }
  public int HouseNumber { get; set; }
}

public class CompanyAddress : Address
{
  public string CompanyName { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<CompanyAddress> pFiller = new Filler<CompanyAddress>();
    pFiller.Setup()
      .IgnoreInheritance();

    CompanyAddress address = pFiller.Create();
  }
}

Documentation

Sometimes it is necessary that the ObjectFiller should NOT fill the properties of a base class from which your poco derives from. ObjectFiller would also fill this properties by default but you can change this behaviour by calling IgnoreInheritance() in the ObjectFiller setup.

In the following example we see, that the class CompanyAddress is derived from the base class Address.

In the filler setup we call .IgnoreInheritance(). This will lead the ObjectFiller to not create values for the properties City and HouseNumber of the base type Address.

Suggest Edits

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

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.

Suggest Edits

Fun with Enumerable

 
public class Person
{
  public string Name { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  public DateTime Birthday { get; set; }

  public List<Address> Addresses { get; set; }
}

public class Address
{
  public int Id { get; set; }

  public string Street { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .SetupFor<Address>()
      .OnProperty(x => x.Id).Use(Enumerable.Range(1, 100).Where(x => x % 2 == 0));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

With ObjectFiller.NET it is possible to use the static Enumerable class to fill objects.
Use it for example when you want to fill a property in a specific order with include and exclude and all the other cool stuff which Enumerable and LINQ supports.

In the following example the ID of an Address item will be an even number between 1 and 100 in ascending order. This means, the first Address will have the Id 2, the second the Id 4, the fourth Id 6 and so...

Suggest Edits

Handle Interface Properties

 
public class Person
{
  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 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>();

    Person filledPerson = pFiller.Create();
  }
}

Documentation

In the following example the class Person has a property Address of the interface type IAddress!
To fill properties which are type of an interface it is necessary to register the implementation type of the interface in the ObjectFiller.NET setup. This can be done by calling the method .OnType<TInterface>().CreateInstanceOf<TImplemenation>().

Suggest Edits

Handle Constructor Arguments

 
public class Person
{
  public Person(Address address)
  {
    Address = address;
  }

  public string Name { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  public DateTime Birthday { get; set; }
  public Address Address { get; set; }

}

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

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnProperty(x=>x.Address).IgnoreIt();

    Person filledPerson = pFiller.Create();
  }
}

Documentation

With ObjectFiller.NET it is possible to instantiate objects which have a constructor WITH arguments.

In the example the property Address in the class person gets ignored because it gets filled by the constructor.

It is also possible to define a setup for the Address by calling .SetupFor<Address> in the fluent API. The addressargument in the constructor of class Person gets than filled with an Addressobject which matches the configuration.

Suggest Edits

Handle IEnumerable Properties

 
public class Person
{
  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>();

    Person filledPerson = pFiller.Create();
  }
}

Documentation

Properties which are of type IEnumerable<T> like lists or dictionaries can also be filled by ObjectFiller.NET like it is shown in the following example.

If you want to specify how the list will get filled by the Objectfiller.NET take a look at the Collectionizer Plugin !

Suggest Edits

Handle Circular Hierarchies

 
public class Children
{
  public Parent Parent { get; set; }
}

public class Parent
{
  public List<Children> Childrens { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Parent> pFiller = new Filler<Parent>();
    pFiller.Setup()
      .OnCircularReference().ThrowException(false);

    Parent filledParent = pFiller.Create();
  }
}

Documentation

The ObjectFiller is able to detect circulare references. You can configure the ObjectFiller to ignore the circular references or throw an exception when a circular reference occurs. By default ObjectFiller.NET stops creating new instances in a circular reference after one loop and leave the property null.

In the following example the class "Parent" has a List<Children> and the class Children has a again a Parent - this is called a circular reference.

The ObjectFiller.NET detects that and doesn't fill the circular object anymore!
When .Setup().OnCircularReference().ThrowException(true); with the true flag is called, ObjectFiller will raise an exception instead of just ignore the circular reference.

Suggest Edits

Complex Example

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

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!

Suggest Edits

Usage of static class Randomizer

 

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

How to write a ObjectFiller.NET plugin

 
public class MyFirstPlugin : IRandomizerPlugin<string>
{
  private readonly Random r = new Random();
  private readonly List<string> allNames = 
  new List<string>() 
  { 
    "Jennifer", 
   	"Jenny", 
   	"Tom", 
   	"John" 
  };

  public string GetValue()
  {
    return allNames[r.Next(0, allNames.Count)];
  }
}

public class Person
{
  public string Name { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnType<string>().Use(new MyFirstPlugin());

    Person filledPerson = pFiller.Create();
  }
}

Documentation

Writing your own plugin is very easy.

Just implement the IRandomizerPlugin<T> plugin.

The typeparameter T defines the type for which you will write the plugin.
The interface has just one function which you have to implement: T GetValue();
Thats all! You can write plugins for simple types and complex types.

The following example shows the implementation of the plugin MyFirstPlugin.
The MyFirstPlugin plugin is written for the type string because it is derived from IRandomizerPlugin<string>.

The implementation in the method public string GetValue() takes a random item of a given list. Thats all. Now it is possible to use this plugin everywhere where a value of type string should be genereated.

If you wrote a great plugin, i would be happy to get a pull request on GitHub :smile+: :+1+:

Suggest Edits

How to use randomizer plugins

 
public class Address
{
  public string City { get; set; }
  public int HouseNumber { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Address> pFiller = new Filler<Address>();
    pFiller.Setup()
      .OnProperty(x => x.City).Use(new CityName())
      .OnType<int>().Use(new IntRange(1, 38));

    Address address = pFiller.Create();
  }
}

Documentation

To use a randomizer plugin you have to setup a property or type in the ObjectFiller.
In the following example we use the CityName plugin for the property City in the class Address.

We also setup the type integer to use the IntRange plugin. Within the constructor of the IntRange plugin we define that every housenumber should be a number between 1 and 38.

Suggest Edits

Collectionizer

 
public class CountryInformations
{
  public List<string> CityNames { get; set; }
  public IEnumerable<string> FirstNames { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<CountryInformations> pFiller = new Filler<CountryInformations>();
    pFiller.Setup()
      .OnProperty(x => x.CityNames).Use(new Collectionizer<string, CityName>(10, 100))
      .OnProperty(x => x.FirstNames).Use(new Collectionizer<string, RealNames>(new RealNames(NameStyle.FirstName), 10));

    CountryInformations countryInfo = pFiller.Create();
  }
}

Documentation

With the Collectionizer plugin it is possible to generate lists filled with values based on other randomizer plugins. For example you have a List<string> in your POCO class and you want to have it filled with city names of the CityName string plugin.

In the following example there are two lists in the class CountryInformations.
In the property setup is specified that the property CityNames will be filled with the CityName-string plugin and that the list shall have a count between 10 and 100 items (new Collectionizer<string, CityName>(10, 100)).

The property FirstNames shall be filled with FirstNames of the RealNames plugin and a minimum count of 10 (new Collectionizer<string, RealNames>(new RealNames(NameStyle.FirstName), 10)) .

 
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<int>().Use(new IntRange(20, 79));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

The IntRange plugin is a very simple plugin and generates integers in a given range.
It has up to two constructor parameter. The first one is the maximum value and the second one (optional) the minimum. When minimum is not set, the minimum will be 0!

Suggest Edits

MnemonicString

 
public class Person
{
  public string Name { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnType<string>().Use(new MnemonicString(1,5,10));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

The MnemonicString plugin generates mnemonic words. A mnemonic word is a word with every second letter is a vowel. For example: "Dubinola"
The advantage is that these words are mostly easy to pronounce.

In this example we see how to use the MnemonicString plugin. It has three constructor parameters. The first one defines how much words will be generated. The second is the word min length and the last one is the word max length.

Suggest Edits

RandomListItem

 
public class Person
{
  public string Name { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnType<string>().Use(new RandomListItem<string>("Jennifer", "Jenny", "Tom", "John"));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

The RandomListItem plugin is usefull when you want to choose the output value from a certain set of given values. The RandomListItem will then pick randomly one item from the list.

In the following example are 4 given values in the RandomListItem plugin, one of them will be the generated name of the Person object.

Suggest Edits

PatternGenerator

 
public class Person
{
  public string Name { get; set; }
  public string LastName { get; set; }
  public int Age { get; set; }
  public DateTime Birthday { get; set; }
  public List<Address> Address { get; set; }
}

public class Address
{
  public string Street { get; set; }
  public string City { get; set; }
  public string PostalCode { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();

    pFiller.Setup()
      .SetupFor<Address>()
      .OnProperty(x => x.City)
      .Use(new PatternGenerator("{A}{a:2-8}"))
      .OnProperty(x => x.PostalCode)
      .Use(new PatternGenerator("CA {C:10000}"))
      .OnProperty(x => x.Street)
      .Use(new PatternGenerator("Street {C:100,10} NE"));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

The PatternGenerator can be used to created strings following a certain pattern. The actual pattern documentation can be found in PatternGenerator documentation.

In the following example the Address.City will become a string, starting with exactly one upper-case char, followed by 2..8 lower-case chars.

Address.PostalCode will start with the fixed value "CA ", followed by a number starting at 10000, incremented by 1 in the next address in the persons address list.

The property `Street┬┤will contain the text "Street ", followed by a (street) number starting at 100, incremented by 10.

Suggest Edits

RealNames

 
public class Person
{
  public string FirstName { get; set; }
  public string LastName { get; set; }
  public string FullName { get; set; }
  public string FullNameReverse { get; set; }
}

public class HelloFiller
{
  public void FillPerson()
  {
    Filler<Person> pFiller = new Filler<Person>();
    pFiller.Setup()
      .OnProperty(x => x.FirstName).Use(new RealNames(NameStyle.FirstName))
      .OnProperty(x => x.LastName).Use(new RealNames(NameStyle.LastName));

    Person filledPerson = pFiller.Create();
  }
}

Documentation

The RealName plugin is made to generate strings based on real names like "Jennifer" or "Miller". The realname plugin contains about 5000 first- and last names.

The RealNameplugin has a NameStyle enumeration as constructor parameter. With that enumeration it is possible to define how the generated name should look like.

 
public class Address
{
  public string City { get; set; }
}

public class HelloFiller
{
  public void FillAddress()
  {
    Filler<Address> pFiller = new Filler<Address>();
    pFiller.Setup()
      .OnProperty(x => x.City).Use(new CityName());
    
    Address filledAddress = pFiller.Create();
  }
}

Documentation

The CityName plugin is a plugin for the type string. It contains the top 1000 cities with the most inhabitants.

Suggest Edits

CountryName

 
public class Address
{
  public string Country { get; set; }
}

public class HelloFiller
{
  public void FillAddress()
  {
    Filler<Address> pFiller = new Filler<Address>();
    pFiller.Setup()
      .OnProperty(x => x.Country)
      .Use(new CountryName());
    
    Address filledAddress = pFiller.Create();
  }
}

Documentation

The CountyName plugin is a plugin for the type string. It contains all country names

Suggest Edits

StreetName

 
public class Address
{
  public string Street { get; set; }
}

public class HelloFiller
{
  public void FillAddress()
  {
    Filler<Address> pFiller = new Filler<Address>();
    pFiller.Setup()
      .OnProperty(x => x.Street)
      .Use(new StreetName(City.Paris));
    
    Address filledAddress = pFiller.Create();
  }
}

Documentation

The StreetName plugin is a plugin for the type string. It contains all streets of the cities Dresden, London, Paris, Tokyo, New York and Moscow.

For which City a street name will be chosen have to be specified by the City-Enumeration in the constructor of the StreetName plugin.

Suggest Edits

EmailAddresses

 
public class Address
{
  public string Street { get; set; }
}

public class HelloFiller
{
  public void FillAddress()
  {
    Filler<Address> pFiller = new Filler<Address>();
    pFiller.Setup()
      .OnProperty(x => x.Street)
      .Use(new EmailAddresses(".de"));
    
    Address filledAddress = pFiller.Create();
  }
}

Documentation

The EmailAddresses plugin is ObjectFiller.NET plugin for the type string. It will generate email-adresses. It is possible to specify the top level domain as well as the domainpart and the name part in the mail address.

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()
      .OnProperty(x => x.LastName)
      .Use(new Lipsum(LipsumFlavor.LoremIpsum,
                      3, 5, minWords: 100))
      
      .OnProperty(x => x.Name)
      .Use(new Lipsum(LipsumFlavor.InDerFremde));
    
    Person filledPerson = pFiller.Create();
  }
}

Documentation

The "Lorem Ipsum" plugin generates some random text which contains the famous "Lorem Ipsum" text. Read more about the Lorem Ipsum here. With the Lipsum plugin it is also possible to generate some other random text in english (Child Harold), german (In der Fremde) and french (Le Masque)

The following example generates for the Lastname a Lorem Ipsum text with 3 paragraphs, min 5 sentences and min 100 words. On property Name it generates a text on german.

Suggest Edits

SequenceGenerator Plugins

 
public void Countdown()
{
  var generator = new SequenceGeneratorInt32
  									 { From = 3, Step = -3 };
  
  generator.GetValue(); // returns  3
  generator.GetValue(); // returns  0
  generator.GetValue(); // returns -3
  generator.GetValue(); // returns -6
}

Documentation

The ObjectFiller contains also tons of sequence generators, like the SequenceGeneratorInt32 or the SequenceGeneratorDateTime. When used without any particular setup, they will simply create an increasing sequence like [1,2,3,...]. Most of these sequence generators can be customized to use a different start value (From), a different increment (Step) or can even wrap around after hitting an end value (To). The Step property can be even set to a negative value to generate a decreasing sequence, like in the example below.