public async Task UpdateField_should_create_events_and_update_state() { var command = new UpdateField { FieldId = 1, Properties = new StringFieldProperties() }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync(fieldName); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(2)); Assert.Equal(command.Properties, sut.Snapshot.SchemaDef.FieldsById[1].RawProperties); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldUpdated { FieldId = fieldId, Properties = command.Properties }) ); }
public async Task Update_should_create_events_and_update_state() { var command = new RenameAssetFolder { FolderName = "New Name" }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateAssetFolderCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(command.FolderName, sut.Snapshot.FolderName); LastEvents .ShouldHaveSameEvents( CreateAssetFolderEvent(new AssetFolderRenamed { FolderName = command.FolderName }) ); }
public async Task UpdateField_should_create_events_and_update_field_properties() { var command = new UpdateField { FieldId = 1, Properties = new StringFieldProperties() }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync(fieldName); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(command.Properties, GetField(1).RawProperties); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldUpdated { FieldId = fieldId, Properties = command.Properties }) ); }
public async Task DeletePattern_should_create_events_and_update_pattern() { var command = new DeletePattern { PatternId = patternId3 }; await ExecuteCreateAsync(); await ExecuteAddPatternAsync(); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(initialPatterns.Count, sut.Snapshot.Patterns.Count); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppPatternDeleted { PatternId = patternId3 }) ); }
public async Task DeleteField_should_create_events_and_delete_field() { var command = new DeleteField { FieldId = 1 }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync(fieldName); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Null(GetField(1)); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldDeleted { FieldId = fieldId }) ); }
public async Task UpdateWorkflow_should_create_events_and_update_workflow() { var command = new UpdateWorkflow { WorkflowId = workflowId, Workflow = Workflow.Default }; await ExecuteCreateAsync(); await ExecuteAddWorkflowAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.NotEmpty(sut.Snapshot.Workflows); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppWorkflowUpdated { WorkflowId = workflowId, Workflow = Workflow.Default }) ); }
public async Task RemoveLanguage_should_create_events_and_remove_language() { var command = new RemoveLanguage { Language = Language.DE }; await ExecuteCreateAsync(); await ExecuteAddLanguageAsync(Language.DE); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.False(sut.Snapshot.LanguagesConfig.Contains(Language.DE)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppLanguageRemoved { Language = Language.DE }) ); }
public async Task RevokeClient_should_create_events_and_update_state() { var command = new RevokeClient { Id = clientId }; await ExecuteCreateAsync(); await ExecuteAttachClientAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(6)); Assert.False(sut.Snapshot.Clients.ContainsKey(clientId)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppClientRevoked { Id = clientId }) ); }
public async Task DeleteRole_should_create_events_and_update_state() { var command = new DeleteRole { Name = roleName }; await ExecuteCreateAsync(); await ExecuteAddRoleAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(6)); Assert.Equal(4, sut.Snapshot.Roles.Count); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppRoleDeleted { Name = roleName }) ); }
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(EntityCreatedResult.Create(data, 0)); LastEvents .ShouldHaveSameEvents( CreateContentEvent(new ContentCreated { Data = data }) ); A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<create-script>")) .MustHaveHappened(); A.CallTo(() => scriptEngine.Execute(A <ScriptContext> .Ignored, "<change-script>")) .MustNotHaveHappened(); }
public async Task Patch_should_not_create_event_for_same_data() { var command = new PatchContent { Data = data }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateContentCommand(command)); result.ShouldBeEquivalent(new ContentDataChangedResult(data, 0)); LastEvents .ShouldHaveSameEvents( CreateContentEvent(new ContentCreated { Data = data }) ); A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<update-script>")) .MustNotHaveHappened(); }
public async Task AssignContributor_should_create_update_events_and_update_state() { var command = new AssignContributor { ContributorId = contributorId, Role = Role.Owner }; await ExecuteCreateAsync(); await ExecuteAssignContributorAsync(); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(EntityCreatedResult.Create(contributorId, 6)); Assert.Equal(Role.Owner, sut.Snapshot.Contributors[contributorId]); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppContributorAssigned { ContributorId = contributorId, Role = Role.Owner }) ); }
public async Task DeleteField_should_create_events_and_update_state() { var command = new DeleteField { FieldId = 1 }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync(fieldName); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(2)); Assert.False(sut.Snapshot.SchemaDef.FieldsById.ContainsKey(1)); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldDeleted { FieldId = fieldId }) ); }
public async Task HideField_should_create_events_and_update_state() { var command = new HideField { FieldId = 1 }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync(fieldName); var result = await sut.ExecuteAsync(CreateCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(2)); Assert.True(sut.Snapshot.SchemaDef.FieldsById[1].IsHidden); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldHidden { FieldId = fieldId }) ); }
public async Task RemoveContributor_should_create_events_and_remove_contributor() { var command = new RemoveContributor { ContributorId = contributorId }; await ExecuteCreateAsync(); await ExecuteAssignContributorAsync(); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.False(sut.Snapshot.Contributors.ContainsKey(contributorId)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppContributorRemoved { ContributorId = contributorId }) ); }
public async Task Update_should_create_events_and_update_state() { var command = new UpdateContent { Data = otherData }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateContentCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateContentEvent(new ContentUpdated { Data = otherData }) ); A.CallTo(() => scriptEngine.ExecuteAndTransform(ScriptContext(otherData, data, Status.Draft), "<update-script>")) .MustHaveHappened(); }
public async Task RevokeClient_should_create_events_and_remove_client() { var command = new RevokeClient { Id = clientId }; await ExecuteCreateAsync(); await ExecuteAttachClientAsync(); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.False(sut.Snapshot.Clients.ContainsKey(clientId)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppClientRevoked { Id = clientId }) ); }
public async Task Update_should_create_events_and_update_state() { var command = MakeUpdateCommand(); await ExecuteCreateAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent2(new EntitySavedResult(1)); Assert.Same(command.Trigger, sut.Snapshot.RuleDef.Trigger); Assert.Same(command.Action, sut.Snapshot.RuleDef.Action); Assert.Equal(command.Name, sut.Snapshot.RuleDef.Name); LastEvents .ShouldHaveSameEvents( CreateRuleEvent(new RuleUpdated { Trigger = command.Trigger, Action = command.Action, Name = "NewName" }) ); }
public async Task DeleteWorkflow_should_create_events_and_remove_workflow() { var command = new DeleteWorkflow { WorkflowId = workflowId }; await ExecuteCreateAsync(); await ExecuteAddWorkflowAsync(); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Empty(sut.Snapshot.Workflows); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppWorkflowDeleted { WorkflowId = workflowId }) ); }
public async Task Patch_should_create_events_and_update_state() { var command = new PatchContent { Data = patch }; await ExecuteCreateAsync(); var result = await sut.ExecuteAsync(CreateContentCommand(command)); result.ShouldBeEquivalent(sut.Snapshot); LastEvents .ShouldHaveSameEvents( CreateContentEvent(new ContentUpdated { Data = patched }) ); A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<update-script>")) .MustHaveHappened(); }
public async Task DeleteRole_should_create_events_and_delete_role() { var command = new DeleteRole { Name = roleName }; await ExecuteCreateAsync(); await ExecuteAddRoleAsync(); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(0, sut.Snapshot.Roles.CustomCount); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppRoleDeleted { Name = roleName }) ); }
public async Task UpdateClient_should_create_events_and_update_client() { var command = new UpdateClient { Id = clientId, Name = clientNewName, Role = Role.Developer }; await ExecuteCreateAsync(); await ExecuteAttachClientAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(clientNewName, sut.Snapshot.Clients[clientId].Name); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppClientUpdated { Id = clientId, Name = clientNewName, Role = Role.Developer }) ); }
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 async Task UpdateLanguage_should_create_events_and_update_language() { var command = new UpdateLanguage { Language = Language.DE, Fallback = new[] { Language.EN } }; await ExecuteCreateAsync(); await ExecuteAddLanguageAsync(Language.DE); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.True(sut.Snapshot.Languages.Contains(Language.DE)); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppLanguageUpdated { Language = Language.DE, Fallback = new[] { Language.EN } }) ); }
public async Task Synchronize_should_create_events_and_update_schema() { var command = new SynchronizeSchema { Category = "My-Category" }; await ExecuteCreateAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(command.Category, sut.Snapshot.SchemaDef.Category); LastEvents .ShouldHaveSameEvents( CreateEvent(new SchemaCategoryChanged { Name = command.Category }) ); }
public async Task Update_should_create_events_and_update_label_and_description() { var command = new UpdateApp { Label = "my-label", Description = "my-description" }; await ExecuteCreateAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal("my-label", sut.Snapshot.Label); Assert.Equal("my-description", sut.Snapshot.Description); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppUpdated { Label = "my-label", Description = "my-description" }) ); }
public async Task Add_should_create_events_and_add_field_to_array() { var command = new AddField { ParentFieldId = 1, Name = fieldName, Properties = ValidProperties() }; await ExecuteCreateAsync(); await ExecuteAddArrayFieldAsync(); var result = await PublishAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Same(command.Properties, GetNestedField(1, 2).RawProperties); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldAdded { ParentFieldId = arrayId, Name = fieldName, FieldId = nestedId, Properties = command.Properties }) ); }
public async Task AssignContributor_should_create_update_events_and_update_contributor() { var command = new AssignContributor { ContributorId = contributorId, Role = Role.Owner }; await ExecuteCreateAsync(); await ExecuteAssignContributorAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.Equal(Role.Owner, sut.Snapshot.Contributors[contributorId]); LastEvents .ShouldHaveSameEvents( CreateEvent(new AppContributorAssigned { ContributorId = contributorId, Role = Role.Owner }) ); }
public async Task DisableField_should_create_events_and_update_field_disabled_flag() { var command = new DisableField { FieldId = 1 }; await ExecuteCreateAsync(); await ExecuteAddFieldAsync(fieldName); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent(sut.Snapshot); Assert.True(GetField(1).IsDisabled); LastEvents .ShouldHaveSameEvents( CreateEvent(new FieldDisabled { FieldId = fieldId }) ); }
public async Task ChangeStatus_should_refresh_properties_and_revert_scheduling_when_invoked_by_scheduler() { var dueTime = Instant.MaxValue; await ExecuteCreateAsync(); await ExecuteScheduledAsync(); var command = new ChangeContentStatus { Status = Status.Draft, JobId = sut.Snapshot.ScheduleJob.Id }; var result = await sut.ExecuteAsync(CreateContentCommand(command)); result.ShouldBeEquivalent(new EntitySavedResult(2)); Assert.Null(sut.Snapshot.ScheduleJob); LastEvents .ShouldHaveSameEvents( CreateContentEvent(new ContentSchedulingCancelled()) ); }