Browse Source

Merge pull request #254 from dsbegnoche/master

Adding some missing tests to Schema Guards.
pull/260/head
Sebastian Stehle 9 years ago
committed by GitHub
parent
commit
d0db82dea6
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  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))); 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))); 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); 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] [Fact]
public void CanAdd_should_throw_exception_if_field_already_exists() 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)); 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] [Fact]
public void CanAdd_should_throw_exception_if_partitioning_not_valid() 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] [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() public void CanReorder_should_not_throw_exception_if_field_ids_are_valid()
{ {
var command = new ReorderFields { FieldIds = new List<long> { 1, 2 } }; var command = new ReorderFields { FieldIds = new List<long> { 1, 2 } };

Loading…
Cancel
Save