Table of Contents

AndAlsoTogether()

SpecBase<TModel, TMetadata> AndAlsoTogether<TModel, TMetadata>(
    this IEnumerable<SpecBase<TModel, TMetadata>> specs)

The AndAlsoTogether() extension method is used to combine a collection of specifications into a single specification that is satisfied if all the original specifications are satisfied. If the first specification is not satisfied, the remaining specifications are not evaluated. This means that any assertions or metadata that would be generated by the remaining specifications are not generated.

IEnumerable<SpecBase<int>> specs = 
    [
        new IsEvenProposition(),
        new IsGreaterThanProposition(5)
    ];

var isEvenAndGreaterThanFive = specs.AndAlsoTogether();

isEvenAndAlsoGreaterThanFive.Evaluate(6).Reason;  // "is even && is greater than 5"
isEvenAndAlsoGreaterThanFive.Evaluate(3).Reason;  // "is odd"