Class ValueObjectSamplerOptions
Namespace: AdCodicem.ValueObjects.Testing.Data
Assembly: AdCodicem.ValueObjects.Testing.Data.dll
How a
public sealed class ValueObjectSamplerOptions
Inheritance
object ← ValueObjectSamplerOptions
Inherited Members
object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.ReferenceEquals(object?, object?), object.ToString()
Remarks
Options are read, never written, while a sampler draws: set them up before the first draw, and share them between samplers as you like.
Properties
KnownValueShare
Gets or sets the share of draws taken from the known values of an open value set, from 0 to 1, the others drawn from the rest of its schema; one half by default.
public double KnownValueShare { get; set; }
Property Value
Remarks
A closed value set always draws one of its known values.
Exceptions
The value is not between 0 and 1.
MaxAttempts
Gets or sets how many candidates a draw tries before it falls back on the example the type declares; 100 by default.
public int MaxAttempts { get; set; }
Property Value
Exceptions
The value is less than 1.
MaxExtraLength
Gets or sets the most characters a string without a maximum length gets beyond the shortest it can be (its minimum
length, the shortest match of its pattern, or one character when it declares neither), and the most repetitions an
open quantifier of a pattern (*, +, {n,}) adds to its minimum unless the lengths the type
declares ask for more; 32 by default.
public int MaxExtraLength { get; set; }
Property Value
Exceptions
The value is negative.
PatternSampler
Gets or sets a sampler tried before the built-in one on the pattern of a string value object: it receives the pattern and the source of randomness, and returns a string the pattern matches, or null for a pattern it cannot sample, which leaves it to the built-in sampler.
public Func<string, Random, string?>? PatternSampler { get; set; }
Property Value
Func<string, Random, string?>?
Remarks
Every string it returns still goes through the rules of the type. It serves
Methods
Use<TSelf, TValue>(Func<Random, TValue>)
Registers the generator of the underlying value of a value object, for a rule its schema cannot carry, such as a checksum: the sampler draws its candidates from it rather than from the schema, and keeps only those the type's rules accept.
public ValueObjectSamplerOptions Use<TSelf, TValue>(Func<Random, TValue> generator) where TSelf : struct, IValueObject<TSelf, TValue>
Parameters
generator Func<Random, TValue>
Draws a candidate underlying value from the sampler's source of randomness.
Returns
These options, so that registrations chain.
Type Parameters
TSelf
The value object.
TValue
Its underlying type.
Remarks
A later registration for the same value object replaces the earlier one.
Exceptions
generator is null.