I have a model:
public class DTO
{
public int[] StatementItems { get; set; }
}
Which I want to validate that:
StatementItems
is not nullStatementItems
is not emptyStatementItems
does not contain any duplicate IDs
The validation rule chain I created is:
RuleFor(x => x.StatementItems).NotNull().NotEmpty().Must(x => x.Distinct().Count() == x.Count());
And I have a test as:
_validator.ShouldHaveValidationErrorFor(x => x.StatementItems, null as int[]);
When I run the test passing in a null value, I would expect it to fail on the first rule of the chain (NotNull()
) and stop there. However, it complains that the lamda value used in the Must()
is null.
Am I wrong in thinking that the Must()
shouldn't be run if the NotNull()
fails? If so, how should this rule be written?
Thanks
int[]
is a non-nullable type? – Faithfaithful