i have a generated domain model using LLBLGEN, and im validating those validation rules which are created at domain layer using the fluentvalidation.TestHelper features.
an example of my validation looks like this:
public partial class MyClassValidator : AbstractValidator< MyClass >
{
public MyClassValidator()
{
RuleFor(x => x.MyObjMoneyValue)
.NotEmpty()
.WithName("MyObjMoneyValue")
.WithState(x => NewFluentCustomState(x));
CustomRules();
}
}
so i have a custom set of rules which arent generated by LLBLGEN which is a partial class to the generated rules which allows me to write some custom rules that arent based on the database (i.e. not null).
public partial class MyClassValidator
{
private void CustomRules()
{
RuleFor(q => q.MyObjMoneyValue)
.GreaterThan(0)
.WithMessage("Value must be greater than 0")
.WithState(NewFluentCustomState);
i have a test to test this case:
_validator.ShouldHaveValidationErrorFor(q => q.MyObjMoneyValue, 0);
However, this fails to test the custom rules.. any idea how how i can test the custom rules?
thanks
You can use Custom(x => x.) for your custom validation no need for another methods