예제 #1
0
        public async Task Should_not_add_error_if_string_is_valid()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                Label = "<FIELD>"
            });

            await sut.ValidateAsync(CreateValue(null), errors);

            Assert.Empty(errors);
        }
예제 #2
0
        public async Task Should_add_errors_if_string_not_allowed()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                AllowedValues = ImmutableList.Create("Foo")
            });

            await sut.ValidateAsync(CreateValue("Bar"), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is not an allowed value" });
        }
예제 #3
0
        public async Task Should_add_errors_if_string_is_longer_than_max_length()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                MaxLength = 5
            });

            await sut.ValidateAsync(CreateValue("12345678"), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> must have less than '5' characters" });
        }
예제 #4
0
        public async Task Should_add_errors_if_string_is_shorter_than_min_length()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                MinLength = 10
            });

            await sut.ValidateAsync(CreateValue("123"), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> must have more than '10' characters" });
        }
예제 #5
0
        public async Task Should_add_errors_if_string_is_required()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                IsRequired = true
            });

            await sut.ValidateAsync(CreateValue(null), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is required" });
        }
예제 #6
0
        public async Task Should_add_errors_if_number_is_not_valid_pattern_with_message()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                Pattern = "[0-9]{3}", PatternMessage = "Custom Error Message"
            });

            await sut.ValidateAsync(CreateValue("abc"), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "Custom Error Message" });
        }
예제 #7
0
        public async Task Should_add_errors_if_number_is_not_valid_pattern()
        {
            var sut = new StringField(1, "my-string", new StringFieldProperties {
                Pattern = "[0-9]{3}"
            });

            await sut.ValidateAsync(CreateValue("abc"), errors);

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