|
|
|
@ -32,7 +32,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
.AddString(1, "field1", Partitioning.Invariant) |
|
|
|
.AddString(2, "field2", Partitioning.Invariant) |
|
|
|
.AddArray(3, "field3", Partitioning.Invariant, f => f |
|
|
|
.AddNumber(301, "field301")); |
|
|
|
.AddNumber(301, "field301")) |
|
|
|
.AddUI(4, "field4", Partitioning.Invariant); |
|
|
|
} |
|
|
|
|
|
|
|
private static Action<Schema, T> A<T>(Action<Schema, T> method) where T : FieldCommand |
|
|
|
@ -163,6 +164,32 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanDelete(schema_1, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanDisable_should_throw_exception_if_already_disabled() |
|
|
|
{ |
|
|
|
var command = new DisableField { FieldId = 1 }; |
|
|
|
|
|
|
|
var schema_1 = schema_0.UpdateField(1, f => f.Disable()); |
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanDisable(schema_1, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanDisable_should_throw_exception_if_ui_field() |
|
|
|
{ |
|
|
|
var command = new DisableField { FieldId = 4 }; |
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanDisable(schema_0, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanEnable_should_throw_exception_if_already_enabled() |
|
|
|
{ |
|
|
|
var command = new EnableField { FieldId = 1 }; |
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanEnable(schema_0, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanHide_should_throw_exception_if_locked() |
|
|
|
{ |
|
|
|
@ -173,6 +200,32 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanHide(schema_1, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanHide_should_throw_exception_if_already_hidden() |
|
|
|
{ |
|
|
|
var command = new HideField { FieldId = 1 }; |
|
|
|
|
|
|
|
var schema_1 = schema_0.UpdateField(1, f => f.Hide()); |
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanHide(schema_1, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanHide_should_throw_exception_if_ui_field() |
|
|
|
{ |
|
|
|
var command = new HideField { FieldId = 4 }; |
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanHide(schema_0, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanShow_should_throw_exception_if_already_visible() |
|
|
|
{ |
|
|
|
var command = new ShowField { FieldId = 4 }; |
|
|
|
|
|
|
|
Assert.Throws<DomainException>(() => GuardSchemaField.CanShow(schema_0, command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanDelete_should_not_throw_exception_if_not_locked() |
|
|
|
{ |
|
|
|
@ -199,6 +252,15 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
GuardSchemaField.CanUpdate(schema_0, command); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanUpdate_should_throw_exception_if_marking_a_ui_field_as_list_field() |
|
|
|
{ |
|
|
|
var command = new UpdateField { FieldId = 4, Properties = new UIFieldProperties { IsListField = true } }; |
|
|
|
|
|
|
|
ValidationAssert.Throws(() => GuardSchemaField.CanUpdate(schema_0, command), |
|
|
|
new ValidationError("UI field cannot be a list field.", "Properties.IsListField")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanUpdate_should_throw_exception_if_properties_null() |
|
|
|
{ |
|
|
|
@ -247,7 +309,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
[Fact] |
|
|
|
public void CanAdd_should_throw_exception_if_properties_not_valid() |
|
|
|
{ |
|
|
|
var command = new AddField { Name = "field4", Properties = invalidProperties }; |
|
|
|
var command = new AddField { Name = "field5", Properties = invalidProperties }; |
|
|
|
|
|
|
|
ValidationAssert.Throws(() => GuardSchemaField.CanAdd(schema_0, command), |
|
|
|
new ValidationError("Max length must be greater or equal to min length.", "Properties.MinLength", "Properties.MaxLength")); |
|
|
|
@ -256,7 +318,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
[Fact] |
|
|
|
public void CanAdd_should_throw_exception_if_properties_null() |
|
|
|
{ |
|
|
|
var command = new AddField { Name = "field4", Properties = null }; |
|
|
|
var command = new AddField { Name = "field5", Properties = null }; |
|
|
|
|
|
|
|
ValidationAssert.Throws(() => GuardSchemaField.CanAdd(schema_0, command), |
|
|
|
new ValidationError("Properties is required.", "Properties")); |
|
|
|
@ -265,12 +327,21 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
[Fact] |
|
|
|
public void CanAdd_should_throw_exception_if_partitioning_not_valid() |
|
|
|
{ |
|
|
|
var command = new AddField { Name = "field4", Partitioning = "INVALID_PARTITIONING", Properties = validProperties }; |
|
|
|
var command = new AddField { Name = "field5", Partitioning = "INVALID_PARTITIONING", Properties = validProperties }; |
|
|
|
|
|
|
|
ValidationAssert.Throws(() => GuardSchemaField.CanAdd(schema_0, command), |
|
|
|
new ValidationError("Partitioning is not a valid value.", "Partitioning")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanAdd_should_throw_exception_if_creating_a_ui_field_as_list_field() |
|
|
|
{ |
|
|
|
var command = new AddField { Name = "field5", Properties = new UIFieldProperties { IsListField = true } }; |
|
|
|
|
|
|
|
ValidationAssert.Throws(() => GuardSchemaField.CanAdd(schema_0, command), |
|
|
|
new ValidationError("UI field cannot be a list field.", "Properties.IsListField")); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void CanAdd_should_throw_exception_if_parent_not_exists() |
|
|
|
{ |
|
|
|
@ -282,7 +353,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards |
|
|
|
[Fact] |
|
|
|
public void CanAdd_should_not_throw_exception_if_field_not_exists() |
|
|
|
{ |
|
|
|
var command = new AddField { Name = "field4", Properties = validProperties }; |
|
|
|
var command = new AddField { Name = "field5", Properties = validProperties }; |
|
|
|
|
|
|
|
GuardSchemaField.CanAdd(schema_0, command); |
|
|
|
} |
|
|
|
|