PgAssert
Namespace: Ankus
Assembly: Ankus.Runtime.dll
Checks conditions inside backend tests, as pgrx tests use assert! and assert_eq!.
public static class PgAssertA failed check throws PgAssertException, which fails the PgTestAttribute method with a message naming the expected and actual values. Test frameworks such as MSTest do not load inside an extension, so use these checks in backend code and the framework’s own assertions in managed tests.
Inheritance: object
Methods
Section titled “Methods”AreEqual(double, double, double, string?)
Section titled “AreEqual(double, double, double, string?)”Checks that two floating-point values differ by no more than a tolerance, as MSTest’s Assert.AreEqual
with a delta does.
public static void AreEqual(double expected, double actual, double delta, string? message = null)Parameters:
expected — double
The expected value.
actual — double
The actual value.
delta — double
The largest allowed difference; NaN equals NaN.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The values differ by more than the tolerance.
AreEqual<T>(T, T, string?)
Section titled “AreEqual<T>(T, T, string?)”Checks that two values are equal by Default.
public static void AreEqual<T>(T expected, T actual, string? message = null)Type parameters:
T
The value type.
Parameters:
expected — T
The expected value.
actual — T
The actual value.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The values differ.
AreNotEqual<T>(T, T, string?)
Section titled “AreNotEqual<T>(T, T, string?)”Checks that two values differ by Default.
public static void AreNotEqual<T>(T notExpected, T actual, string? message = null)Type parameters:
T
The value type.
Parameters:
notExpected — T
The value that must not appear.
actual — T
The actual value.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The values are equal.
AreSequenceEqual<T>(IEnumerable<T>, IEnumerable<T>, string?)
Section titled “AreSequenceEqual<T>(IEnumerable<T>, IEnumerable<T>, string?)”Checks that two sequences hold equal elements in the same order.
public static void AreSequenceEqual<T>(IEnumerable<T> expected, IEnumerable<T> actual, string? message = null)Type parameters:
T
The element type.
Parameters:
expected — IEnumerable<T>
The expected elements.
actual — IEnumerable<T>
The actual elements.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The sequences differ.
Contains(string, string?, string?)
Section titled “Contains(string, string?, string?)”Checks that a string contains a substring, compared ordinally.
public static void Contains(string substring, string? value, string? message = null)Parameters:
substring — string
The text that must appear.
value — string
The string to search.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The string does not contain the substring.
DoesNotContain(string, string?, string?)
Section titled “DoesNotContain(string, string?, string?)”Checks that a string does not contain a substring, compared ordinally.
public static void DoesNotContain(string substring, string? value, string? message = null)Parameters:
substring — string
The text that must not appear.
value — string
The string to search.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The string contains the substring.
EndsWith(string, string?, string?)
Section titled “EndsWith(string, string?, string?)”Checks that a string ends with a suffix, compared ordinally.
public static void EndsWith(string suffix, string? value, string? message = null)Parameters:
suffix — string
The expected end.
value — string
The string.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The string does not end with the suffix.
Fail(string)
Section titled “Fail(string)”Fails the test.
public static void Fail(string message)Parameters:
message — string
The explanation.
Exceptions:
- PgAssertException: Always.
HasCount<T>(int, IEnumerable<T>, string?)
Section titled “HasCount<T>(int, IEnumerable<T>, string?)”Checks that a sequence has exactly the given number of elements.
public static void HasCount<T>(int expected, IEnumerable<T> values, string? message = null)Type parameters:
T
The element type.
Parameters:
expected — int
The expected count.
values — IEnumerable<T>
The sequence.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The count differs.
IsEmpty<T>(IEnumerable<T>, string?)
Section titled “IsEmpty<T>(IEnumerable<T>, string?)”Checks that a sequence has no elements.
public static void IsEmpty<T>(IEnumerable<T> values, string? message = null)Type parameters:
T
The element type.
Parameters:
values — IEnumerable<T>
The sequence.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The sequence has elements.
IsFalse(bool, string?, string?)
Section titled “IsFalse(bool, string?, string?)”Checks that a condition is false.
public static void IsFalse(bool condition, string? message = null, string? expression = null)Parameters:
condition — bool
The condition.
message — string
An optional explanation.
expression — string
The condition’s source text, supplied by the compiler.
Exceptions:
- PgAssertException: The condition is true.
IsNotNull(object?, string?)
Section titled “IsNotNull(object?, string?)”Checks that a value is not null.
public static void IsNotNull(object? value, string? message = null)Parameters:
value — object
The value.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The value is null.
IsNull(object?, string?)
Section titled “IsNull(object?, string?)”Checks that a value is null, which is SQL NULL for values read from PostgreSQL.
public static void IsNull(object? value, string? message = null)Parameters:
value — object
The value.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The value is not null.
IsTrue(bool, string?, string?)
Section titled “IsTrue(bool, string?, string?)”Checks that a condition is true.
public static void IsTrue(bool condition, string? message = null, string? expression = null)Parameters:
condition — bool
The condition.
message — string
An optional explanation.
expression — string
The condition’s source text, supplied by the compiler.
Exceptions:
- PgAssertException: The condition is false.
StartsWith(string, string?, string?)
Section titled “StartsWith(string, string?, string?)”Checks that a string starts with a prefix, compared ordinally.
public static void StartsWith(string prefix, string? value, string? message = null)Parameters:
prefix — string
The expected beginning.
value — string
The string.
message — string
An optional explanation.
Exceptions:
- PgAssertException: The string does not start with the prefix.
ThrowsExactly<TException>(Action, string?)
Section titled “ThrowsExactly<TException>(Action, string?)”Checks that work throws an exception of exactly the given type.
public static TException ThrowsExactly<TException>(Action action, string? message = null) where TException : ExceptionType parameters:
TException
The expected exception type.
Parameters:
action — Action
The work, which runs in its own subtransaction.
message — string
An optional explanation.
Returns: TException
The exception.
Exceptions:
- PgAssertException: The work completed, or threw another exception type.
Running the work in a subtransaction rolls back its changes and any PostgreSQL error, so the test continues in the same transaction.
ThrowsSqlState(string, Action, string?)
Section titled “ThrowsSqlState(string, Action, string?)”Checks that work raises a PostgreSQL error with the given SQLSTATE, as a pgrx test’s
#[pg_test(error = “…”)] expects an error.
public static PgException ThrowsSqlState(string sqlState, Action action, string? message = null)Parameters:
sqlState — string
The expected five-character SQLSTATE, such as DivisionByZero.
action — Action
The work, which runs in its own subtransaction.
message — string
An optional explanation.
Returns: PgException
The error, for checking its message and other fields.
Exceptions:
- PgAssertException: The work completed, raised another SQLSTATE or threw another exception.