public void ShouldHaveErrorWhenTimeNotValid(int hours, int minutes, int seconds, bool expectedValid, int expectedNumberOfErrors) { var time = new BerlinTime(hours, minutes, seconds); var validationResult = _validator.Validate(time); validationResult.IsValid.Should().Be(expectedValid); validationResult.Errors.Should().HaveCount(expectedNumberOfErrors); }
public FluentValidation.Results.ValidationResult Validar(ITimeService service) { TimeValidator validator = new TimeValidator(service); var results = validator.Validate(this); return(results); }
protected override bool CheckSaveEligibility() { if (dateValidator.Validate() && timeValidator.Validate()) { return(true); } return(false); }
public void Validate() { reqDATE.Enabled = true; valDATE.Enabled = true; valTIME.Enabled = true; // 04/15/2006 Paul. The error message is not binding properly. Just assign here as a quick solution. // 06/09/2006 Paul. Now that we have solved the data binding issues, we can let the binding fill the message. //valDATE.ErrorMessage = L10n.Term(".ERR_INVALID_DATE"); reqDATE.Validate(); // 08/31/2006 Paul. Enable and perform date validation. valDATE.Validate(); valTIME.Validate(); }
public void InserirTime(Time timao) { var validator = new TimeValidator(); var validRes = validator.Validate(timao); if (validRes.IsValid) { listaTimes.Add(timao); } else { throw new Exception(validRes.Errors.FirstOrDefault().ToString()); } }
protected void Page_Command(Object sender, CommandEventArgs e) { if (e.CommandName == "NewRecord") { reqNAME.Enabled = true; reqDATE_START.Enabled = true; reqTIME_START.Enabled = true; valDATE_START.Enabled = true; valTIME_START.Enabled = true; reqNAME.Validate(); reqDATE_START.Validate(); reqTIME_START.Validate(); valDATE_START.Validate(); valTIME_START.Validate(); if (Page.IsValid) { Guid gID = Guid.Empty; try { // 02/28/2006 Paul. The easiest way to parse the two separate date/time fields is to combine the text. DateTime dtDATE_START = T10n.ToServerTime(Sql.ToDateTime(ctlDATE_START.DateText + " " + txtTIME_START.Text)); if (radScheduleCall.Checked) { SqlProcs.spCALLS_New(ref gID, txtNAME.Text, dtDATE_START); } else { SqlProcs.spMEETINGS_New(ref gID, txtNAME.Text, dtDATE_START); } } catch (Exception ex) { SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message); lblError.Text = ex.Message; } if (!Sql.IsEmptyGuid(gID)) { if (radScheduleCall.Checked) { Response.Redirect("~/Calls/view.aspx?ID=" + gID.ToString()); } else { Response.Redirect("~/Meetings/view.aspx?ID=" + gID.ToString()); } } } } }
public string ValidationMsg() { // If we have no text to validate... if (String.IsNullOrEmpty(_attachedTextControl.Text.Trim())) { if (_required) { return("Please enter a value into " + _nomenclature); } return(String.Empty); } // If we got here then there is text to validate if (_attachedTextControl.Text == _originalText) { // Assume the original text is in the proper validation style if (_validationStyle == ValidationStyle.NoOriginalValue) { return("Please enter a different value into " + _nomenclature); } return(String.Empty); } // Okay, we have something to validate and its not the original value... string returnMsg = String.Empty; TextValidator validator; string errSuffix = " into " + _nomenclature; switch (_validationStyle) { case ValidationStyle.NoValidation: returnMsg = String.Empty; break; case ValidationStyle.DateAny: validator = new DateValidator(DateStyle.DontCare); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DateFuture: validator = new DateValidator(DateStyle.Future); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DatePast: validator = new DateValidator(DateStyle.Past); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DigitsOnly: validator = new DigitsValidator(DigitStyle.DigitsOnly); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.DigitsNotZero: validator = new DigitsValidator(DigitStyle.DigitsNotZero); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.Money: validator = new DigitsValidator(DigitStyle.Money); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.MoneyNotZero: validator = new DigitsValidator(DigitStyle.MoneyNotZero); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.Percentage: validator = new DigitsValidator(DigitStyle.Percentage); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.PercentageNotZero: validator = new DigitsValidator(DigitStyle.PercentageNotZero); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.PhoneNumber: validator = new PhoneNumberValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.EmailAddr: validator = new PureTextValidator(PureTextStyle.EmailAddress); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.StateAbbreviation: validator = new PureTextValidator(PureTextStyle.StateAbbreviation); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.NoWhiteSpace: validator = new PureTextValidator(PureTextStyle.NoWhiteSpace); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.NoPunctuation: validator = new PureTextValidator(PureTextStyle.NoPunctuation); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.NoWhiteSpaceAndNoPunct: validator = new PureTextValidator(PureTextStyle.NoWhiteSpaceAndNoPunct); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.SSN: validator = new SSNValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.Time: validator = new TimeValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; case ValidationStyle.ZipPlus4: validator = new ZipCodeValidator(); returnMsg = validator.Validate(_attachedTextControl.Text); if (returnMsg.Length > 0) { returnMsg = returnMsg + errSuffix; } break; } return(returnMsg); }
public void IfIncorrectInput_ThrowExceptions(string data) { Assert.Throws <ArgumentException>(() => TimeValidator.Validate(data)); }
public void IfCorrectInput_DoesNotThrowExceptions(string data) { TimeValidator.Validate(data); }