예제 #1
0
        public async Task ChangeStatus_should_create_proposal_events_and_update_state()
        {
            var command = new ChangeContentStatus {
                Status = Status.Published
            };

            await ExecuteCreateAsync();
            await ExecutePublishAsync();
            await ExecuteProposeUpdateAsync();

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

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.False(sut.Snapshot.IsPending);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentChangesPublished())
                );

            A.CallTo(() => scriptEngine.Execute(A <ScriptContext> .Ignored, "<update-script>"))
            .MustNotHaveHappened();
        }
예제 #2
0
        public async Task Create_should_create_events_and_update_state()
        {
            var command = new CreateContent {
                Data = data
            };

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

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(Status.Draft, sut.Snapshot.Status);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentCreated {
                Data = data, Status = Status.Draft
            })
                );

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<create-script>"))
            .MustHaveHappened();
            A.CallTo(() => scriptEngine.Execute(A <ScriptContext> .Ignored, "<change-script>"))
            .MustNotHaveHappened();
        }
예제 #3
0
        public async Task ChangeStatus_should_create_events_and_update_state_when_archived()
        {
            var command = new ChangeContentStatus {
                Status = Status.Archived
            };

            await ExecuteCreateAsync();

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

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(Status.Archived, sut.Snapshot.Status);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentStatusChanged {
                Status = Status.Archived
            })
                );

            A.CallTo(() => scriptEngine.Execute(A <ScriptContext> .Ignored, "<change-script>"))
            .MustHaveHappened();
        }
예제 #4
0
        public async Task UpdateField_should_create_events_and_update_state_for_array()
        {
            var command = new UpdateField {
                ParentFieldId = 1, FieldId = 2, Properties = new StringFieldProperties()
            };

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

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

            result.ShouldBeEquivalent(new EntitySavedResult(3));

            Assert.NotEqual(command.Properties, GetField(1).RawProperties);
            Assert.Equal(command.Properties, GetNestedField(1, 2).RawProperties);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new FieldUpdated {
                ParentFieldId = arrayId, FieldId = nestedId, Properties = command.Properties
            })
                );
        }
예제 #5
0
        public async Task DeleteField_should_create_events_and_update_state_for_array()
        {
            var command = new DeleteField {
                ParentFieldId = 1, FieldId = 2
            };

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

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

            result.ShouldBeEquivalent(new EntitySavedResult(3));

            Assert.NotNull(GetField(1));
            Assert.Null(GetNestedField(1, 2));

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new FieldDeleted {
                ParentFieldId = arrayId, FieldId = nestedId
            })
                );
        }
예제 #6
0
        public async Task ChangeStatus_should_create_events_and_update_status_when_published()
        {
            var command = new ChangeContentStatus {
                Status = Status.Published
            };

            await ExecuteCreateAsync();

            var result = await PublishAsync(CreateContentCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(Status.Published, sut.Snapshot.CurrentVersion.Status);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentStatusChanged {
                Status = Status.Published, Change = StatusChange.Published
            })
                );

            A.CallTo(() => scriptEngine.ExecuteAsync(ScriptContext(data, null, Status.Published, Status.Draft), "<change-script>"))
            .MustHaveHappened();
        }
예제 #7
0
        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
            })
                );
        }
예제 #8
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 PublishAsync(command);

            result.ShouldBeEquivalent2(sut.Snapshot);

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

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new FieldEnabled {
                ParentFieldId = arrayId, FieldId = nestedId
            })
                );
        }
예제 #9
0
        public async Task Patch_should_create_events_and_update_data()
        {
            var command = new PatchContent {
                Data = patch
            };

            await ExecuteCreateAsync();

            var result = await PublishAsync(CreateContentCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.NotEqual(data, sut.Snapshot.CurrentVersion.Data);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentUpdated {
                Data = patched
            })
                );

            A.CallTo(() => scriptEngine.ExecuteAndTransformAsync(ScriptContext(patched, data, Status.Draft), "<update-script>"))
            .MustHaveHappened();
        }
        public async Task ChangePlan_from_callback_should_create_events_and_update_state()
        {
            var command = new ChangePlan {
                PlanId = planIdPaid, FromCallback = true
            };

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent(new EntitySavedResult(4));

            Assert.Equal(planIdPaid, sut.Snapshot.Plan !.PlanId);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new AppPlanChanged {
                PlanId = planIdPaid
            })
                );

            A.CallTo(() => appPlansBillingManager.ChangePlanAsync(A <string> .Ignored, A <NamedId <Guid> > .Ignored, A <string?> .Ignored))
            .MustNotHaveHappened();
        }
예제 #11
0
        public async Task Reorder_should_create_events_and_update_state_for_array()
        {
            var command = new ReorderFields {
                ParentFieldId = 1, FieldIds = new List <long> {
                    3, 2
                }
            };

            await ExecuteCreateAsync();
            await ExecuteAddArrayFieldAsync();
            await ExecuteAddFieldAsync("field1", 1);
            await ExecuteAddFieldAsync("field2", 1);

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent2(sut.Snapshot);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new SchemaFieldsReordered {
                ParentFieldId = arrayId, FieldIds = command.FieldIds
            })
                );
        }
        public async Task ChangePlan_should_create_events_and_update_state()
        {
            var command = new ChangePlan {
                PlanId = planIdPaid
            };

            A.CallTo(() => appPlansBillingManager.ChangePlanAsync(Actor.Identifier, AppNamedId, planIdPaid))
            .Returns(new PlanChangedResult());

            await ExecuteCreateAsync();

            var result = await PublishIdempotentAsync(command);

            Assert.True(result is PlanChangedResult);

            Assert.Equal(planIdPaid, sut.Snapshot.Plan !.PlanId);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new AppPlanChanged {
                PlanId = planIdPaid
            })
                );
        }
예제 #13
0
        public async Task Update_should_create_events_and_update_data()
        {
            var command = new UpdateContent {
                Data = otherData
            };

            await ExecuteCreateAsync();

            var result = await PublishAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(otherData, sut.Snapshot.CurrentVersion.Data);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentUpdated {
                Data = otherData
            })
                );

            A.CallTo(() => scriptEngine.TransformAsync(ScriptContext(otherData, data, Status.Draft), "<update-script>", ScriptOptions()))
            .MustHaveHappened();
        }
예제 #14
0
        public async Task Upsert_should_create_contnet_when_not_found()
        {
            var command = new UpsertContent {
                Data = data
            };

            var result = await PublishAsync(CreateContentCommand(command));

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Same(data, sut.Snapshot.CurrentVersion.Data);

            LastEvents
            .ShouldHaveSameEvents(
                CreateContentEvent(new ContentCreated {
                Data = data, Status = Status.Draft
            })
                );

            A.CallTo(() => scriptEngine.TransformAsync(ScriptContext(data, null, Status.Draft), "<create-script>", ScriptOptions()))
            .MustHaveHappened();
            A.CallTo(() => scriptEngine.ExecuteAsync(A <ScriptVars> ._, "<change-script>", ScriptOptions()))
            .MustNotHaveHappened();
        }
예제 #15
0
        public async Task ShowField_should_create_events_and_update_nested_field_hidden_flag()
        {
            var command = new ShowField {
                ParentFieldId = 1, FieldId = 2
            };

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

            var result = await PublishIdempotentAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

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

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new FieldShown {
                ParentFieldId = arrayId, FieldId = nestedId
            })
                );
        }
예제 #16
0
        public async Task Create_should_create_schema_and_create_events()
        {
            var properties = new SchemaProperties();

            var command = new CreateSchema {
                Name = SchemaName, SchemaId = SchemaId, Properties = properties
            };

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

            result.ShouldBeEquivalent(EntityCreatedResult.Create(Id, 0));

            Assert.Equal(AppId, sut.Snapshot.AppId.Id);

            Assert.Equal(SchemaName, sut.Snapshot.Name);
            Assert.Equal(SchemaName, sut.Snapshot.SchemaDef.Name);

            LastEvents
            .ShouldHaveSameEvents(
                CreateEvent(new SchemaCreated {
                Name = SchemaName, Properties = properties
            })
                );
        }