JustDummies

Just dummies — but seriously powerful ones.

API v1.0.0-preview.6

API sections

Entry point

One door in, and the contract every generator it produces satisfies — from the simplest primitive to a generator composed of several.

static class

Any

The entry point of the library: supplies arbitrary, valid values for the parts of a test that are not under assertion — the dummies a test needs so its Arrange stops advertising values it never checks. The constraints chained on a generator express what the surrounding code requires of the value (a value object's invariant, a contract precondition), never what the test asserts: an explicit Any call reads as "this is arbitrary" where a hand-picked literal reads as "this matters".

public static class Any

sealed class

AnyContext

An isolated, deterministic generation context created by WithSeed: every generator created from it draws from a dedicated source seeded with Seed, independent of the ambient context the static Any entry points use. Two contexts created with the same seed yield the same sequence of values.

public sealed class AnyContext

Constructed via

static AnyContext Any.WithSeed(int seed)Creates an isolated, deterministic generation context: every generator created from it draws from a dedicated source seeded with seed, independent of the ambient context. Two contexts created with the same seed yield the same sequence of values. Prefer Reproducibly inside tests — it keeps the arbitrary-by-default behavior and reports the seed only when the test fails; reach for WithSeed when you need an explicit generator object, for example outside a test body.

Properties

int Seed { get; }The seed pinning this context's value sequence.

Methods

AnyString String()Starts an arbitrary String generator drawing from this context — same fluent surface as String, deterministic under this context's seed.
AnyPattern StringMatching(string pattern)Starts a generator of arbitrary strings matching pattern drawing from this context — same fluent surface as StringMatching, deterministic under this context's seed.
AnyPattern StringMatching(Regex pattern)Starts a generator of arbitrary strings matching pattern drawing from this context — same fluent surface as StringMatching, deterministic under this context's seed. IgnoreCase is honoured; IgnorePatternWhitespace is rejected; the remaining options are ignored.
AnyUri Uri()Starts an arbitrary Uri generator drawing from this context — same fluent surface as Uri, deterministic under this context's seed.
AnyInt32 Int32()Starts an arbitrary Int32 generator drawing from this context — same fluent surface as Int32, deterministic under this context's seed.
AnySByte SByte()Starts an arbitrary SByte generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32.
AnyByte Byte()Starts an arbitrary Byte generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32, less Positive() and Negative(), which an unsigned type cannot express.
AnyInt16 Int16()Starts an arbitrary Int16 generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32.
AnyUInt16 UInt16()Starts an arbitrary UInt16 generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32, less Positive() and Negative(), which an unsigned type cannot express.
AnyUInt32 UInt32()Starts an arbitrary UInt32 generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32, less Positive() and Negative(), which an unsigned type cannot express.
AnyInt64 Int64()Starts an arbitrary Int64 generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32.
AnyUInt64 UInt64()Starts an arbitrary UInt64 generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32, less Positive() and Negative(), which an unsigned type cannot express.
AnyTimeSpan TimeSpan()Starts an arbitrary TimeSpan generator drawing from this context — deterministic under this context's seed: full range unless constrained, negative durations included. Same constraint algebra as AnyInt32, less MultipleOf(...) and plus WithGranularity(...).
AnyDateTime DateTime()Starts an arbitrary DateTime generator drawing from this context — deterministic under this context's seed: any representable instant unless constrained; generated values carry Utc kind. Same constraint algebra as AnyInt32 with the bounds renamed After(...)/Before(...): no sign or zero constraint, no MultipleOf(...), plus WithGranularity(...).
AnyDateTimeOffset DateTimeOffset()Starts an arbitrary DateTimeOffset generator drawing from this context — deterministic under this context's seed: any representable instant unless constrained; generated values carry a zero (UTC) offset. Same constraint algebra as AnyInt32 with the bounds renamed After(...)/Before(...): no sign or zero constraint, no MultipleOf(...), plus WithGranularity(...) and WithOffset(...).
AnyDouble Double()Starts an arbitrary Double generator drawing from this context — deterministic under this context's seed: finite values only — NaN and infinities are never generated. Same constraint algebra as AnyInt32, less MultipleOf(...).
AnySingle Single()Starts an arbitrary Single generator drawing from this context — deterministic under this context's seed: finite values only — NaN and infinities are never generated. Same constraint algebra as AnyInt32, less MultipleOf(...).
AnyDecimal Decimal()Starts an arbitrary Decimal generator drawing from this context — deterministic under this context's seed: full range unless constrained. Same constraint algebra as AnyInt32, less MultipleOf(...) and plus WithScale(...).
AnyBoolean Boolean()Starts an arbitrary Boolean generator drawing from this context (deterministic under this context's seed) — an even coin flip unless pinned with True() or False().
AnyGuid Guid()Starts an arbitrary Guid generator drawing from this context (deterministic under this context's seed) — unlike NewGuid, reproducible inside an Any.Reproducibly(...) run, and for every practical purpose never empty.
AnyEnum<TEnum> Enum<TEnum>() where TEnum : struct, EnumStarts an arbitrary TEnum generator drawing from this context (deterministic under this context's seed) — uniformly across the enum's declared members, never an undeclared numeric value.
AnyChar Char()Starts an arbitrary Char generator drawing from this context (deterministic under this context's seed) — the whole of ASCII, control characters included, unless constrained (ADR-0075), mirroring AnyString's character families.
AnyDateOnly DateOnly()Starts an arbitrary DateOnly generator drawing from this context (deterministic under this context's seed) — any representable date unless constrained. Net8.0 target only, like the type itself.
AnyTimeOnly TimeOnly()Starts an arbitrary TimeOnly generator drawing from this context (deterministic under this context's seed) — any time of day unless constrained. Net8.0 target only, like the type itself.
AnyInt128 Int128()Starts an arbitrary Int128 generator drawing from this context (deterministic under this context's seed) — full range unless constrained. Net8.0 target only, like the type itself.
AnyUInt128 UInt128()Starts an arbitrary UInt128 generator drawing from this context (deterministic under this context's seed) — full range unless constrained. Net8.0 target only, like the type itself.
AnyHalf Half()Starts an arbitrary Half generator drawing from this context (deterministic under this context's seed) — finite values only. Net8.0 target only, like the type itself.
AnyOneOf<T?> OneOf<T>(params T?[] values)Draws an arbitrary value from an explicit pool of caller-supplied values drawing from this context — same surface as OneOf, deterministic under this context's seed.
AnyOneOf<T?> ElementOf<T>(IReadOnlyList<T?> values)Draws an arbitrary value from an explicit pool held as a list drawing from this context — same surface as ElementOf, deterministic under this context's seed.
AnyOneOf<T?> ElementOf<T>(IEnumerable<T?> values)Draws an arbitrary value from an explicit pool held as a sequence drawing from this context — same surface as ElementOf, deterministic under this context's seed. The sequence is materialized once.

interface

IAny<T>

A recipe for an arbitrary value of type T that satisfies the constraints declared on it. This is the composition seam of the library: every generator — built-in or derived through As and Combine — implements it, so a constrained primitive, a value object built from one, and an object assembled from several all flow through the same contract.

public interface IAny<T>

Methods

T? Generate()Produces one arbitrary value satisfying every constraint declared on this generator.