Skip to content

Configure object creation

TheCodeKing edited this page Jul 16, 2011 · 4 revisions

Overview | How To | Configure Object Creation

The library allows the configuration of predictable test data which is used for populating the generated instances. The configuration is implemented using a fluent interface either globally or in-line as shown in the example below. For a full list of commands see here, and for documentation on default behaviours see here.

In-line configuration to set all supported value types to their min value:

Person person = Auto.Make<Person>().Min();

Assert.That(person.Id, Is.EqualTo(int.MinValue));

The same configuration set globally:

Auto.Configure.Min();

Person person = Auto.Make<Person>();

Assert.That(person.Id, Is.EqualTo(int.MinValue));

Configuration commands can also be chained together using the fluent interface.

 Person person = Auto.Make<Person>()
					 .With<int>(15)
					 .Do(o => o.Father = new Person { FirstName = "FatherName"})
					 .EnumerabeSize(2);
 
 Assert.That(person.Id, Is.EqualTo(15));
 Assert.That(person.Father.FirstName, Is.EqualTo("FatherName"));
 Assert.That(person.Children.Count, Is.EqualTo(2));
 Assert.That(person.Children[0].FirstName, Is.EqualTo("FirstName"));

Clone this wiki locally