예제 #1
0
        public async Task Should_not_add_error_if_value_is_empty()
        {
            var sut = new PatternValidator("[a-z]{3}:[0-9]{2}");

            await sut.ValidateAsync(string.Empty, errors);

            Assert.Empty(errors);
        }
예제 #2
0
        public async Task Should_add_timeout_error_when_regex_is_too_slow()
        {
            var sut = new PatternValidator(@"^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$");

            await sut.ValidateAsync("https://archiverbx.blob.core.windows.net/static/C:/Users/USR/Documents/Projects/PROJ/static/images/full/1234567890.jpg", errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Regex is too slow." });
        }
예제 #3
0
        public async Task Should_add_error_with_custom_message_if_value_is_not_valid()
        {
            var sut = new PatternValidator("[a-z]{3}:[0-9]{2}", "Custom Error Message.");

            await sut.ValidateAsync("foo", errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Custom Error Message." });
        }
예제 #4
0
        public async Task Should_add_error_with_default_message_if_value_is_not_valid()
        {
            var sut = new PatternValidator("[a-z]{3}:[0-9]{2}");

            await sut.ValidateAsync("foo", errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is not valid." });
        }