Ejemplo n.º 1
0
        public void ValidateCorrectlyForOptionalDate()
        {
            //--Arrange
            var model = new ModelWithDateTimeFieldWithoutCustomErrorMessage
            {
                CreatedDate = null
            };
            var validationContext = new ValidationContext(model, null, null);
            var result            = new List <ValidationResult>();

            //--Act
            var valid = Validator.TryValidateObject(model, validationContext, result, true);

            //--Assert
            valid.ShouldBeTrue();
            result.Count.ShouldBe(0);
        }
Ejemplo n.º 2
0
        public void InvalidateCorrectlyWithoutCustomErrorMessage()
        {
            //--Arrange
            var model = new ModelWithDateTimeFieldWithoutCustomErrorMessage
            {
                CreatedDate = "invalidDate"
            };
            var validationContext = new ValidationContext(model, null, null);
            var result            = new List <ValidationResult>();

            FormatResponseMessage.SetSnakeCaseSetting(false);

            //--Act
            var valid = Validator.TryValidateObject(model, validationContext, result, true);

            //--Assert
            valid.ShouldBeFalse();
            result.Count.ShouldBe(1);
            const string defaultErrorMsg = "The 'CreatedDate' must be in ISO-8601 format, (i.e. yyyy-mm-ddThh:mm:ss.ffffff).";

            result[0].ErrorMessage
            .ShouldBe(ModelStateCustomErrorMessage.Create(1, defaultErrorMsg));
        }