public async Task <IActionResult> PostContent(string app, string name, DomainId id, [FromBody] NamedContentData request, [FromQuery] bool publish = false) { var command = new UpsertContent { ContentId = id, Data = request.ToCleaned(), Publish = publish }; var response = await InvokeCommandAsync(command); return(Ok(response)); }
public async Task Upsert_should_update_contnet_when_found() { var command = new UpsertContent { Data = otherData }; await ExecuteCreateAsync(); var result = await PublishAsync(CreateContentCommand(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(); }
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(); }
private async Task <ContentCommand> CreateCommandAsync(BulkTask task) { var job = task.CommandJob; switch (job.Type) { case BulkUpdateContentType.Create: { var command = new CreateContent(); await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsCreate); return(command); } case BulkUpdateContentType.Update: { var command = new UpdateContent(); await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsUpdateOwn); return(command); } case BulkUpdateContentType.Upsert: { var command = new UpsertContent(); await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsUpsert); return(command); } case BulkUpdateContentType.Patch: { var command = new PatchContent(); await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsUpdateOwn); return(command); } case BulkUpdateContentType.Validate: { var command = new ValidateContent(); await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsReadOwn); return(command); } case BulkUpdateContentType.ChangeStatus: { var command = new ChangeContentStatus { Status = job.Status ?? Status.Draft }; await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsChangeStatusOwn); return(command); } case BulkUpdateContentType.Delete: { var command = new DeleteContent(); await EnrichAndCheckPermissionAsync(task, command, Permissions.AppContentsDeleteOwn); return(command); } default: throw new NotSupportedException(); } }