Browse Source
Merge pull request #254 from dsbegnoche/master
Adding some missing tests to Schema Guards.
pull/260/head
Sebastian Stehle
8 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
34 additions and
1 deletions
-
src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs
-
tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs
-
tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.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))); |
|
|
|
} |
|
|
|
|
|
|
|
@ -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() |
|
|
|
{ |
|
|
|
|
|
|
|
@ -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 } }; |
|
|
|
|