Ejemplo n.º 1
0
        public async Task EnableField_should_create_events_and_update_state_for_array()
        {
            var command = new EnableField {
                ParentFieldId = 1, FieldId = 2
            };

            await ExecuteCreateAsync();
            await ExecuteAddArrayFieldAsync();
            await ExecuteAddFieldAsync(fieldName, 1);
            await ExecuteDisableFieldAsync(2, 1);

            var result = await sut.ExecuteAsync(CreateCommand(command));

            result.ShouldBeEquivalent(new EntitySavedResult(4));

            Assert.False(GetField(1).IsDisabled);
            Assert.False(GetNestedField(1, 2).IsDisabled);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new FieldEnabled {
                ParentFieldId = arrayId, FieldId = nestedId
            })
                );
        }
Ejemplo n.º 2
0
        public void CanEnable_should_throw_exception_if_not_found()
        {
            var command = new EnableField {
                FieldId = 3
            };

            Assert.Throws <DomainObjectNotFoundException>(() => GuardSchemaField.CanEnable(schema_0, command));
        }
Ejemplo n.º 3
0
        public void CanEnable_should_throw_exception_if_ui_field()
        {
            var command = new EnableField {
                FieldId = 4
            };

            Assert.Throws <DomainException>(() => GuardSchemaField.CanEnable(command, schema_0));
        }
Ejemplo n.º 4
0
        public SchemaDomainObject EnableField(EnableField command)
        {
            VerifyCreatedAndNotDeleted();

            RaiseEvent(command, new FieldEnabled());

            return(this);
        }
Ejemplo n.º 5
0
        public void CanEnable_should_throw_exception_if_already_enabled()
        {
            var command = new EnableField {
                FieldId = 1
            };

            Assert.Throws <DomainException>(() => GuardSchemaField.CanEnable(schema_0, command));
        }
Ejemplo n.º 6
0
        public static void CanEnable(Schema schema, EnableField command)
        {
            var field = GetFieldOrThrow(schema, command.FieldId);

            if (!field.IsDisabled)
            {
                throw new DomainException("Schema field is already enabled.");
            }
        }
Ejemplo n.º 7
0
        protected Task On(EnableField command, CommandContext context)
        {
            return(handler.UpdateSyncedAsync <SchemaDomainObject>(context, s =>
            {
                GuardSchemaField.CanEnable(s.Snapshot.SchemaDef, command);

                s.EnableField(command);
            }));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> EnableNestedField(string app, string name, long parentId, long id)
        {
            var command = new EnableField {
                ParentFieldId = parentId, FieldId = id
            };

            var response = await InvokeCommandAsync(app, command);

            return(Ok(response));
        }
Ejemplo n.º 9
0
        public void CanEnable_should_not_throw_exception_if_disabled()
        {
            var command = new EnableField {
                FieldId = 1
            };

            var schema_1 = schema_0.DisableField(1);

            GuardSchemaField.CanEnable(schema_1, command);
        }
Ejemplo n.º 10
0
        public void CanEnable_should_throw_exception_if_locked()
        {
            var command = new EnableField {
                FieldId = 1
            };

            var schema_1 = schema_0.UpdateField(1, f => f.Lock());

            Assert.Throws <DomainException>(() => GuardSchemaField.CanEnable(command, schema_1));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> EnableField(string app, string name, long id)
        {
            var command = new EnableField {
                FieldId = id
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Ejemplo n.º 12
0
        public void CanShow_should_not_throw_exception_if_already_shown()
        {
            var command = new EnableField {
                FieldId = 1
            };

            var schema_1 = schema_0.UpdateField(1, f => f.Show());

            GuardSchemaField.CanEnable(command, schema_1);
        }
Ejemplo n.º 13
0
        public async Task <IActionResult> EnableField(string app, string name, long id)
        {
            var command = new EnableField {
                FieldId = id
            };

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
Ejemplo n.º 14
0
        public void CanEnable_should_not_throw_exception_if_disabled()
        {
            var command = new EnableField {
                FieldId = 1
            };

            schema.FieldsById[1].Disable();

            GuardSchemaField.CanEnable(schema, command);
        }
Ejemplo n.º 15
0
        public static void CanEnable(EnableField command, Schema schema)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsForApi(true))
            {
                throw new DomainException(T.Get("schemas.uiFieldCannotBeEnabled"));
            }
        }
Ejemplo n.º 16
0
        public static void CanEnable(EnableField command, Schema schema)
        {
            Guard.NotNull(command);

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsForApi(true))
            {
                throw new DomainException("UI field cannot be enabled.");
            }
        }
Ejemplo n.º 17
0
        public static void CanEnable(Schema schema, EnableField command)
        {
            Guard.NotNull(command, nameof(command));

            var field = GuardHelper.GetFieldOrThrow(schema, command.FieldId, command.ParentFieldId, false);

            if (!field.IsDisabled)
            {
                throw new DomainException("Schema field is already enabled.");
            }
        }
Ejemplo n.º 18
0
        public SchemaDomainObject EnableField(EnableField command)
        {
            Guard.NotNull(command, nameof(command));

            VerifyCreatedAndNotDeleted();

            SchemaFieldGuard.GuardCanEnable(schema, command.FieldId);

            RaiseEvent(command, new FieldEnabled());

            return(this);
        }
Ejemplo n.º 19
0
        public async Task EnableField_should_create_events_and_update_state()
        {
            var command = new EnableField { FieldId = 1 };

            await ExecuteCreateAsync();
            await ExecuteAddFieldAsync(fieldName);
            await ExecuteDisableFieldAsync(1);

            var result = await sut.ExecuteAsync(CreateCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.False(GetField(1).IsDisabled);

            LastEvents
                .ShouldHaveSameEvents(
                    CreateEvent(new FieldEnabled { FieldId = fieldId })
                );
        }
Ejemplo n.º 20
0
        public async Task EnableField_should_create_events_and_update_nested_field_disabled_flag()
        {
            var command = new EnableField {
                ParentFieldId = 1, FieldId = 2
            };

            await ExecuteCreateAsync();
            await ExecuteAddArrayFieldAsync();
            await ExecuteAddFieldAsync(fieldName, 1);
            await ExecuteDisableFieldAsync(2, 1);

            var result = await PublishAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.False(GetNestedField(1, 2).IsDisabled);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new FieldEnabled {
                ParentFieldId = arrayId, FieldId = nestedId
            })
                );
        }
Ejemplo n.º 21
0
 public void EnableField(EnableField command)
 {
     RaiseEvent(command, new FieldEnabled());
 }
Ejemplo n.º 22
0
 private void EnableField(EnableField command)
 {
     Raise(command, new FieldEnabled());
 }
 protected Task On(EnableField command, CommandContext context)
 {
     return(handler.UpdateAsync <SchemaDomainObject>(context, s => s.EnableField(command)));
 }