-
Notifications
You must be signed in to change notification settings - Fork 53
Advanced Checks
Cyrille DUPUYDAUBY edited this page May 17, 2018
·
16 revisions
This page is dedicated to advanced functions available to write your own checks
As shown in Extensibility the general structure of check logic is
public static ICheckLink<ICheck<string>> IsXXX(this ICheck<string> context)
{
ExtensibilityHelper.BeginCheck(context).
Rulexx(...).
Rulexx(...).
Rulexx(...).
EndCheck();
return ExtensibilityHelper.BuildChainLink(context);
}
Where each Rulexx(...) is an helper function that:
- defines a rule to check
- or provides details for error messages
Describes a situation where the check should faild. Signature:
ICheckLogic<T> FailWhen(Func<T, bool> predicate, string errorMessage, MessageOptions option = MessageOptions.None);
// exemple: fail when the sut is even.
...
FailWhen( sut => sut % 2 == 0, "The {checked} is even, whereas it should be odd.");
Where:
- predicate: function that will received the sut and must returns true when the check must fail.
-
errorMessage: error message template, using
{checked}
and{expected}
as placeholders for the sut and the provided expected value (if any). - option: flag enumeration that allows to specify options for error message structure. See below.
Enumeration that is used to specify options for error message generation. Values are flags and can be combined:
-
MessageOptions.None
: error message is generated with an error message, a standard description bloc for the checked value and a standard description bloc for the expected value, if one is provided -
MessageOptions.NoCheckedBlock
: prevent the creation of a description bloc for the checked value. Should be use when error message is explicit enough, for example when the checked value is null. -
MessageOptions.NoExpectedBlock
: prevent the creation of a description bloc for the exptected value. Should be use when error message is explicit enough, for example when the expected and checked value are equal. -
MessageOptions.ForceType
: ensure that explicit type information is provided for checked and expected blocs. -
MessageOptions.WithHash
: ensure that has values are provided for checked and expected blocs.
- Welcome
- How to start
- Customising error messages
-
Check.That
- All (Equality, Type)
- Reference types
- Members based
- IEnumerable (Properties, Content, Elements)
- String (Properties, Content, RegExp )
- Numeric Type(Properties, Comparisons, Floating)
- Dictionary
- Char (Properties, Value)
- IComparable
- DateTime
- DateTimeOffset
- Misc: Boolean, TimeSpan, Stream, Enum, EventWaitHandle
- Check.ThatCode
- Check.ThatDynamic
- Extensibility
- Auxiliary types (TimeUnit)
- Mocks