yanncourtel / fluent-validation-kata

A kata to discover FluentValidation in c#

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fluent Validation Kata

Kata to start with FluentValidation library.

Packages

Your task

Implement a validator for the Product class satisfying the following rules.

Validation Rules

Product

  • 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

Need some help ?

Strategy

  • Create extension methods to group common validation patterns
  • Create custom validators for complex property validation

GTIN Check Digit Calculator

Format Digit position
GTIN-8 N1N2 N3N4N5N6 N7N8
GTIN-12 N1N2 N3N4N5N6 N7N8N9N10 N11N12
GTIN-13 N1N2 N3N4N5N6 N7N8N9N10 N11N12N13
GTIN-14 N1N2 N3N4N5N6 N7N8N9N10 N11N12N13N14
Step 1 Multiply value of each position by :
x3x1x3x1x3x1 x3x1x3x1x3x1 x3x0
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

About

A kata to discover FluentValidation in c#


Languages

Language:C# 100.0%