public void Validate(ErrorSummary errors) { if (Product == null) { errors.RegisterErrorMessage("Product", "The order must have a product."); return; } if (Quantity < Product.MinQuantity || Quantity > Product.MaxQuantity) { errors.RegisterErrorMessage("Quantity", string.Format("The quantity {0} is invalid, it must be between {1} and {2}", Quantity, Product.MinQuantity, Product.MaxQuantity)); } }
public ErrorSummary IsValid(object instance, RunWhen runWhen) { ErrorSummary errors = new ErrorSummary(); errors.RegisterErrorMessage("someKey", "error"); return(errors); }
protected bool CheckForValidationFailures(object instance, Type instanceType, PropertyInfo prop, object value, string name, string prefix, ErrorSummary summary) { bool hasFailure = false; if (validator == null) { return(false); } IValidator[] validators = validator.GetValidators(instanceType, prop); foreach (IValidator validatorItem in validators) { if (!validatorItem.IsValid(instance, value)) { string propName = validatorItem.FriendlyName ?? validatorItem.Name; errors.Add(new DataBindError(prefix, prop.Name, validatorItem.ErrorMessage)); summary.RegisterErrorMessage(propName, validatorItem.ErrorMessage); hasFailure = true; } } return(hasFailure); }
public void RegisterMessageChaining() { ErrorSummary summ1 = new ErrorSummary().RegisterErrorMessage("test1", "test1"); ErrorSummary summ2 = summ1.RegisterErrorMessage("test2", "test2").RegisterErrorMessage("test3", "test3"); Assert.AreSame(summ1, summ2); }
public ViewResult ChangeAnswer(UserFull userModification) { UserAnswer userAnswer = new UserAnswer(userModification); var errors = userAnswer.Validate(); if (errors == null) { MembershipUser mu = Membership.GetUser(); if (!mu.ChangePasswordQuestionAndAnswer(userAnswer.Password, securityQuestionRepository.Get(userModification.SecurityQuestion).Description, userAnswer.SecurityAnswer)) { errors = new ErrorSummary(); errors.RegisterErrorMessage("SecurityQuestion", "There was an error while we was updating your security answer, please check your password and try again."); } else { userModification.Alert = "User security question and answer changed successfully"; } } if (errors != null) { Session["Errors"] = errors.ErrorMessages; } userModification.Tab = 3; userModification = GetAccountData(userModification); return(View("Index", userModification)); }
public void RegisterMessageChaining() { ErrorSummary summ1 = new ErrorSummary().RegisterErrorMessage("test1", "test1"); ErrorSummary summ2 = summ1.RegisterErrorMessage("test2", "test2").RegisterErrorMessage("test3", "test3"); Assert.AreSame(summ1, summ2); }
public ViewResult ChangeEmail(UserFull userModification) { UserEmail userEmail = new UserEmail(userModification); var errors = userEmail.Validate(); if (errors == null) { if (registeredUserRepository.GetByMail(userModification.Email) == null) { MembershipUser mu = Membership.GetUser(); PublicUser ru = (PublicUser)registeredUserRepository.GetByMembershipId(Convert.ToInt32(mu.ProviderUserKey)); mu.Email = userModification.Email; ru.EmailAddress = userModification.Email; registeredUserRepository.SaveOrUpdate(ru); userModification.Alert = "User email updated successfully"; } else { errors = new ErrorSummary(); errors.RegisterErrorMessage("Email", "That email already exist in our database"); } } if (errors != null) { Session["Errors"] = errors.ErrorMessages; } userModification.Tab = 1; userModification = GetAccountData(userModification); return(View("Index", userModification)); }
public void Validate(ErrorSummary errorSummary) { if (total > 1000 && ItemSKUs.Length == 1) { //TODO Make it easy to register an error message with a key errorSummary.RegisterErrorMessage("total", "Customers cannot purchase 1 item if it is more than $1000 dollars."); } }
public void Validate(ErrorSummary summary) { if (Recipient == null || (Payer != null && Payer.Recipient == null)) { summary.RegisterErrorMessage( "Recipient", "Получатель платежа не установлен"); } if (Recipient != null && Payer != null && Payer.Recipient != null && Recipient.Id != Payer.Recipient.Id) { summary.RegisterErrorMessage( "Recipient", "Получатель платежей плательщика должен соответствовать получателю платежей выбранном в платеже"); } }
/// <summary> /// Registers the error message returned from an object validator /// as an error message for each individual indexed property. /// </summary> /// <param name="validator">The validator.</param> /// <param name="errors">The errors.</param> private void RegisterObjectValidatorErrorMessages(ObjectValidator validator, ErrorSummary errors) { ErrorSummary objectErrors = validator.ErrorSummary; foreach (string property in objectErrors.InvalidProperties) { foreach (string message in objectErrors.GetErrorsForProperty(property)) { errors.RegisterErrorMessage(validator.FriendlyName + "." + property, message); } } }
/// <summary> /// Appends the error to the <see cref="ErrorSummary">ErrorSummary</see>. /// </summary> /// <param name="validator">The validator.</param> /// <param name="errors">The errors.</param> protected virtual void AppendError(IValidator validator, ErrorSummary errors) { string name = validator.FriendlyName ?? validator.Name; ObjectValidator objectValidator = validator as ObjectValidator; if (objectValidator != null) { RegisterObjectValidatorErrorMessages(objectValidator, errors); } else { errors.RegisterErrorMessage(name, validator.ErrorMessage); } }
public void Should_Fail_To_Send_Email_Because_Email_Is_Invalid() { // arrange const string errorMessage = "message"; var email = new Email(); var validatorRunner = new Mock <IValidatorRunner>(); var errorSummary = new ErrorSummary(); validatorRunner.Setup(v => v.IsValid(It.IsAny <Email>())).Returns(false); validatorRunner.Setup(v => v.GetErrorSummary(It.IsAny <Email>())).Returns(errorSummary); errorSummary.RegisterErrorMessage(errorMessage, errorMessage); // act var service = new EmailSenderService(validatorRunner.Object); TestDelegate act = () => service.Send(email); // assert Assert.That(act, Throws.InstanceOf <ValidationException>().With.Property("ValidationErrorMessages").EqualTo(new[] { errorMessage })); }
public ViewResult ChangePassword(UserFull userModification, string OldPassword, string NewPassword, string ConfirmPassword) { UserPassword userPassword = new UserPassword(OldPassword, NewPassword, ConfirmPassword); var errors = userPassword.Validate(); if (errors == null) { if (OldPassword != NewPassword) { MembershipUser mu = Membership.GetUser(); if (!mu.ChangePassword(userPassword.OldPassword, userPassword.NewPassword)) { errors = new ErrorSummary(); errors.RegisterErrorMessage("OldPassword", "The password that you enter is invalid"); } else { userModification.Alert = "User password changed successfully"; } } else { errors = new ErrorSummary(); errors.RegisterErrorMessage("NewPassword", "The New Password is same as the Old Password"); } } if (errors != null) { Session["Errors"] = errors.ErrorMessages; } userModification.Tab = 2; userModification = GetAccountData(userModification); return(View("Index", userModification)); }
private void CheckForValidationFailures(object instance, string prefix, Node node, ErrorSummary summary) { if (validator == null) { return; } if (!validator.IsValid(instance)) { ErrorSummary errorSummaryFromValidator = validator.GetErrorSummary(instance); foreach (string invalidProperty in errorSummaryFromValidator.InvalidProperties) { if (ShouldIgnoreProperty(string.Format("{0}.{1}", node.FullName, invalidProperty))) { continue; } foreach (string errorMessage in errorSummaryFromValidator.GetErrorsForProperty(invalidProperty)) { summary.RegisterErrorMessage(invalidProperty, errorMessage); errors.Add(new DataBindError(prefix, invalidProperty, errorMessage)); } } } }
public void Validate(ErrorSummary errors) { errors.RegisterErrorMessage("errorKey", "errorMessage"); }
public ErrorSummary IsValid(object instance, RunWhen runWhen) { ErrorSummary errors = new ErrorSummary(); errors.RegisterErrorMessage("someKey", "error"); return errors; }
private void CheckForValidationFailures(object instance, string prefix, Node node, ErrorSummary summary) { if (validator == null) { return; } if (!validator.IsValid(instance)) { ErrorSummary errorSummaryFromValidator = validator.GetErrorSummary(instance); foreach (string invalidProperty in errorSummaryFromValidator.InvalidProperties) { if (ShouldIgnoreProperty(string.Format("{0}.{1}", node.FullName, invalidProperty))) continue; foreach (string errorMessage in errorSummaryFromValidator.GetErrorsForProperty(invalidProperty)) { summary.RegisterErrorMessage(invalidProperty, errorMessage); errors.Add(new DataBindError(prefix, invalidProperty, errorMessage)); } } } }
public void Validate(ErrorSummary errorSummary) { if (total > 1000 && ItemSKUs.Length == 1) //TODO Make it easy to register an error message with a key errorSummary.RegisterErrorMessage("total", "Customers cannot purchase 1 item if it is more than $1000 dollars."); }
public void Validate(ErrorSummary errors) { errors.RegisterErrorMessage("errorKey", "errorMessage"); }
public ViewResult Register(UserRegistration userRegistration) { var errors = userRegistration.Validate(); if (errors == null) { IList <UserFlavor> userFlavors = Session["UserFlavorSelected"] as List <UserFlavor>; IList <EventType> eventTypes = Session["EventTypeSelected"] as List <EventType>; IList <Garment> mygarments = Session["MyGarments"] as List <Garment>; IList <Garment> mywishlist = Session["MyWishList"] as List <Garment>; PublicUser user = new PublicUser(); user.EmailAddress = userRegistration.Email; user.ChangeZipCode(userRegistration.ZipCode); user.SetFlavors(userFlavors); user.Size = new UserSize(Convert.ToInt32(userRegistration.UserSize)); //TODO: Get the UserId from ASP.NET Membership MembershipCreateStatus status; MembershipUser mu = Membership.CreateUser(userRegistration.UserName, userRegistration.Password, userRegistration.Email, securityQuestionRepository.Get(Convert.ToInt32(userRegistration.SecurityQuestion)).Description, userRegistration.SecurityAnswer, true, out status); if (status != MembershipCreateStatus.Success) { errors = new ErrorSummary(); errors.RegisterErrorMessage("MembershipUser", status.ToString()); return(RegistrationError(userRegistration, errors.ErrorMessages)); } user.MembershipUserId = Convert.ToInt32(mu.ProviderUserKey); user.FirstName = string.Empty; user.LastName = string.Empty; user.PhoneNumber = string.Empty; if (eventTypes != null) { foreach (EventType eventType in eventTypes) { user.AddEventType(eventType); } } registeredUserRepository.SaveOrUpdate(user); Closet closet = new Closet(); closet.User = user; closet.PrivacyLevel = PrivacyLevel.Private; closetRepository.SaveOrUpdate(closet); if (mygarments != null) { foreach (Garment garment in mygarments) { closet.AddGarment(garment); } closetRepository.SaveOrUpdate(closet); } user.Closet = closet; registeredUserRepository.SaveOrUpdate(user); if (mywishlist != null && mywishlist.Count > 0) { WishList wl = new WishList(); wl.User = user; foreach (Garment wishlist in mywishlist) { wl.AddGarment(wishlist); } wishListRepository.SaveOrUpdate(wl); } closetRepository.GenerateCloset(user); Session.Abandon(); Session["UserRegistration"] = mu; return(View("RegistrationFinish", userRegistration)); } return(RegistrationError(userRegistration, errors.ErrorMessages)); }
protected bool CheckForValidationFailures(object instance, Type instanceType, PropertyInfo prop, object value, string name, string prefix, ErrorSummary summary) { bool hasFailure = false; if (validator == null) { return false; } IValidator[] validators = validator.GetValidators(instanceType, prop); foreach (IValidator validatorItem in validators) { if (!validatorItem.IsValid(instance, value)) { string propName = validatorItem.FriendlyName ?? validatorItem.Name; errors.Add(new DataBindError(prefix, prop.Name, validatorItem.ErrorMessage)); summary.RegisterErrorMessage(propName, validatorItem.ErrorMessage); hasFailure = true; } } return hasFailure; }