public void Should_return_null_from_references_field_when_removing_references_from_null_array() { var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant); var result = sut.CleanReferences(null, null); Assert.Null(result); }
public void Should_get_default_value_from_references_field() { var field = new ReferencesField(1, "1", Partitioning.Invariant, new ReferencesFieldProperties()); Assert.Equal(new JArray(), DefaultValueFactory.CreateDefaultValue(field, Now)); }
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 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)." }); }
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_return_list_from_references_field_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.ExtractReferences("invalid").ToArray(); Assert.Equal(new[] { schemaId }, result); }
public JsonProperty Visit(ReferencesField field) { return(CreateProperty(field, jsonProperty => { var itemSchema = schemaResolver("ReferenceItem", new JsonSchema4 { Type = JsonObjectType.String }); jsonProperty.Type = JsonObjectType.Array; jsonProperty.Item = itemSchema; })); }
public void Should_return_same_token_from_references_field_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.CleanReferences(token, new HashSet <Guid>(new[] { Guid.NewGuid() })); Assert.Same(token, result); }
private static JToken Visit(ReferencesField field, JToken value, ICollection <Guid> oldReferences) { if (oldReferences.Contains(field.Properties.SchemaId)) { return(new JArray()); } var oldIds = GetIds(value); var newIds = oldIds.Except(oldReferences).ToList(); return(oldIds.Count != newIds.Count ? JToken.FromObject(newIds) : value); }
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}'." }); }
public void Should_remove_all_references_from_references_field_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.CleanReferences(CreateValue(id1, id2), new HashSet <Guid>(new[] { schemaId })); Assert.Equal(CreateValue(), result); }
public void Should_return_ids_from_references_field() { var id1 = Guid.NewGuid(); var id2 = Guid.NewGuid(); var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant, new ReferencesFieldProperties { SchemaId = schemaId }); var result = sut.ExtractReferences(CreateValue(id1, id2)).ToArray(); Assert.Equal(new[] { id1, id2, schemaId }, result); }
private static IEnumerable <Guid> Visit(ReferencesField field, JToken value) { IEnumerable <Guid> result; try { result = value?.ToObject <List <Guid> >() ?? Enumerable.Empty <Guid>(); } catch { result = Enumerable.Empty <Guid>(); } return(result.Union(new[] { field.Properties.SchemaId })); }
public void Should_instantiate_field() { var sut = new ReferencesField(1, "my-refs", Partitioning.Invariant); Assert.Equal("my-refs", sut.Name); }
public IEdmTypeReference Visit(ReferencesField field) { return(CreatePrimitive(EdmPrimitiveTypeKind.String, field)); }
public object Visit(ReferencesField field) { return(Value.ToObject <List <Guid> >()); }