I'm struggling to make my Fluent Validation RuleSet work, currently it doesn't, and I don't have any idea why is that happening, everything seems all right. I would like to somehow step into the code that performs the validation itself, but RuleSet lambdas are ExpressionTrees which doesn't provide even poor debugging experience.
Is there a way to debug RuleSet logic to see what's happening inside RuleSets?
You can use debug log to debug your code. Goto Setup--> Administration Setup--> Monitoring-->Debug logs--> Click on New Button ---> click on lookup icon--> select logged in user from list -->click save. Now execute your code and go to that debug log page, you would find a entry log entry against your execution.
Using the Code The program does the following basic steps: Creating a new Item object and setting the properties on that object. Creating an instance of the ItemValidator class to validate the properties on the object instance. Validating the values on the instance of the Item object.
FluentValidation provides a great alternative to Data Annotations in order to validate models. It gives better control of validation rules and makes validation rules easy to read, easy to test, and enable great separation of concerns.
Fluent Validation is a validation library for . NET, used for building strongly typed validation rules for business objects. Fluent validation is one way of setting up dedicated validator objects, that you would use when you want to treat validation logic as separate from business logic.
FluentValidation is open source, so theoretically you could download the code from the repo at https://github.com/JeremySkinner/FluentValidation and then load up the solution, reference it directly, then step through.
Hopefully this will get you where you need to be, but I'm sure someone here could help if you provided your rules and maybe some unit tests that show the failures.
The current version of FluentValidation allows you to unit test your validators by using the TestValidate
extension method. There is also an async version available.
Calling this method, passing an object to validate, will return a TestValidationResult<>
object which has 2 useful methods ShouldHaveValidationErrorFor
and
ShouldNotHaveValidationErrorFor
that can be used to check if tests passed or failed.
The documentation can be found here https://docs.fluentvalidation.net/en/latest/testing.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With