Skip to content

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 PgPropertyRunner

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))));

Inheritance: object

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))));

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: