public void UiDateTimeDateValidationFails() { _timeZoneName = TimeZoneInfo.FindSystemTimeZoneById("Mountain Standard Time").StandardName; var model = new ValidationTestUiDateTimeModel { BasicDateTime = new UiDateTimeModel(_timeZoneName) { LocalDate = "1/15/" } }; var testContext = new ValidationContext(model, null, null) { DisplayName = "BasicDateTime" }; var attribute = new UiDateTimeFormatDateValidation("LocalDate"); try { attribute.Validate(model.BasicDateTime.LocalDate, testContext); Assert.Fail("Exception not thrown"); } catch (ValidationException ex) { Assert.AreEqual("'Date' does not exist or is improperly formated: MM/DD/YYYY.", ex.Message); } catch (Exception) { Assert.Fail("Unexpected Exception thrown"); } }
public void UiDateTimeDateValidationPasses() { var model = new ValidationTestUiDateTimeModel { BasicDateTime = new UiDateTimeModel(_timeZoneName) { LocalDate = "1/14/2100" } }; var testContext = new ValidationContext(model, null, null) { DisplayName = "BasicDateTime" }; var attribute = new UiDateTimeFormatDateValidation("LocalDate"); try { attribute.Validate(model.BasicDateTime.LocalDate, testContext); } catch (Exception ex) { Assert.Fail("Unexpected Exception thrown: " + ex.Message); } }