예제 #1
0
        public void ValidateCorrectly()
        {
            //--Arrange
            var model = new ModelWithEmailAddressFieldWithoutCustomErrorMessage
            {
                MultipleWordedField = "*****@*****.**"
            };
            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);
        }
예제 #2
0
        public void ConvertFieldNameToSnakeCaseIfSetInAppConfig()
        {
            //--Arrange
            var model = new ModelWithEmailAddressFieldWithoutCustomErrorMessage()
            {
                MultipleWordedField = "invalidemail"
            };
            var validationContext = new ValidationContext(model, null, null);
            var result            = new List <ValidationResult>();

            FormatResponseMessage.SetSnakeCaseSetting(true);

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

            //--Assert
            valid.ShouldBeFalse();
            result.Count.ShouldBe(1);
            const string defaultErrorMsg = "The 'multiple_worded_field' field is an invalid email address.";

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