public void IsInvalidWhen_MatchingEstablishment_IsNotMember() { const string emailAddress = "*****@*****.**"; var establishment = new Establishment { IsMember = false, EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld", } } }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Establishment>()).Returns(new[] { establishment }.AsQueryable); var validator = new SignOnValidator(entities.Object); var model = new SignOnForm { EmailAddress = emailAddress }; 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(string.Format( SignOnValidator.FailedBecauseEstablishmentIsNotEligible, emailAddress)); // ReSharper restore PossibleNullReferenceException }
public void IsInvalidWhen_IsNotValidEmailAddress() { var validator = new SignOnValidator(null); var model = new SignOnForm { EmailAddress = "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( SignOnValidator.FailedBecauseEmailAddressIsNotValidEmailAddress); // ReSharper restore PossibleNullReferenceException }
public void IsValidWhen_IsValidEmailAddress_AndBelongsToMemberEstablishment() { var establishment = new Establishment { IsMember = true, EmailDomains = new[] { new EstablishmentEmailDomain { Value = "@domain.tld", } } }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Establishment>()).Returns(new[] { establishment }.AsQueryable); var validator = new SignOnValidator(entities.Object); var model = new SignOnForm { EmailAddress = "*****@*****.**" }; var results = validator.Validate(model); var error = results.Errors.SingleOrDefault(e => e.PropertyName == PropertyName); error.ShouldBeNull(); }
public void Implements_IReturnUrl() { var model = new SignOnForm(); model.ShouldImplement <IReturnUrl>(); }