Kata to start with FluentValidation library.
Implement a validator for the Product class satisfying the following rules.
- A mandatory property is neither null nor empty nor blank
- Properties Reference, Language, Gtin, SellerId and CategoryId are mandatory
- The Language is ISO 639-1 compliant (2 chars string, lower case)
- The Gtin allows GTIN-8, GTIN-12, GTIN-13 and GTIN-14 formats
- If provided, the Description is neither empty nor blank
- If provided, there must be between 2 and 5 pictures
- The CategoryId is a sequence of 2, 4 or 6 uppercase letters
- Create extension methods to group common validation patterns
- Create custom validators for complex property validation
Format | Digit position | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
GTIN-8 | N1 | N2 | N3 | N4 | N5 | N6 | N7 | N8 | ||||||
GTIN-12 | N1 | N2 | N3 | N4 | N5 | N6 | N7 | N8 | N9 | N10 | N11 | N12 | ||
GTIN-13 | N1 | N2 | N3 | N4 | N5 | N6 | N7 | N8 | N9 | N10 | N11 | N12 | N13 | |
GTIN-14 | N1 | N2 | N3 | N4 | N5 | N6 | N7 | N8 | N9 | N10 | N11 | N12 | N13 | N14 |
Step 1 | Multiply value of each position by : | |||||||||||||
x3 | x1 | x3 | x1 | x3 | x1 | x3 | x1 | x3 | x1 | x3 | x1 | x3 | x0 | |
Step 2 | Add results together to create sum | |||||||||||||
Step 3 | Subtract the sum from the nearest equal or higher multiple of ten = CHECK DIGIT |
See https://www.gs1us.org/tools/check-digit-calculator for more details