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

            var result = sut.RemoveDeletedReferences(JValue.CreateNull(), null);

            Assert.Null(result);
        }
        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);
        }
        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" });
        }
        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);
        }
        public void Should_return_list_with_schema_id_for_referenced_ids_when_other_type()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant, new ReferencesFieldProperties {
                SchemaId = schemaId
            });

            var result = sut.GetReferencedIds("invalid").ToArray();

            Assert.Equal(new[] { schemaId }, result);
        }
        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 reference(s)" });
        }
        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" });
        }
        public void Should_remove_deleted_references()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

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

            var result = sut.RemoveDeletedReferences(CreateValue(id1, id2), new HashSet <Guid>(new[] { id2 }));

            Assert.Equal(CreateValue(id1), result);
        }
        public void Should_return_same_token_when_removing_references_and_nothing_to_remove()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

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

            var token  = CreateValue(id1, id2);
            var result = sut.RemoveDeletedReferences(token, new HashSet <Guid>(new[] { Guid.NewGuid() }));

            Assert.Same(token, result);
        }
Exemplo n.º 10
0
        public void Should_remove_all_references_when_schema_is_removed()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

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

            var result = sut.RemoveDeletedReferences(CreateValue(id1, id2), new HashSet <Guid>(new[] { schemaId }));

            Assert.Equal(CreateValue(), result);
        }
Exemplo n.º 11
0
        public void Should_return_ids()
        {
            var id1 = Guid.NewGuid();
            var id2 = Guid.NewGuid();

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

            var result = sut.GetReferencedIds(CreateValue(id1, id2)).ToArray();

            Assert.Equal(new[] { id1, id2, schemaId }, result);
        }
Exemplo n.º 12
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}'" });
        }
Exemplo n.º 13
0
        public void Should_clone_object()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant);

            Assert.NotEqual(sut, sut.Enable());
        }
Exemplo n.º 14
0
        public void Should_instantiate_field()
        {
            var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant);

            Assert.Equal("my-refs", sut.Name);
        }