Values
Most assertions require you to make some comparison between two or more values. They can either be values in your database or constant values.
Constants
The simplest values are constants, which are defined during assertion creation.
To create them call Constant.<Type>(<value>)
with the appropriate type and value:
using DataConformance.Checking.Constants;
Constant.Null; // for the logical null value
Constant.Boolean(true); // for boolean values
Constant.String("some value"); // for string values
Constant.Integer(123); // for numbers without decimal points
Constant.Decimal(1.23); // for numbers with decimal points
Constant.LocalDate(1999, 02, 14); // for date values
Constant.OffsetDateTime(DateTimeOffset.Now); // for date time values with timezone
Column references
Column references are used to represent values loaded from your database. During assertion execution the column references are replaced with constants containing the values loaded from the database and can be used as such.
They are created using ColumnReference.<Type>(<reference to containing entity>, <column name>, <nullability>)
with the type being the constant type you want to use the value as.
If for example you want to use a nullabe text column called name in your database as a String constant, you would call ColumnReference.String(<reference to containing entity>, "name", true)
.
Note that nullability should match the nullability of the column in your database schema.
See mapping tables to see which data types can be mapped to which constant types.
Comparison
Values can be checked for equality and ordering. All values can be compared with other values of the same type. Constants of type Decimal, Integer and LocalDate can be compared for ordering with values of the same type. In addition Decimal and Integer constant values can be compared for ordering with each other. The Null constant is equal to itself and greater than all other values.
Operator | Method |
---|---|
a == b | a.IsEqualTo(b) |
a != b | a.IsNotEqualTo(b) |
a == Constant.Null | a.IsNull() |
a != Constant.Null | a.IsNotNull() |
a == b || a == c | a.IsOneOf(new []{ b, c }) |
a != b && a != c | a.IsNotOneOf(new []{ b, c }) |
a < b | a.IsLessThan(b) |
a <= b | a.IsLessThanOrEqualTo(b) |
a > b | a.IsGreaterThan(b) |
a >= b | a.IsGreaterThanOrEqualTo(b) |