PgPropertyRunner
Namespace: Ankus
Assembly: Ankus.Runtime.dll
Runs a property test inside PostgreSQL, the counterpart of pgrx’s PgTestRunner: it checks a condition
against many generated inputs, reports a backend error as a failing input, and shrinks a failing input to a
small one.
public sealed class PgPropertyRunnerEach case runs in its own internal subtransaction, so a PostgreSQL error rolls back that case’s work and the run continues; a passing case keeps its changes in the enclosing transaction. Any exception from the test, including a PgException, fails the case. Query cancellation and other operator-intervention errors stop the run instead. Call it from a PgTestAttribute method or another backend callback.
[PgTest]
public static void DatesRoundTrip()
=> new PgPropertyRunner().Run(
PgGenerators.Number<int>().Select(PgDate.FromRawSaturating),
date => PgAssert.AreEqual(date, Spi.ExecuteScalar<PgDate>("SELECT $1", SpiParameter.Create(date))));
Inheritance: object
Constructors
Section titled “Constructors”PgPropertyRunner(PgPropertyOptions?)
Section titled “PgPropertyRunner(PgPropertyOptions?)”Runs a property test inside PostgreSQL, the counterpart of pgrx’s PgTestRunner: it checks a condition
against many generated inputs, reports a backend error as a failing input, and shrinks a failing input to a
small one.
public PgPropertyRunner(PgPropertyOptions? options = null)Parameters:
options — PgPropertyOptions
The case count, seed and limits, or null for proptest’s defaults.
Each case runs in its own internal subtransaction, so a PostgreSQL error rolls back that case’s work and the run continues; a passing case keeps its changes in the enclosing transaction. Any exception from the test, including a PgException, fails the case. Query cancellation and other operator-intervention errors stop the run instead. Call it from a PgTestAttribute method or another backend callback.
[PgTest]
public static void DatesRoundTrip()
=> new PgPropertyRunner().Run(
PgGenerators.Number<int>().Select(PgDate.FromRawSaturating),
date => PgAssert.AreEqual(date, Spi.ExecuteScalar<PgDate>("SELECT $1", SpiParameter.Create(date))));
Methods
Section titled “Methods”Run<T>(PgGenerator<T>, Action<T>)
Section titled “Run<T>(PgGenerator<T>, Action<T>)”Checks a property against generated inputs.
public void Run<T>(PgGenerator<T> generator, Action<T> test)Type parameters:
T
The input type.
Parameters:
generator — PgGenerator<T>
The input generator.
test — Action<T>
The property, which throws to fail.
Exceptions:
- PgPropertyException: An input failed, with the smallest failing input as Input and its failure as the inner exception, or the generator rejected too many cases.
- ArgumentOutOfRangeException: An option is outside its range.