tpierrain/NFluent

Improve Extensibility syntax for contributions

Closed this issue · 0 comments

Current syntax is still a bit tricky for newcomers. Especially when handling complex determination logic.
I propose to build a fluent syntax allowing to chain conditions and related error messages.
such as

 public static ICheckLink<ICheck<string>> IsNullOrWhiteSpace(this ICheck<string> check)
{
    ExtensibilityHelper.BeginCheck(check)
         // this check covers the simple failure scenario
        .FailsIf((sut) => !PolyFill.IsNullOrWhiteSpace(sut), "The {0} contains non whitespace characters.")
        // when negated, we fail if the string is null
        .NegatesIf((sut) => sut == null, "The {0} is null, whereas it should not.")
        // or, we fail if the string is empty
        .NegatesIf((sut) => sut == string.Empty, "The {0} is empty, whereas it should not.")
        // otherwise, it is because the string contains only spaces
        .Negates("The {0} contains only whitespace characters, whereas it should not.")
        // perform decision logic and raise exception if needed
        .EndCheck();

       // return continuation object
        return ExtensibilityHelper.BuildCheckLink(check);
}