Mercurial > silverbladetech
comparison SilverlightValidation/SilverlightValidation.Tests/Fakes/UserModelValidatorFake.cs @ 102:db05a55e3536
INPC tests added
author | stevenhollidge <stevenhollidge@hotmail.com> |
---|---|
date | Sun, 06 May 2012 12:13:29 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
101:2372846797f0 | 102:db05a55e3536 |
---|---|
1 using System; | |
2 using FluentValidation; | |
3 using SilverlightValidation.Interfaces; | |
4 | |
5 namespace SilverlightValidation.Tests.Fakes | |
6 { | |
7 class UserModelValidatorFake : AbstractValidator<IUserModel> | |
8 { | |
9 private UserModelValidatorFake() | |
10 { | |
11 RuleFor(x => x.Username) | |
12 .Length(3, 8) | |
13 .WithMessage("Must be between 3-8 characters."); | |
14 | |
15 RuleFor(x => x.Password) | |
16 .Matches(@"^\w*(?=\w*\d)(?=\w*[a-z])(?=\w*[A-Z])\w*$") | |
17 .WithMessage("Must contain lower, upper and numeric chars."); | |
18 | |
19 RuleFor(x => x.Email) | |
20 .EmailAddress() | |
21 .WithMessage("A valid email address is required."); | |
22 | |
23 RuleFor(x => x.DateOfBirth) | |
24 .Must(BeAValidDateOfBirth) | |
25 .WithMessage("Must be within 100 years of today."); | |
26 } | |
27 | |
28 private bool BeAValidDateOfBirth(DateTime? dateOfBirth) | |
29 { | |
30 if (dateOfBirth == null) return false; | |
31 if (dateOfBirth.Value > DateTime.Today || dateOfBirth < DateTime.Today.AddYears(-100)) | |
32 return false; | |
33 return true; | |
34 } | |
35 | |
36 public static UserModelValidatorFake Create() { return new UserModelValidatorFake(); } | |
37 } | |
38 } |