示例#1
0
        public async Task Should_not_add_error_if_references_are_null_and_valid()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant);

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

            Assert.Empty(errors);
        }
示例#2
0
        public async Task Should_add_errors_if_value_is_not_valid()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant);

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

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is not a valid value." });
        }
示例#3
0
        public async Task Should_not_add_error_if_references_are_valid()
        {
            var referenceId = Guid.NewGuid();

            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant);

            await sut.ValidateAsync(CreateValue(referenceId), errors, ValidationTestExtensions.ValidContext);

            Assert.Empty(errors);
        }
示例#4
0
        public async Task Should_add_errors_if_value_has_not_enough_items()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant, new ReferencesFieldProperties {
                SchemaId = schemaId, MinItems = 3
            });

            await sut.ValidateAsync(CreateValue(Guid.NewGuid(), Guid.NewGuid()), errors);

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> must have at least 3 item(s)." });
        }
示例#5
0
        public async Task Should_add_errors_if_references_are_required_and_empty()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant, new ReferencesFieldProperties {
                SchemaId = schemaId, IsRequired = true
            });

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

            errors.ShouldBeEquivalentTo(
                new[] { "<FIELD> is required." });
        }
示例#6
0
        public async Task Should_add_errors_if_reference_are_not_valid()
        {
            var referenceId = Guid.NewGuid();

            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant, new ReferencesFieldProperties {
                SchemaId = schemaId
            });

            await sut.ValidateAsync(CreateValue(referenceId), errors, ValidationTestExtensions.InvalidContext(referenceId));

            errors.ShouldBeEquivalentTo(
                new[] { $"<FIELD> contains invalid reference '{referenceId}'." });
        }