public void IsValidWhen_Value_MatchesPreviousSpelling_CaseInsensitively() { var model = new UpdateEmailValueForm { Value = "*****@*****.**", PersonUserName = string.Empty }; var emailAddress = new EmailAddress { Value = "*****@*****.**", Person = new Person { User = new User { Name = model.PersonUserName } }, }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailAddress>()).Returns(new[] { emailAddress }.AsQueryable); var validator = new UpdateEmailValueValidator(entities.Object); var results = validator.Validate(model); var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName); error.ShouldBeNull(); }
public void IsInvalidWhen_Number_DoesNotMatchEmail_ForNonNullPersonUserName() { const string personUserName = "******"; const string emailValue = "*****@*****.**"; var form = new UpdateEmailValueForm { PersonUserName = personUserName, Number = 13, Value = emailValue.ToUpper(), }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailAddress>()).Returns(new EmailAddress[] { }.AsQueryable); var validator = new UpdateEmailValueValidator(entities.Object); var results = validator.Validate(form); results.IsValid.ShouldBeFalse(); results.Errors.Count.ShouldBeInRange(1, int.MaxValue); var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName); error.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException error.ErrorMessage.ShouldEqual(string.Format( ValidateEmailAddress.FailedBecauseNumberAndPrincipalMatchedNoEntity, form.Number, form.PersonUserName)); // ReSharper restore PossibleNullReferenceException }
public void IsValidWhen_Number_MatchesEmail_ForPersonUserName() { const string personUserName = "******"; const string emailValue = "*****@*****.**"; var form = new UpdateEmailValueForm { PersonUserName = personUserName, Number = 13, Value = emailValue.ToUpper(), }; var emailAddress = new EmailAddress { Value = emailValue.ToLower(), Number = form.Number, Person = new Person { User = new User { Name = form.PersonUserName, } } }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailAddress>()).Returns(new[] { emailAddress }.AsQueryable); var validator = new UpdateEmailValueValidator(entities.Object); var results = validator.Validate(form); var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName); error.ShouldBeNull(); }
public void IsInvalidWhen_Value_DoesNotMatchPreviousSpelling_CaseInsensitively() { var model = new UpdateEmailValueForm { Value = "*****@*****.**", PersonUserName = string.Empty }; var emailAddress = new EmailAddress { Value = "*****@*****.**", Person = new Person { User = new User { Name = model.PersonUserName }, } }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <EmailAddress>()).Returns(new[] { emailAddress }.AsQueryable); var validator = new UpdateEmailValueValidator(entities.Object); var results = validator.Validate(model); results.IsValid.ShouldBeFalse(); results.Errors.Count.ShouldBeInRange(1, int.MaxValue); var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName); error.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException error.ErrorMessage.ShouldEqual( UpdateEmailValueValidator.FailedBecausePreviousSpellingDoesNotMatchValueCaseInsensitively); // ReSharper restore PossibleNullReferenceException }
public void IsInvalidWhen_Value_IsMissingTldExtension() { var validator = new UpdateEmailValueValidator(null); var model = new UpdateEmailValueForm { Value = "email@domain" }; var results = validator.Validate(model); results.IsValid.ShouldBeFalse(); results.Errors.Count.ShouldBeInRange(1, int.MaxValue); var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName); error.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException error.ErrorMessage.ShouldEqual( UpdateEmailValueValidator.FailedBecausePreviousSpellingDoesNotMatchValueCaseInsensitively); // ReSharper restore PossibleNullReferenceException }