public void Init() { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-us"); validator = new DateValidator(); validator.Initialize(new CachedValidationRegistry(), typeof(TestTarget).GetProperty("DtField")); target = new TestTarget(); }
public IActionResult SetCurrentActionPlanResourceCompleteByDate( int learningLogItemId, EditCompleteByDateFormData formData ) { if (!ModelState.IsValid) { var model = new EditCompleteByDateViewModel(formData, learningLogItemId); return(View("Current/SetCompleteByDate", model)); } var completeByDate = DateValidator.IsDateNull(formData.Day, formData.Month, formData.Year) ? (DateTime?)null : new DateTime(formData.Year !.Value, formData.Month !.Value, formData.Day !.Value); actionPlanService.SetCompleteByDate(learningLogItemId, completeByDate); return(RedirectToAction("Current")); }
public void ValidateDate_returns_appropriate_error_if_some_values_invalid( int day, int month, int year, bool dayError, bool monthError, bool yearError, string errorMessageEnding ) { // When var result = DateValidator.ValidateDate(day, month, year); // Then result.HasDayError.Should().Be(dayError); result.HasMonthError.Should().Be(monthError); result.HasYearError.Should().Be(yearError); result.ErrorMessage.Should().Be("Enter a Date containing a real " + errorMessageEnding); }
public IActionResult SetCurrentCourseCompleteByDate( int id, int progressId, EditCompleteByDateFormData formData ) { if (!ModelState.IsValid) { var model = new EditCompleteByDateViewModel(formData, id, progressId); return(View("Current/SetCompleteByDate", model)); } var completeByDate = DateValidator.IsDateNull(formData.Day, formData.Month, formData.Year) ? (DateTime?)null : new DateTime(formData.Year !.Value, formData.Month !.Value, formData.Day !.Value); courseDataService.SetCompleteByDate(progressId, User.GetCandidateIdKnownNotNull(), completeByDate); return(RedirectToAction("Current")); }
public void Then_correct_errors_are_returned(string input, bool isValid) { var validator = new DateValidator { ValidationDefinition = new ValidationDefinition() { ErrorMessage = "Not a valid Date", Name = "Date" } }; var question = new Question { QuestionId = "Q1" }; var errors = validator.Validate(question, new Answer { Value = input, QuestionId = question.QuestionId }); (errors.Count is 0).Should().Be(isValid); }
private void ValidateStartDate(List <ValidationResult> validationResults) { var startDateValidationResults = DateValidator.ValidateDate( StartDay, StartMonth, StartYear, "Start date", true, false, true ) .ToValidationResultList(nameof(StartDay), nameof(StartMonth), nameof(StartYear)); if (!startDateValidationResults.Any()) { ValidateStartDateIsAfterDataStart(startDateValidationResults); } validationResults.AddRange(startDateValidationResults); }
protected override void SetData() { base.SetData(); DateValidator dateHandler = FindObjectOfType <DateValidator>(); int[] date = dateHandler.GetDate_int(); string[] slots = FindObjectOfType <CalendarViewController>().RequestEmptySlots(new System.DateTime(date[2], date[1], date[0])); slotterTranslation = (slots.Length - 1) / 2 * -30; if (slots != null && slots.Length > 0) { foreach (string s in slots) { Spawn(s); } slotContainer.GetComponent <RectTransform>().localPosition += (new Vector3(0, slotterTranslation, 0)); button.GetComponent <UnityEngine.UI.Image>().sprite = collapse; } else { button.SetActive(false); } }
private static void Main(string[] args) { if (args.Length == 0) { Console.WriteLine("No input arguments"); return; } if (!DateValidator.IsValid(args[0], out DateTime firstDate)) { Console.WriteLine("First date is invalid"); return; } if (!DateValidator.IsValid(args[1], out DateTime secondDate)) { Console.WriteLine("Second date is invalid"); return; } if (DateValidator.IsSame(firstDate, secondDate)) { Console.WriteLine("Dates are the same"); return; } if (DateValidator.IsGreater(firstDate, secondDate)) { Console.WriteLine("First date is later than second"); return; } var calculatedDate = new DateBuilder(firstDate, secondDate).CalculateDates(); Console.WriteLine(calculatedDate); Console.ReadKey(); }
public IHttpActionResult Put(ProductEdit product) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var service = CreateProductService(); var prodDetail = service.ValidateAuctionStatus(product.ProductId); if (prodDetail == "") { var result = new DateValidator(product.ProductCloseTime); bool validateAllProperties = false; var results = new List <ValidationResult>(); bool isValid = Validator.TryValidateObject(result, new ValidationContext(result, null, null), results, validateAllProperties); if (!isValid) { string errorMessage = ""; foreach (var item in results) { errorMessage = item + ", "; } return(BadRequest(errorMessage)); } if (!service.UpdateProduct(product)) { return(InternalServerError()); } return(Ok("Product succesfully updated.")); } return(BadRequest(prodDetail)); }
public void Do_Validator_Valid_Years_Properly() { Date validYear = new Date { Day = 1, Month = 1, Year = 1960 }; Date invalidYear = new Date { Day = 1, Month = 1, Year = -100 }; IDateValidator target = new DateValidator(); bool validDateResult = target.DateValidate(validYear.Year, validYear.Month, validYear.Day); bool invalidDateResult = target.DateValidate(invalidYear.Year, invalidYear.Month, invalidYear.Day); Assert.IsTrue(validDateResult); Assert.IsFalse(invalidDateResult); }
public void SitoTestMethod() { DateValidator validator = new DateValidator(); Assert.IsFalse(validator.DateValidate(2014, 13, 31)); Assert.IsFalse(validator.DateValidate(2014, 12, 32)); Assert.IsTrue(validator.DateValidate(2014, 12, 31)); Assert.IsFalse(validator.DateValidate(2014, 04, 31)); Assert.IsFalse(validator.DateValidate(2015, 02, 29)); Assert.IsFalse(validator.DateValidate(2014, 13, 31)); Assert.IsFalse(validator.DateValidate(2014, 12, 32)); Assert.IsTrue(validator.DateValidate(2014, 12, 30)); Assert.IsFalse(validator.DateValidate(2014, 09, 32)); Assert.IsTrue(validator.DateValidate(2014, 06, 10)); Assert.IsTrue(validator.DateValidate(2014, 12, 31)); Assert.IsFalse(validator.DateValidate(2014, 02, 29)); Assert.IsTrue(validator.DateValidate(2014, 02, 28)); Assert.IsFalse(validator.DateValidate(2014, 04, 31)); Assert.IsFalse(validator.DateValidate(2014, 13, 31)); Assert.IsFalse(validator.DateValidate(2014, 12, 32)); Assert.IsTrue(validator.DateValidate(2014, 12, 31)); Assert.IsFalse(validator.DateValidate(2014, 04, 31)); Assert.IsFalse(validator.DateValidate(2015, 02, 29)); }
public StartDateAfterLatestStartDateException(DateValidator dv) : base(dv, "Contract start date", dv.StartDate, "must be earlier than latest start date for this contract", dv.LatestStartDate) { }
public StartDateBeforeEarliestStartDateException(DateValidator dv) : base(dv, "Contract start date", dv.StartDate, "must be later than earliest start date for this contract", dv.EarliestStartDate) { }
public StartDateBeforeEndDateException(DateValidator dv) : base(dv, "Contract start date", dv.StartDate, "must be later than contract end date", dv.EndDate) { }
public void DatePropertyShouldBeEqualDefaultValue() { DateValidator dateValidator = new DateValidator(correctDate); Assert.AreEqual(defaultClassDate, dateValidator.Date); }
public DateValidatorShould() { _sut = new DateValidator(); }
public static IRuleBuilder <T> Date <T>(this IRuleBuilder <T> ruleBuilder) where T : class { ruleBuilder.AddRule(DateValidator <T> .New(ruleBuilder)); return(ruleBuilder); }
// If NE tab visible, create Eingangsrechnung AND Buchungszeile. Otherwise, only create Buchungszeile to current Eingangsrechnung private void AddBuchungszeile(object sender, EventArgs e) { this.eingangsrechnungMsgLabel.Text = string.Empty; this.eingangsrechnungMsgLabel.Hide(); // in case of new Eingangsrechnung, the input fields are not locked if (!this.eingangsrechnungBezeichnungTextBox.ReadOnly == true) { this.logger.Log(Logger.Level.Info, "Beginning with new Eingangsrechnung"); // create new Eingangsrechnung this.eingangsrechnung = new EingangsrechnungTable(); // check Eingangsrechnungs input fields if (this.existingKontakteComboBox.SelectedIndex < 1) { this.eingangsrechnungMsgLabel.Text = "Keine KundenID gewählt!"; this.eingangsrechnungMsgLabel.ForeColor = Color.Red; this.eingangsrechnungMsgLabel.Show(); return; } // get KontaktID out of Combobox string kontaktID = this.existingKontakteComboBox.SelectedItem.ToString(); this.eingangsrechnung.KontaktID = -1; try { this.eingangsrechnung.KontaktID = GlobalActions.GetIdFromCombobox(kontaktID, this.eingangsrechnungMsgLabel); } catch (InvalidInputException) { logger.Log(Logger.Level.Error, "Unknown Exception while getting ID from Projekte from AngeboteTab!"); } // check for valid KontaktID IRule posint = new PositiveIntValidator(); DataBindingFramework.BindFromInt(this.eingangsrechnung.KontaktID.ToString(), "KontaktID", this.eingangsrechnungMsgLabel, false, posint); // check other vals eingangsrechnung.Rechnungsdatum = this.eingangsrechnungDatePicker.Value.ToShortDateString(); eingangsrechnung.Bezeichnung = this.eingangsrechnungBezeichnungTextBox.Text; // check date IRule dateval = new DateValidator(); DataBindingFramework.BindFromString(eingangsrechnung.Rechnungsdatum, "Datum", this.eingangsrechnungMsgLabel, false, dateval); // check description IRule lnhsv = new LettersNumbersHyphenSpaceValidator(); IRule slv = new StringLength150Validator(); DataBindingFramework.BindFromString(eingangsrechnung.Bezeichnung, "Bez. Eingangsrechnung", this.eingangsrechnungMsgLabel, false, lnhsv, slv); // add Archivierungspfad // Year/Month/Date/KontaktID/Bezeichnung eingangsrechnung.Archivierungspfad = DateTime.Now.Year.ToString() + '/' + DateTime.Now.Month.ToString() + '/' + DateTime.Now.ToShortDateString() + '-' + this.eingangsrechnung.KontaktID + '-' + this.eingangsrechnung.Bezeichnung; // check for errors if (this.eingangsrechnungMsgLabel.Visible) { return; } } // save Buchungszeile this.AddBuchungszeileToDataGridView(); // lock Eingangsrechnungs elements, if not already done if (!this.eingangsrechnungBezeichnungTextBox.ReadOnly == true) { this.existingKontakteComboBox.Enabled = false; this.eingangsrechnungDatePicker.Enabled = false; this.eingangsrechnungBezeichnungTextBox.ReadOnly = true; this.logger.Log(Logger.Level.Info, "Locked Eingangsrechnungs-elements"); } }
public void GivenInValidDateShouldThrowException(string startDate, string endDate) { var dateValidator = new DateValidator(); Assert.Throws <Exception>(() => dateValidator.FormatDate(startDate, endDate)); }
protected viewValidations getDataForView(int viewId) { //we get all the relevant fields for this view var viewFields = GetFieldsForView(viewId); //we find the date fields var dataFields = (from field in viewFields where field.dataType == Constants.TIMEPICKER || field.dataType == Constants.DATEPICKER || field.dataType == Constants.EDITTEXT || field.dataType == Constants.CHECKBOX || field.dataType == Constants.RADIOBUTTON select field).ToList(); var context = this; var valueFields = new List <FieldValuePair>(); var validationIssues = new List <DataValidationIssue>(); foreach (var field in dataFields) { var resultObject = new FieldValuePair() { Field = field, Value = string.Empty }; var fieldView = new ValidationObject() { isRequired = field.IsRequired, label = field.Label, //value = view.Text, //viewId = view.Id, validation = field.validation }; switch (field.dataType) { case Constants.TIMEPICKER: case Constants.DATEPICKER: { var view = field.GetDataView <EditText>(this); fieldView.value = view.Text; fieldView.viewId = view.Id; fieldView.viewObject = view; var validationResult = DateValidator.validates(fieldView); clearError(view); if (validationResult != null) { validationIssues.Add(validationResult); } if (string.IsNullOrWhiteSpace(view.Text)) { continue; } resultObject.Value = view.Text; break; } case Constants.EDITTEXT: { var view = field.GetDataView <EditText>(this); fieldView.value = view.Text; fieldView.viewId = view.Id; fieldView.viewObject = view; clearError(view); var validationResult = TextValidator.validates(fieldView); if (validationResult != null) { validationIssues.Add(validationResult); } if (string.IsNullOrWhiteSpace(view.Text)) { continue; } resultObject.Value = view.Text; break; } case Constants.CHECKBOX: { var view = field.GetDataView <CheckBox>(this); if (!view.Checked) { continue; } resultObject.Value = Constants.DEFAULT_CHECKED; break; } case Constants.RADIOBUTTON: { var view = field.GetDataView <RadioButton>(this); if (view == null) { view = field.GetDataView <RadioButton>(this); } if (!view.Checked) { continue; } resultObject.Value = Constants.DEFAULT_CHECKED; break; } default: { throw new ArgumentNullException("Could not find view for field " + field.name); } } if (string.IsNullOrWhiteSpace(resultObject.Value)) { throw new ArgumentNullException("Could not find view for field " + field.name); } valueFields.Add(resultObject); } return(new viewValidations() { TemporalViewData = valueFields, Validations = validationIssues }); }
public void Do_Validator_Valid_Days_Properly() { Date validDayMarz = new Date { Day = 31, Month = 3, Year = 1960 }; Date validDayApril = new Date { Day = 30, Month = 4, Year = 1960 }; Date validDayFeb = new Date { Day = 28, Month = 2, Year = 2003 }; Date validDayFebLeapYear = new Date { Day = 28, Month = 2, Year = 2000 }; Date invalidDayMarz = new Date { Day = 32, Month = 3, Year = 1960 }; Date invalidDayApril = new Date { Day = 31, Month = 4, Year = 1960 }; Date invalidDayFeb = new Date { Day = 29, Month = 2, Year = 2003 }; Date invalidDayFebLeapYear = new Date { Day = 30, Month = 2, Year = 2000 }; IDateValidator target = new DateValidator(); bool validDateMarzResult = target.DateValidate(validDayMarz.Year, validDayMarz.Month, validDayMarz.Day); bool validDateAprilResult = target.DateValidate(validDayApril.Year, validDayApril.Month, validDayApril.Day); bool validDateFebResult = target.DateValidate(validDayFeb.Year, validDayFeb.Month, validDayFeb.Day); bool validDateFebLeapYearResult = target.DateValidate(validDayFebLeapYear.Year, validDayFebLeapYear.Month, validDayFebLeapYear.Day); bool invalidDateMarzResult = target.DateValidate(invalidDayMarz.Year, invalidDayMarz.Month, invalidDayMarz.Day); bool invalidDateAprilResult = target.DateValidate(invalidDayApril.Year, invalidDayApril.Month, invalidDayApril.Day); bool invalidDateFebResult = target.DateValidate(invalidDayFeb.Year, invalidDayFeb.Month, invalidDayFeb.Day); bool invalidDateFebLeapYearResult = target.DateValidate(invalidDayFebLeapYear.Year, invalidDayFebLeapYear.Month, invalidDayFebLeapYear.Day); Assert.IsTrue(validDateMarzResult); Assert.IsTrue(validDateAprilResult); Assert.IsTrue(validDateFebResult); Assert.IsTrue(validDateFebLeapYearResult); Assert.IsFalse(invalidDateMarzResult); Assert.IsFalse(invalidDateAprilResult); Assert.IsFalse(invalidDateFebResult); Assert.IsFalse(invalidDateFebLeapYearResult); }
public void ShouldReturnFalseForCorrectDateDouble() { Validator dateValidator = new DateValidator(dateDouble); Assert.IsFalse(dateValidator.Validate()); }
public EndDateBeforeEarliestEndDateException(DateValidator dv) : base(dv, "Contract end date", dv.EndDate, "must be later than earliest end date for this contract", dv.EarliestEndDate) { }
public bool Test_DateValidator(int minDate, int maxDate, int value) { var validator = new DateValidator(minDate, maxDate); return(validator.Validate(value.ToString())); }
public EndDateAfterLatestEndDateException(DateValidator dv) : base(dv, "Contract end date", dv.EndDate, "must be earlier than latest end date for this contract", dv.LatestEndDate) { }
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); }
/// <summary> /// The method validates whether a supplied object is a valid DateTime entity. /// </summary> /// <param name="objectToValidate">An object to be valdiated whether it is a dateime value.</param> /// <returns>True - if object is valid, false - if object is invalid.</returns> public static bool IsDateTime(object objectToValidate) { Validator validator = new DateValidator(objectToValidate); return(validator.Validate()); }
public void ShouldReturnErrorMessage() { var validator = new DateValidator(); validator.GetErrorMessage().Should().Be("Answer accepts only dates."); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { return(DateValidator.ValidateDate(Day, Month, Year, "Email delivery date", true) .ToValidationResultList(nameof(Day), nameof(Month), nameof(Year))); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { return(DateValidator.ValidateDate(Day, Month, Year, "complete by date") .ToValidationResultList(nameof(Day), nameof(Month), nameof(Year))); }
public DateValidatorTests() { metadata = new DisplayNameMetadataProvider().GetMetadataForProperty(null, typeof(AccountView), "Username"); validator = new DateValidator(metadata, new ControllerContext()); }
public void ShouldReturnTrueForCorrectDate() { Validator dateValidator = new DateValidator(correctDate); Assert.IsTrue(dateValidator.Validate()); }