public void IsValid_WhenUserName_IsEmpty(string userName) { var command = new FakeMustNotContainInvalidUserNameTextCommand { UserName = userName, }; var validator = new FakeMustNotContainInvalidUserNameTextValidator(); var result = validator.Validate(command); result.IsValid.ShouldBeTrue(); validator.ShouldNotHaveValidationErrorFor(x => x.UserName, command.UserName); }
public void IsValid_WhenUserName_IsEmailAddress() { var userName = string.Format("{0}@domain.tld", Guid.NewGuid()); var command = new FakeMustNotContainInvalidUserNameTextCommand { UserName = userName, }; var validator = new FakeMustNotContainInvalidUserNameTextValidator(); var result = validator.Validate(command); result.IsValid.ShouldBeTrue(); validator.ShouldNotHaveValidationErrorFor(x => x.UserName, command.UserName); }
public void IsInvalid_WhenUserName_ContainsUnallowedCharacters(string userName) { var command = new FakeMustNotContainInvalidUserNameTextCommand { UserName = userName, }; var validator = new FakeMustNotContainInvalidUserNameTextValidator(); var result = validator.Validate(command); result.IsValid.ShouldBeFalse(); Func <ValidationFailure, bool> userNameError = x => x.PropertyName == command.PropertyName(y => y.UserName); result.Errors.Count(userNameError).ShouldEqual(1); result.Errors.Single(userNameError).ErrorMessage.ShouldEqual(Resources.Validation_UserName_AllowedCharacters .Replace("{PropertyName}", User.Constraints.NameLabel) ); validator.ShouldHaveValidationErrorFor(x => x.UserName, command.UserName); }