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