public SchemaDomainObject Reorder(ReorderFields command) { VerifyCreatedAndNotDeleted(); RaiseEvent(SimpleMapper.Map(command, new SchemaFieldsReordered())); return(this); }
public void CanReorder_should_throw_exception_if_field_ids_null() { var command = new ReorderFields { FieldIds = null }; Assert.Throws <ValidationException>(() => GuardSchema.CanReorder(schema_0, command)); }
protected Task On(ReorderFields command, CommandContext context) { return(handler.UpdateSyncedAsync <SchemaDomainObject>(context, s => { GuardSchema.CanReorder(s.Snapshot.SchemaDef, command); s.Reorder(command); })); }
public void CanReorder_should_throw_exception_if_field_ids_null() { var command = new ReorderFields { FieldIds = null }; ValidationAssert.Throws(() => GuardSchema.CanReorder(schema_0, command), new ValidationError("Field ids is required.", "FieldIds")); }
public SchemaDomainObject Reorder(ReorderFields command) { Guard.Valid(command, nameof(command), () => $"Cannot reorder fields for schema '{Id}'"); VerifyCreatedAndNotDeleted(); RaiseEvent(SimpleMapper.Map(command, new SchemaFieldsReordered())); return(this); }
public void CanReorder_should_throw_exception_if_field_ids_do_not_covers_all_fields() { var command = new ReorderFields { FieldIds = new List <long> { 1 } }; Assert.Throws <ValidationException>(() => GuardSchema.CanReorder(schema_0, command)); }
public void CanReorder_should_not_throw_exception_if_field_ids_are_valid() { var command = new ReorderFields { FieldIds = new List <long> { 1, 2 } }; GuardSchema.CanReorder(schema_0, command); }
public async Task <IActionResult> PutFieldOrdering(string app, string name, [FromBody] ReorderFields request) { var command = new ReorderFields { FieldIds = request.FieldIds }; await CommandBus.PublishAsync(command); return(NoContent()); }
public void CanReorder_should_throw_exception_if_field_ids_contains_invalid_id() { var command = new ReorderFields { FieldIds = new List <long> { 1, 3 } }; Assert.Throws <ValidationException>(() => GuardSchema.CanReorder(schema_0, command)); }
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)); }
public void CanReorder_should_throw_exception_if_field_ids_do_not_covers_all_fields() { var command = new ReorderFields { FieldIds = new List <long> { 1 } }; ValidationAssert.Throws(() => GuardSchema.CanReorder(schema_0, command), new ValidationError("Field ids do not cover all fields.", "FieldIds")); }
public static void CanReorder(Schema schema, ReorderFields command) { Guard.NotNull(command, nameof(command)); Validate.It(() => "Cannot reorder schema fields.", error => { if (command.FieldIds == null) { 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))) { error(new ValidationError("Ids must cover all fields.", nameof(command.FieldIds))); } }); }
public async Task Reorder_should_create_events_and_update_state() { var command = new ReorderFields { FieldIds = new List<long> { 1, 2 } }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync("field1"); await ExecuteAddFieldAsync("field2"); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaFieldsReordered { FieldIds = command.FieldIds }) ); }
public async Task Reorder_should_create_events_and_reorder_fields() { var command = new ReorderFields { FieldIds = new[] { 2L, 1L } }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync("field1"); await ExecuteAddFieldAsync("field2"); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaFieldsReordered { FieldIds = command.FieldIds }) ); }
public async Task Reorder_should_create_events_and_reorder_nestedy_fields() { var command = new ReorderFields { ParentFieldId = 1, FieldIds = new[] { 3L, 2L } }; await ExecuteCreateAsync(); await ExecuteAddArrayFieldAsync(); await ExecuteAddFieldAsync("field1", 1); await ExecuteAddFieldAsync("field2", 1); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaFieldsReordered { ParentFieldId = arrayId, FieldIds = command.FieldIds }) ); }
public static void CanReorder(Schema schema, ReorderFields command) { Guard.NotNull(command, nameof(command)); IArrayField arrayField = null; if (command.ParentFieldId.HasValue) { var parentId = command.ParentFieldId.Value; if (schema.FieldsById.TryGetValue(parentId, out var field) && field is IArrayField a) { arrayField = a; } else { throw new DomainObjectNotFoundException(parentId.ToString(), "Fields", typeof(Schema)); } } Validate.It(() => "Cannot reorder schema fields.", error => { if (command.FieldIds == null) { error(new ValidationError("Field ids is required.", nameof(command.FieldIds))); } if (arrayField == null) { CheckFields(error, command, schema.FieldsById); } else { CheckFields(error, command, arrayField.FieldsById); } }); }
public async Task Reorder_should_create_events_and_update_state_for_array() { var command = new ReorderFields { ParentFieldId = 1, FieldIds = new List <long> { 2, 3 } }; await ExecuteCreateAsync(); await ExecuteAddArrayFieldAsync(); await ExecuteAddFieldAsync("field1", 1); await ExecuteAddFieldAsync("field2", 1); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(4)); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaFieldsReordered { ParentFieldId = arrayId, FieldIds = command.FieldIds }) ); }
public void Reorder(ReorderFields command) { RaiseEvent(SimpleMapper.Map(command, new SchemaFieldsReordered { ParentFieldId = GetFieldId(command.ParentFieldId) })); }
public void Reorder(ReorderFields command) { RaiseEvent(command, new SchemaFieldsReordered()); }
private void Reorder(ReorderFields command) { Raise(command, new SchemaFieldsReordered()); }
public void Reorder(ReorderFields command) { RaiseEvent(SimpleMapper.Map(command, new SchemaFieldsReordered())); }
protected Task On(ReorderFields command, CommandContext context) { return(handler.UpdateAsync <SchemaDomainObject>(context, s => s.Reorder(command))); }