annotate SilverlightValidation/SilverlightValidation.PL/Validators/UserModelValidator.cs @ 96:188f8b366e87

Unit test project correctly setup as normal class library DLL.
author stevenhollidge <stevenhollidge@hotmail.com>
date Sat, 05 May 2012 13:29:56 +0100
parents SilverlightValidation/SilverlightValidation/Validators/UserModelValidator.cs@241e2f22ed3c
children db05a55e3536
rev   line source
58
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
1 using System;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
2 using FluentValidation;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
3 using SilverlightValidation.Interfaces;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
4
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
5 namespace SilverlightValidation.Validators
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
6 {
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
7 public class UserModelValidator : AbstractValidator<IUserModel>
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
8 {
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
9 public UserModelValidator()
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
10 {
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
11 RuleFor(x => x.Username)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
12 .Length(3, 8)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
13 .WithMessage("Must be between 3-8 characters.");
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
14
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
15 RuleFor(x => x.Password)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
16 .Matches(@"^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$")
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
17 .WithMessage("Must contain lower, upper and numeric chars.");
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
18
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
19 RuleFor(x => x.Email)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
20 .EmailAddress()
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
21 .WithMessage("A valid email address is required.");
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
22
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
23 RuleFor(x => x.DateOfBirth)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
24 .Must(BeAValidDateOfBirth)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
25 .WithMessage("Must be within 100 years of today.");
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
26 }
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
27
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
28 private bool BeAValidDateOfBirth(DateTime? dateOfBirth)
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
29 {
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
30 if (dateOfBirth == null) return false;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
31 if (dateOfBirth.Value > DateTime.Today || dateOfBirth < DateTime.Today.AddYears(-100))
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
32 return false;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
33 return true;
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
34 }
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
35 }
241e2f22ed3c Latest version
Steven Hollidge <stevenhollidge@hotmail.com>
parents:
diff changeset
36 }