Skip to main content
Version: 0.3.x (0.3.0)

Class ValueObjectCustomization

Namespace: AdCodicem.ValueObjects.AutoFixture
Assembly: AdCodicem.ValueObjects.AutoFixture.dll

Customizes an AutoFixture fixture so that every value object it creates is drawn from the rules its type declares: asked for directly, as its nullable form, or as a member of an object the fixture builds.

public sealed class ValueObjectCustomization : ICustomization

Inheritance​

object ← ValueObjectCustomization

Implements​

ICustomization

Inherited Members​

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()

Remarks​

Without it, AutoFixture calls the value object's Create with values of its own, longer than a declared MaxLength, outside declared bounds, always the first known value of a closed set, and the creation fails or passes by chance. With it, each value object is drawn by a : a candidate built from its schema, kept only once its rules accept it, or the example it declares.

A registration of the fixture wins over the customization, whether it comes before or after it: fixture.Register(() => EvenCode.Create(...)) is how a rule no schema carries, a checksum for one, is met in AutoFixture's terms, as is in the sampler's. A specimen builder the fixture's customizations held before the customization wins too, its builder being added after them.

A value object is found through ValueObjectRegistry.TryResolve, which describes a value object written by hand the first time a fixture asks for it, and keeps that description. The customization is as thread-safe as the it draws from: by default is, a created with a seed is not, and gives the same values for the same requests only when a single thread makes them.

Constructors​

ValueObjectCustomization()​

Initializes a new instance of the class, drawing from with the default sampler options.

public ValueObjectCustomization()

ValueObjectCustomization(ValueObjectSamplerOptions)​

Initializes a new instance of the class, drawing from with the given sampler options.

public ValueObjectCustomization(ValueObjectSamplerOptions options)

Parameters​

options ValueObjectSamplerOptions

How each value object is drawn, the generators of the rules no schema carries included.

Exceptions​

ArgumentNullException

options is null.

ValueObjectCustomization(ValueObjectSamplerOptions, Random)​

Initializes a new instance of the class, drawing from the given source of randomness with the given sampler options.

public ValueObjectCustomization(ValueObjectSamplerOptions options, Random random)

Parameters​

options ValueObjectSamplerOptions

How each value object is drawn, the generators of the rules no schema carries included.

random Random

The source of randomness: a created with a seed replays the same values.

Exceptions​

ArgumentNullException

options or random is null.

Methods​

Customize(IFixture)​

Adds to the fixture's customizations a specimen builder that answers the request for any value object type, or for its nullable type, with a value its rules accept.

public void Customize(IFixture fixture)

Parameters​

fixture IFixture

The fixture to customize.

Exceptions​

ArgumentNullException

fixture is null.