diff --git a/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs b/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs index c95bac2f6..fb59048a1 100644 --- a/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs +++ b/src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs @@ -82,7 +82,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards error(new ValidationError("Field ids is required.", nameof(command.FieldIds))); } - if (command.FieldIds.Count != schema.Fields.Count || command.FieldIds.Any(x => !schema.FieldsById.ContainsKey(x))) + if (command.FieldIds != null && (command.FieldIds.Count != schema.Fields.Count || command.FieldIds.Any(x => !schema.FieldsById.ContainsKey(x)))) { error(new ValidationError("Ids must cover all fields.", nameof(command.FieldIds))); } diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs index 3d121e8ab..7636f0faa 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs @@ -203,6 +203,22 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards GuardSchemaField.CanUpdate(schema_0, command); } + [Fact] + public void CanUpdate_should_throw_exception_if_properties_null() + { + var command = new UpdateField { FieldId = 2, Properties = null }; + + Assert.Throws(() => GuardSchemaField.CanUpdate(schema_0, command)); + } + + [Fact] + public void CanUpdate_should_throw_exception_if_properties_not_valid() + { + var command = new UpdateField { FieldId = 2, Properties = new StringFieldProperties { MinLength = 10, MaxLength = 5 } }; + + Assert.Throws(() => GuardSchemaField.CanUpdate(schema_0, command)); + } + [Fact] public void CanAdd_should_throw_exception_if_field_already_exists() { @@ -227,6 +243,14 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards Assert.Throws(() => GuardSchemaField.CanAdd(schema_0, command)); } + [Fact] + public void CanAdd_should_throw_exception_if_properties_null() + { + var command = new AddField { Name = "field3", Properties = null }; + + Assert.Throws(() => GuardSchemaField.CanAdd(schema_0, command)); + } + [Fact] public void CanAdd_should_throw_exception_if_partitioning_not_valid() { diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs index 407b72608..1f2bd3233 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs @@ -170,6 +170,15 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards } [Fact] + public void CanReorder_should_throw_exception_if_field_ids_null() + { + var command = new ReorderFields { FieldIds = null }; + + Assert.Throws(() => GuardSchema.CanReorder(schema_0, command)); + } + + [Fact] + public void CanReorder_should_not_throw_exception_if_field_ids_are_valid() { var command = new ReorderFields { FieldIds = new List { 1, 2 } };