Advent of Code 2022 - Day 4
Puzzle: Camp Cleanup
Puzzle: Camp Cleanup
Puzzle: Rucksack Reorganization
Puzzle: Rock Paper Scissors
Puzzle: Calorie Counting
In the previous posts, we’ve learned how to create validators. Set the required rules and build custom validators. To finish learning using the fluent validation library, we’ll write some tests to be sure that we defined rules properly. Unit test extensions The validation library consists of two extension methods for validators which allow checking if a validator has or not any error for the chosen property. There are a few methods to use:...
In the previous posts, I’ve presented some basic info and possible configuration. Now, it’s time to show more complex examples. Custom Validator Sometimes build-in validator may not be enough. Then, you need to create it on your own. To have custom validator you define a class that inherits from PropertyValidator. We can pass the validation message to the base class. Moreover, our validation should be written inside IsValid the method....
Previously I’ve presented some introduction to Fluent Validation. In this post, I’m going to cover some configuration possibilities. Such as arranging validation processing to receive different results. Cascade mode At first, let’s manage validation execution. Cascade mode allows to setup how chained validators are executed. For example, there is a rule with two validators NotEmpty and GreaterThan: RuleFor(e => e.Number).NotEmpty().GreaterThan(10); When using that rule, it checks both of the validators no matter if the first validator fails or not....
Fluent Validation is a .NET library used to define validation rules for an object’s data. In the following post, I show the basic usage. At first, you need to add FluentValidation.dll to your project. For .NET Core use CLI command: dotnet add package FluentValidation However, if you are using NuGet run: Install-Package FluentValidation Validator To illustrate a basic concept, I use example class that will help to introduce different rules....