Browse Source

Guard tests.

pull/297/head
Sebastian 8 years ago
parent
commit
0f83a5fa07
  1. 22
      src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateNestedSchemaField.cs
  2. 3
      src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchemaField.cs
  3. 2
      src/Squidex.Domain.Apps.Entities/Schemas/Commands/ReorderFields.cs
  4. 2
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/FieldPropertiesValidator.cs
  5. 64
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs
  6. 39
      src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchemaField.cs
  7. 4
      src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs
  8. 4
      src/Squidex.Domain.Apps.Events/Schemas/SchemaCreatedField.cs
  9. 11
      src/Squidex.Infrastructure/ValidationError.cs
  10. 33
      tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ArrayFieldPropertiesTests.cs
  11. 176
      tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs
  12. 104
      tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs

22
src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateNestedSchemaField.cs

@ -0,0 +1,22 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using Squidex.Domain.Apps.Core.Schemas;
namespace Squidex.Domain.Apps.Entities.Schemas.Commands
{
public sealed class CreateNestedSchemaField
{
public string Name { get; set; }
public bool IsHidden { get; set; }
public bool IsDisabled { get; set; }
public FieldProperties Properties { get; set; }
}
}

3
src/Squidex.Domain.Apps.Entities/Schemas/Commands/CreateSchemaField.cs

@ -6,6 +6,7 @@
// ==========================================================================
using Squidex.Domain.Apps.Core.Schemas;
using FieldNested = System.Collections.Generic.List<Squidex.Domain.Apps.Entities.Schemas.Commands.CreateNestedSchemaField>;
namespace Squidex.Domain.Apps.Entities.Schemas.Commands
{
@ -21,6 +22,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Commands
public bool IsDisabled { get; set; }
public FieldNested Nested { get; set; }
public FieldProperties Properties { get; set; }
}
}

2
src/Squidex.Domain.Apps.Entities/Schemas/Commands/ReorderFields.cs

@ -11,6 +11,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Commands
{
public sealed class ReorderFields : SchemaCommand
{
public long? ParentFieldId { get; set; }
public List<long> FieldIds { get; set; }
}
}

2
src/Squidex.Domain.Apps.Entities/Schemas/Guards/FieldPropertiesValidator.cs

@ -22,7 +22,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
public static IEnumerable<ValidationError> Validate(FieldProperties properties)
{
return properties?.Accept(Instance) ?? Enumerable.Empty<ValidationError>();
return properties?.Accept(Instance);
}
public IEnumerable<ValidationError> Visit(ArrayFieldProperties properties)

64
src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchema.cs

@ -20,7 +20,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{
Guard.NotNull(command, nameof(command));
return Validate.It(() => "Cannot create schema.", async error =>
return Validate.It(() => "Cannot create schema.", (System.Func<System.Action<ValidationError>, Task>)(async (System.Action<ValidationError> error) =>
{
if (!command.Name.IsSlug())
{
@ -32,12 +32,14 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
error(new ValidationError($"A schema with name '{command.Name}' already exists", nameof(command.Name)));
}
if (command.Fields != null && command.Fields.Any())
if (command.Fields?.Count > 0)
{
var index = 0;
foreach (var field in command.Fields)
{
index++;
var prefix = $"Fields.{index}";
if (!field.Partitioning.IsValidPartitioning())
@ -54,12 +56,57 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{
error(new ValidationError("Properties is required.", $"{prefix}.{nameof(field.Properties)}"));
}
else
{
var errors = FieldPropertiesValidator.Validate(field.Properties);
var propertyErrors = FieldPropertiesValidator.Validate(field.Properties);
foreach (var e in errors)
{
error(e.WithPrefix(prefix));
}
}
foreach (var propertyError in propertyErrors)
if (field.Nested?.Count > 0)
{
error(propertyError);
if (!(field.Properties is ArrayFieldProperties))
{
error(new ValidationError("Only array fields can have nested fields.", $"{prefix}.{nameof(field.Partitioning)}"));
}
else
{
var nestedIndex = 0;
foreach (var nestedField in field.Nested)
{
nestedIndex++;
var nestedPrefix = $"Fields.{index}.Nested.{nestedIndex}";
if (!nestedField.Name.IsPropertyName())
{
error(new ValidationError("Name must be a valid property name.", $"{prefix}.{nameof(nestedField.Name)}"));
}
if (nestedField.Properties == null)
{
error(new ValidationError("Properties is required.", $"{prefix}.{nameof(nestedField.Properties)}"));
}
else
{
var errors = FieldPropertiesValidator.Validate(nestedField.Properties);
foreach (var e in errors)
{
error(e.WithPrefix(nestedPrefix));
}
}
}
}
if (field.Nested.Select(x => x.Name).Distinct().Count() != field.Nested.Count)
{
error(new ValidationError("Fields cannot have duplicate names.", $"{prefix}.Nested"));
}
}
}
@ -68,13 +115,18 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
error(new ValidationError("Fields cannot have duplicate names.", nameof(command.Fields)));
}
}
});
}));
}
public static void CanReorder(Schema schema, ReorderFields command)
{
Guard.NotNull(command, nameof(command));
if (command.ParentFieldId.HasValue && !schema.FieldsById.ContainsKey(command.ParentFieldId.Value))
{
throw new DomainObjectNotFoundException(command.ParentFieldId.ToString(), "Fields", typeof(Schema));
}
Validate.It(() => "Cannot reorder schema fields.", error =>
{
if (command.FieldIds == null)

39
src/Squidex.Domain.Apps.Entities/Schemas/Guards/GuardSchemaField.cs

@ -5,6 +5,7 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Linq;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Schemas.Commands;
@ -34,12 +35,14 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{
error(new ValidationError("Properties is required.", nameof(command.Properties)));
}
var propertyErrors = FieldPropertiesValidator.Validate(command.Properties);
foreach (var propertyError in propertyErrors)
else
{
error(propertyError);
var errors = FieldPropertiesValidator.Validate(command.Properties);
foreach (var e in errors)
{
error(e.WithPrefix(nameof(command.Properties)));
}
}
if (schema.FieldsByName.ContainsKey(command.Name))
@ -53,27 +56,29 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{
Guard.NotNull(command, nameof(command));
var field = GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId);
if (field.IsLocked)
{
throw new DomainException("Schema field is already locked.");
}
Validate.It(() => "Cannot update field.", error =>
{
if (command.Properties == null)
{
error(new ValidationError("Properties is required.", nameof(command.Properties)));
}
var propertyErrors = FieldPropertiesValidator.Validate(command.Properties);
foreach (var propertyError in propertyErrors)
else
{
error(propertyError);
var errors = FieldPropertiesValidator.Validate(command.Properties);
foreach (var e in errors)
{
error(e.WithPrefix(nameof(command.Properties)));
}
}
});
var field = GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId);
if (field.IsLocked)
{
throw new DomainException("Schema field is already locked.");
}
}
public static void CanDelete(Schema schema, DeleteField command)

4
src/Squidex.Domain.Apps.Entities/Schemas/State/SchemaState.cs

@ -87,9 +87,9 @@ namespace Squidex.Domain.Apps.Entities.Schemas.State
var field = registry.CreateRootField(TotalFields, eventField.Name, partitioning, eventField.Properties);
if (field is ArrayField arrayField && eventField.Children?.Count > 0)
if (field is ArrayField arrayField && eventField.Nested?.Count > 0)
{
foreach (var nestedEventField in eventField.Children)
foreach (var nestedEventField in eventField.Nested)
{
TotalFields++;

4
src/Squidex.Domain.Apps.Events/Schemas/SchemaCreatedField.cs

@ -6,7 +6,7 @@
// ==========================================================================
using Squidex.Domain.Apps.Core.Schemas;
using FieldChildren = System.Collections.Generic.List<Squidex.Domain.Apps.Events.Schemas.SchemaCreatedNestedField>;
using FieldNested = System.Collections.Generic.List<Squidex.Domain.Apps.Events.Schemas.SchemaCreatedNestedField>;
namespace Squidex.Domain.Apps.Events.Schemas
{
@ -22,7 +22,7 @@ namespace Squidex.Domain.Apps.Events.Schemas
public bool IsDisabled { get; set; }
public FieldChildren Children { get; set; }
public FieldNested Nested { get; set; }
public FieldProperties Properties { get; set; }
}

11
src/Squidex.Infrastructure/ValidationError.cs

@ -6,6 +6,7 @@
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
namespace Squidex.Infrastructure
{
@ -33,5 +34,15 @@ namespace Squidex.Infrastructure
this.propertyNames = propertyNames ?? FallbackProperties;
}
public ValidationError WithPrefix(string prefix)
{
if (propertyNames.Length > 0)
{
return new ValidationError(Message, propertyNames.Select(x => $"{prefix}.{x}").ToArray());
}
return this;
}
}
}

33
tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/FieldProperties/ArrayFieldPropertiesTests.cs

@ -0,0 +1,33 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschränkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System.Collections.Generic;
using System.Linq;
using FluentAssertions;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Infrastructure;
using Xunit;
namespace Squidex.Domain.Apps.Entities.Schemas.Guards.FieldProperties
{
public class ArrayFieldPropertiesTests
{
[Fact]
public void Should_add_error_if_min_items_greater_than_max_items()
{
var sut = new ArrayFieldProperties { MinItems = 10, MaxItems = 5 };
var errors = FieldPropertiesValidator.Validate(sut).ToList();
errors.ShouldBeEquivalentTo(
new List<ValidationError>
{
new ValidationError("Max items must be greater than min items.", "MinItems", "MaxItems")
});
}
}
}

176
tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaFieldTests.cs

@ -5,6 +5,8 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Collections.Generic;
using Squidex.Domain.Apps.Core;
using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Schemas.Commands;
@ -12,6 +14,7 @@ using Squidex.Infrastructure;
using Xunit;
#pragma warning disable SA1310 // Field names must not contain underscore
#pragma warning disable SA1401 // Fields must be private
namespace Squidex.Domain.Apps.Entities.Schemas.Guards
{
@ -26,145 +29,126 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
schema_0 =
new Schema("my-schema")
.AddString(1, "field1", Partitioning.Invariant)
.AddString(2, "field2", Partitioning.Invariant);
.AddString(2, "field2", Partitioning.Invariant)
.AddArray(3, "field3", Partitioning.Invariant, f => f
.AddNumber(301, "field301"));
}
[Fact]
public void CanHide_should_throw_exception_if_already_hidden()
private static Action<Schema, T> A<T>(Action<Schema, T> method) where T : FieldCommand
{
var command = new HideField { FieldId = 1 };
var schema_1 = schema_0.UpdateField(1, f => f.Hide());
Assert.Throws<DomainException>(() => GuardSchemaField.CanHide(schema_1, command));
return new Action<Schema, T>(method);
}
[Fact]
public void CanHide_should_throw_exception_if_not_found()
private static Func<Schema, Schema> S(Func<Schema, Schema> method)
{
var command = new HideField { FieldId = 3 };
Assert.Throws<DomainObjectNotFoundException>(() => GuardSchemaField.CanHide(schema_0, command));
return new Func<Schema, Schema>(method);
}
[Fact]
public void CanHide_hould_not_throw_exception_if_visible()
public static IEnumerable<object[]> FieldCommandData = new[]
{
var command = new HideField { FieldId = 1 };
new object[] { A<EnableField>(GuardSchemaField.CanEnable) },
new object[] { A<DeleteField>(GuardSchemaField.CanDelete) },
new object[] { A<DisableField>(GuardSchemaField.CanDisable) },
new object[] { A<HideField>(GuardSchemaField.CanHide) },
new object[] { A<LockField>(GuardSchemaField.CanLock) },
new object[] { A<ShowField>(GuardSchemaField.CanShow) },
new object[] { A<UpdateField>(GuardSchemaField.CanUpdate) }
};
GuardSchemaField.CanHide(schema_0, command);
}
[Fact]
public void CanDisable_should_throw_exception_if_already_disabled()
public static IEnumerable<object[]> InvalidStates = new[]
{
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_not_found()
{
var command = new DisableField { FieldId = 3 };
Assert.Throws<DomainObjectNotFoundException>(() => GuardSchemaField.CanDisable(schema_0, command));
}
[Fact]
public void CanDisable_Should_not_throw_exception_if_enabled()
{
var command = new DisableField { FieldId = 1 };
GuardSchemaField.CanDisable(schema_0, command);
}
new object[] { A<EnableField>(GuardSchemaField.CanEnable), S(s => s) },
new object[] { A<DisableField>(GuardSchemaField.CanDisable), S(s => s.DisableField(1)) },
new object[] { A<HideField>(GuardSchemaField.CanHide), S(s => s.HideField(1)) },
new object[] { A<LockField>(GuardSchemaField.CanLock), S(s => s.LockField(1)) },
new object[] { A<ShowField>(GuardSchemaField.CanShow), S(s => s.LockField(1)) }
};
[Fact]
public void CanShow_should_throw_exception_if_already_shown()
public static IEnumerable<object[]> InvalidNestedStates = new[]
{
var command = new ShowField { FieldId = 1 };
Assert.Throws<DomainException>(() => GuardSchemaField.CanShow(schema_0, command));
}
new object[] { A<EnableField>(GuardSchemaField.CanEnable), S(s => s) },
new object[] { A<DisableField>(GuardSchemaField.CanDisable), S(s => s.DisableField(301, 3)) },
new object[] { A<HideField>(GuardSchemaField.CanHide), S(s => s.HideField(301, 3)) },
new object[] { A<ShowField>(GuardSchemaField.CanShow), S(s => s) }
};
[Fact]
public void CanShow_should_throw_exception_if_not_found()
public static IEnumerable<object[]> ValidStates = new[]
{
var command = new ShowField { FieldId = 3 };
new object[] { A<EnableField>(GuardSchemaField.CanEnable), S(s => s.DisableField(1)) },
new object[] { A<DisableField>(GuardSchemaField.CanDisable), S(s => s) },
new object[] { A<HideField>(GuardSchemaField.CanHide), S(s => s) },
new object[] { A<ShowField>(GuardSchemaField.CanShow), S(s => s.HideField(1)) }
};
Assert.Throws<DomainObjectNotFoundException>(() => GuardSchemaField.CanShow(schema_0, command));
}
[Fact]
public void CanShow_should_not_throw_exception_if_hidden()
public static IEnumerable<object[]> ValidNestedStates = new[]
{
var command = new ShowField { FieldId = 1 };
var schema_1 = schema_0.UpdateField(1, f => f.Hide()); ;
GuardSchemaField.CanShow(schema_1, command);
}
new object[] { A<EnableField>(GuardSchemaField.CanEnable), S(s => s.DisableField(301, 3)) },
new object[] { A<DisableField>(GuardSchemaField.CanDisable), S(s => s) },
new object[] { A<HideField>(GuardSchemaField.CanHide), S(s => s) },
new object[] { A<ShowField>(GuardSchemaField.CanShow), S(s => s.HideField(301, 3)) }
};
[Fact]
public void CanEnable_should_throw_exception_if_already_enabled()
[Theory]
[MemberData(nameof(FieldCommandData))]
public void Commands_should_throw_exception_if_field_not_found<T>(Action<Schema, T> action) where T : FieldCommand, new()
{
var command = new EnableField { FieldId = 1 };
var command = new T { FieldId = 4 };
Assert.Throws<DomainException>(() => GuardSchemaField.CanEnable(schema_0, command));
Assert.Throws<DomainObjectNotFoundException>(() => action(schema_0, command));
}
[Fact]
public void CanEnable_should_throw_exception_if_not_found()
[Theory]
[MemberData(nameof(FieldCommandData))]
public void Commands_should_throw_exception_if_parent_field_not_found<T>(Action<Schema, T> action) where T : FieldCommand, new()
{
var command = new EnableField { FieldId = 3 };
var command = new T { ParentFieldId = 4, FieldId = 401 };
Assert.Throws<DomainObjectNotFoundException>(() => GuardSchemaField.CanEnable(schema_0, command));
Assert.Throws<DomainObjectNotFoundException>(() => action(schema_0, command));
}
[Fact]
public void CanEnable_should_not_throw_exception_if_disabled()
[Theory]
[MemberData(nameof(FieldCommandData))]
public void Commands_should_throw_exception_if_child_field_not_found<T>(Action<Schema, T> action) where T : FieldCommand, new()
{
var command = new EnableField { FieldId = 1 };
var command = new T { ParentFieldId = 3, FieldId = 302 };
var schema_1 = schema_0.UpdateField(1, f => f.Disable());
GuardSchemaField.CanEnable(schema_1, command);
Assert.Throws<DomainObjectNotFoundException>(() => action(schema_0, command));
}
[Fact]
public void CanLock_should_throw_exception_if_already_locked()
[Theory]
[MemberData(nameof(InvalidStates))]
public void Commands_should_throw_exception_if_state_not_valid<T>(Action<Schema, T> action, Func<Schema, Schema> updater) where T : FieldCommand, new()
{
var command = new LockField { FieldId = 1 };
var command = new T { FieldId = 1 };
var schema_1 = schema_0.UpdateField(1, f => f.Lock());
Assert.Throws<DomainException>(() => GuardSchemaField.CanLock(schema_1, command));
Assert.Throws<DomainException>(() => action(updater(schema_0), command));
}
[Fact]
public void LockField_should_throw_exception_if_not_found()
[Theory]
[MemberData(nameof(InvalidNestedStates))]
public void Commands_should_throw_exception_if_nested_state_not_valid<T>(Action<Schema, T> action, Func<Schema, Schema> updater) where T : FieldCommand, new()
{
var command = new LockField { FieldId = 3 };
var command = new T { ParentFieldId = 3, FieldId = 301 };
Assert.Throws<DomainObjectNotFoundException>(() => GuardSchemaField.CanLock(schema_0, command));
Assert.Throws<DomainException>(() => action(updater(schema_0), command));
}
[Fact]
public void CanLock_should_not_throw_exception_if_not_locked()
[Theory]
[MemberData(nameof(ValidStates))]
public void Commands_should_not_throw_exception_if_state_valid<T>(Action<Schema, T> action, Func<Schema, Schema> updater) where T : FieldCommand, new()
{
var command = new LockField { FieldId = 1 };
var command = new T { FieldId = 1 };
GuardSchemaField.CanLock(schema_0, command);
action(updater(schema_0), command);
}
[Fact]
public void CanDelete_should_throw_exception_if_not_found()
[Theory]
[MemberData(nameof(ValidNestedStates))]
public void Commands_should_not_throw_exception_if_nested_state_valid<T>(Action<Schema, T> action, Func<Schema, Schema> updater) where T : FieldCommand, new()
{
var command = new DeleteField { FieldId = 3 };
var command = new T { ParentFieldId = 3, FieldId = 301 };
Assert.Throws<DomainObjectNotFoundException>(() => GuardSchemaField.CanDelete(schema_0, command));
action(updater(schema_0), command);
}
[Fact]
@ -262,7 +246,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 = "field3", Properties = new StringFieldProperties() };
var command = new AddField { Name = "field4", Properties = new StringFieldProperties() };
GuardSchemaField.CanAdd(schema_0, command);
}

104
tests/Squidex.Domain.Apps.Entities.Tests/Schemas/Guards/GuardSchemaTests.cs

@ -74,6 +74,44 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
Name = null,
Properties = InvalidProperties(),
Partitioning = "invalid"
},
new CreateSchemaField
{
Name = null,
Properties = new ArrayFieldProperties(),
Partitioning = "invalid",
Nested = new List<CreateNestedSchemaField>
{
new CreateNestedSchemaField
{
Name = null,
Properties = InvalidProperties()
},
new CreateNestedSchemaField
{
Name = null,
Properties = InvalidProperties()
}
}
},
new CreateSchemaField
{
Name = null,
Properties = InvalidProperties(),
Partitioning = "invalid",
Nested = new List<CreateNestedSchemaField>
{
new CreateNestedSchemaField
{
Name = null,
Properties = InvalidProperties()
},
new CreateNestedSchemaField
{
Name = null,
Properties = InvalidProperties()
}
}
}
},
Name = "new-schema"
@ -101,6 +139,25 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
Name = "field1",
Properties = ValidProperties(),
Partitioning = "invariant"
},
new CreateSchemaField
{
Name = "field1",
Properties = new ArrayFieldProperties(),
Partitioning = "invariant",
Nested = new List<CreateNestedSchemaField>
{
new CreateNestedSchemaField
{
Name = "nested1",
Properties = ValidProperties()
},
new CreateNestedSchemaField
{
Name = "nested1",
Properties = ValidProperties()
}
}
}
},
Name = "new-schema"
@ -112,7 +169,45 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
[Fact]
public Task CanCreate_should_not_throw_exception_if_command_is_valid()
{
var command = new CreateSchema { AppId = appId, Name = "new-schema" };
var command = new CreateSchema
{
AppId = appId,
Fields = new List<CreateSchemaField>
{
new CreateSchemaField
{
Name = "field1",
Properties = ValidProperties(),
Partitioning = "invariant"
},
new CreateSchemaField
{
Name = "field2",
Properties = ValidProperties(),
Partitioning = "invariant"
},
new CreateSchemaField
{
Name = "field3",
Properties = new ArrayFieldProperties(),
Partitioning = "invariant",
Nested = new List<CreateNestedSchemaField>
{
new CreateNestedSchemaField
{
Name = "nested1",
Properties = ValidProperties()
},
new CreateNestedSchemaField
{
Name = "nested2",
Properties = ValidProperties()
}
}
}
},
Name = "new-schema"
};
return GuardSchema.CanCreate(command, appProvider);
}
@ -178,7 +273,14 @@ namespace Squidex.Domain.Apps.Entities.Schemas.Guards
}
[Fact]
public void CanReorder_should_throw_exception_if_parent_field_not_found()
{
var command = new ReorderFields { FieldIds = new List<long> { 1, 2 }, ParentFieldId = 99 };
Assert.Throws<DomainObjectNotFoundException>(() => 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