Quantcast
Channel: Fluent Validation for .NET
Viewing all articles
Browse latest Browse all 1917

New Post: when condition not working as expected

$
0
0
I am very new to Fluent Validation and C# programming

Below is my validator:
    public CustomerValidator()
    {
        When(customer => customer.IsPreferredCustomer, () =>
        {
            RuleFor(customer => customer.Discount).GreaterThan(0);
        });
    }
Here is how I validate data. But inspite of isPreferredCustomer set to false, the results.isValid = true. Am I missing anything
        Customer customer = new Customer();
        customer.Id = 13;
        customer.Surname = "foo";
        customer.Forename = "Abcs";
        customer.Discount = 2;
        customer.Address = "23 abc drive, hilton, ak";
        customer.IsPreferredCustomer = false;
        CustomerValidator validator = new CustomerValidator();
        var results = validator.Validate(customer);

Viewing all articles
Browse latest Browse all 1917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>