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

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

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

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

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

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

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

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

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

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

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

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

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

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

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