AutoFixture comes with a set of default builders so that most common scenarios are supported out-of-the-box.
These builders can be overridden with ad-hoc customizations or when building an anonymous variable.
The default builder for numbers is the
It supports the following types:
Unique numbers are generated randomly from the set
[1, 255]. Once these are used up they are then be generated from the set
[256, 65 535]. And finally from the set
[65 536, 2 147 483 647].
When all numbers within the final set have been used AutoFixture will start again from the first set.
The default builder for chars is the
It generates random characters from the printable ASCII character set (
! (33) to
The default builder for strings is an instance of
It returns randomly generated
Guid as string using the format
The default builder for
DateTime is the
It generates a date and a time between 2 years prior and 2 years after the current date.
var dateTime = fixture.Create<DateTime>();Assert.That(dateTime, Is.GreaterOrEqualThan(DateTime.Today.AddYears(-2)));Assert.That(dateTime, Is.LessOrEqualThan(DateTime.Today.AddYears(2)));
EnumGenerator is the default builder for enumerations.
It returns all the values of the enumeration in order. When all values are used, it starts from the first value again.
AutoFixture has a built-in support for many collection types:
Also, AutoFixture natively supports common collection interfaces like
IEnumerable. When requested, AutoFixture will return a type implementing the requested interface.
AutoFixture is able to generate out-of-the-box anonymous variables of both
var tuple = fixture.Create<Tuple<string, int>>();var valueTuple = fixture.Create<ValueTuple<string, int>>();
In the case of
ValueTuple, it also supports the simplified syntax.
var valueTuple = fixture.Create<(string, int)>();
The default builder for
Uri is the
UriGenerator delegates the scheme creation to a
UriSchemeGenerator configured to return
http by default.
The default builder for the
MailAddress type is the
This generator splits the email address into two parts that can be independently customized:
EmailAddressLocalPart, generated via a
DomainName, generated via a
For some types, the default configuration of AutoFixture is to return well-known values.
Here is a list of these cases:
IPAddress is registered with the value
Encoding is registered with the value
CultureInfo is registered with the value