Browse Source

Adding some missing tests to Schema Guards.

pull/254/head
Derek Begnoche 8 years ago
parent
commit
ae79f60f91
  1. 2
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs
  2. 24
      tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs
  3. 9
      tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs

2
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)));
}

24
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<ValidationException>(() => 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<ValidationException>(() => 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<ValidationException>(() => 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<ValidationException>(() => GuardSchemaField.CanAdd(schema_0, command));
}
[Fact]
public void CanAdd_should_throw_exception_if_partitioning_not_valid()
{

9
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<ValidationException>(() => 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<long> { 1, 2 } };

Loading…
Cancel
Save