public ConfirmPasswordFixture() { Input = new StringOrKeyInputComponent(Console); Confirm = new ConfirmPasswordComponent(Console, this); this.ConvertToString(); }
/// <summary> /// This method returns the User /// </summary> public bool ValidateUser() { // initial value (default to true) bool isValid = true; // Erase by default ValidationMessage = ""; // if there is a UserNameComponent if (HasUserNameComponent) { // validate this control isValid = UserNameComponent.Validate(); // if the value for isValid is false if (!isValid) { // Set the Validation Message ValidationMessage = UserNameComponent.InvalidReason; } else { // Set the UserName UserName = UserNameComponent.Text; } } // if the value for HasNameComponent is true if (HasNameComponent) { // no validation is required, just capturing the value this.Name = NameComponent.Text; } // if still valid if ((isValid) && (HasEmailAddressComponent)) { // is this valid isValid = EmailAddressComponent.Validate(); // if not valid if (!isValid) { // Set the InvalidReason ValidationMessage = EmailAddressComponent.InvalidReason; } else { // next we must check if this is a valid email isValid = CheckValidEmail(EmailAddressComponent.Text); // if not valid if (!isValid) { // Set the text ValidationMessage = "Please enter a valid email address"; // set to false EmailAddressComponent.IsValid = false; } else { // Set the EmailAddress EmailAddress = EmailAddressComponent.Text; } } // if the Password exists if ((isValid) && (HasPasswordComponent)) { // validate this control isValid = PasswordComponent.Validate(); // if the value for isValid is false if (!isValid) { // Set the Validation Message ValidationMessage = PasswordComponent.InvalidReason; } else { // Set Password Password = PasswordComponent.Text; } } // if the Confirm Password exists if ((isValid) && (HasConfirmPasswordComponent)) { // validate this control isValid = ConfirmPasswordComponent.Validate(); // if the value for isValid is false if (!isValid) { // Set the Validation Message ValidationMessage = ConfirmPasswordComponent.InvalidReason; } else { // Set Password2 Password2 = ConfirmPasswordComponent.Text; } } // if still valid if (isValid) { // next we must check that the two passwords match if (!TextHelper.IsEqual(Password, Password2, true, true)) { // set to false isValid = false; // Set the failed reason ValidationMessage = "The passwords do not match"; // verify both components exist if ((HasPasswordComponent) && (HasConfirmPasswordComponent)) { // set both to not valid PasswordComponent.IsValid = false; ConfirmPasswordComponent.IsValid = false; } } } } // return value return(isValid); }
public InputBuilder <Input <string>, string, string> WithConfirmation() { Confirm = new ConfirmPasswordComponent(Console, this); return(this); }