Beispiel #1
0
        public async Task Patch_should_create_events_and_update_new_version_when_draft_available()
        {
            var command = new PatchContent {
                Data = patch
            };

            await ExecuteCreateAsync();
            await ExecutePublishAsync();
            await ExecuteCreateDraftAsync();

            var result = await PublishAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Equal(patched, sut.Snapshot.NewVersion?.Data);

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

            A.CallTo(() => scriptEngine.TransformAsync(ScriptContext(patched, data, Status.Draft), "<update-script>", ScriptOptions()))
            .MustHaveHappened();
        }
Beispiel #2
0
        public async Task Patch_should_create_proposal_events_and_update_state()
        {
            var command = new PatchContent {
                Data = patch, AsDraft = true
            };

            await ExecuteCreateAsync();
            await ExecutePublishAsync();

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

            result.ShouldBeEquivalent(new ContentDataChangedResult(otherData, 2));

            Assert.True(sut.Snapshot.IsPending);

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

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<update-script>"))
            .MustHaveHappened();
        }
Beispiel #3
0
        public void CanPatch_should_throw_exception_if_data_is_null()
        {
            var command = new PatchContent();

            ValidationAssert.Throws(() => GuardContent.CanPatch(command),
                                    new ValidationError("Data is required.", "Data"));
        }
Beispiel #4
0
        public void CanPatch_should_not_throw_exception_if_data_is_not_null()
        {
            var command = new PatchContent {
                Data = new NamedContentData()
            };

            GuardContent.CanPatch(command);
        }
Beispiel #5
0
        public static void CanPatch(PatchContent command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot patch content.", e =>
            {
                ValidateData(command, e);
            });
        }
        public async Task <IActionResult> PatchContent(Guid id, [FromBody] ContentData request)
        {
            var command = new PatchContent {
                ContentId = id, Data = request.ToCleaned()
            };

            await CommandBus.PublishAsync(command);

            return(NoContent());
        }
        public async Task <IActionResult> PatchContent(string app, string name, DomainId id, [FromBody] NamedContentData request)
        {
            var command = new PatchContent {
                ContentId = id, Data = request.ToCleaned()
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Beispiel #8
0
        public async Task CanPatch_should_throw_exception_if_data_is_null()
        {
            SetupCanUpdate(true);

            var content = CreateContent(Status.Draft);
            var command = new PatchContent();

            await ValidationAssert.ThrowsAsync(() => GuardContent.CanPatch(content, contentWorkflow, command),
                                               new ValidationError("Data is required.", "Data"));
        }
Beispiel #9
0
        public async Task CanPatch_should_throw_exception_if_workflow_blocks_it()
        {
            SetupCanUpdate(false);

            var content = CreateContent(Status.Draft);
            var command = new PatchContent {
                Data = new NamedContentData()
            };

            await Assert.ThrowsAsync <DomainException>(() => GuardContent.CanPatch(content, contentWorkflow, command));
        }
Beispiel #10
0
        public async Task CanPatch_should_not_throw_exception_if_data_is_not_null()
        {
            SetupCanUpdate(true);

            var content = CreateContent(Status.Draft);
            var command = new PatchContent {
                Data = new NamedContentData(), User = user
            };

            await GuardContent.CanPatch(content, contentWorkflow, command);
        }
Beispiel #11
0
        public async Task <IActionResult> PatchContent(string app, string name, Guid id, [FromBody] NamedContentData request, [FromQuery] bool asDraft = false)
        {
            await contentQuery.GetSchemaOrThrowAsync(Context, name);

            var command = new PatchContent {
                ContentId = id, Data = request.ToCleaned(), AsDraft = asDraft
            };

            var response = await InvokeCommandAsync(command);

            return(Ok(response));
        }
Beispiel #12
0
        public static void CanPatch(PatchContent command)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(() => "Cannot patch content.", error =>
            {
                if (command.Data == null)
                {
                    error(new ValidationError("Data cannot be null.", nameof(command.Data)));
                }
            });
        }
Beispiel #13
0
        public void Patch(PatchContent command)
        {
            var newData = command.Data.MergeInto(Snapshot.Data);

            if (!newData.Equals(Snapshot.Data))
            {
                var @event = SimpleMapper.Map(command, new ContentUpdated());

                @event.Data = newData;

                RaiseEvent(@event);
            }
        }
Beispiel #14
0
        public static async Task CanPatch(PatchContent command,
                                          IContentEntity content,
                                          IContentWorkflow contentWorkflow)
        {
            Guard.NotNull(command, nameof(command));

            Validate.It(e =>
            {
                ValidateData(command, e);
            });

            await ValidateCanUpdate(content, contentWorkflow, command.User);
        }
Beispiel #15
0
        public async Task <IActionResult> PatchContent(string app, string name, Guid id, [FromBody] NamedContentData request, [FromQuery] bool asDraft = false)
        {
            await contentQuery.ThrowIfSchemaNotExistsAsync(Context().WithSchemaName(name));

            var command = new PatchContent {
                ContentId = id, Data = request.ToCleaned(), AsDraft = asDraft
            };
            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <ContentDataChangedResult>();
            var response = result.Data;

            return(Ok(response));
        }
        public async Task <IActionResult> PatchContent(string app, string name, Guid id, [FromBody] NamedContentData request)
        {
            await contentQuery.FindSchemaAsync(App, name);

            var command = new PatchContent {
                ContentId = id, Data = request.ToCleaned()
            };
            var context = await CommandBus.PublishAsync(command);

            var result   = context.Result <ContentDataChangedResult>();
            var response = result.Data;

            return(Ok(response));
        }
Beispiel #17
0
        public ContentDomainObject Patch(PatchContent command)
        {
            VerifyCreatedAndNotDeleted();

            var newData = Data.MergeInto(command.Data);

            if (!newData.Equals(Data))
            {
                RaiseEvent(SimpleMapper.Map(command, new ContentUpdated {
                    Data = newData
                }));
            }

            return(this);
        }
        protected async Task On(PatchContent command, CommandContext context)
        {
            await handler.UpdateAsync <ContentDomainObject>(context, async content =>
            {
                var schemaAndApp = await ResolveSchemaAndAppAsync(command);

                ExecuteScriptAndTransform(command, content, schemaAndApp.SchemaEntity.ScriptUpdate, "Patch");

                await ValidateAsync(schemaAndApp, command, () => "Failed to patch content", true);

                content.Patch(command);

                context.Complete(new ContentDataChangedResult(content.Data, content.Version));
            });
        }
Beispiel #19
0
        protected async Task On(PatchContent command, CommandContext context)
        {
            await handler.UpdateAsync <ContentDomainObject>(context, async content =>
            {
                GuardContent.CanPatch(command);

                var operationContext = await CreateContext(command, content, () => "Failed to patch content.");

                await operationContext.ValidateAsync(true);
                await operationContext.ExecuteScriptAndTransformAsync(x => x.ScriptUpdate, "Patch");

                content.Patch(command);

                context.Complete(new ContentDataChangedResult(content.Snapshot.Data, content.Version));
            });
        }
Beispiel #20
0
        private void AddContentPatch(string schemaType, string schemaName, ContentDataGraphInputType inputType, IComplexGraphType resultType)
        {
            AddField(new FieldType
            {
                Name      = $"patch{schemaType}Content",
                Arguments = new QueryArguments
                {
                    new QueryArgument(AllTypes.None)
                    {
                        Name         = "id",
                        Description  = $"The id of the {schemaName} content (GUID)",
                        DefaultValue = string.Empty,
                        ResolvedType = AllTypes.NonNullGuid
                    },
                    new QueryArgument(AllTypes.None)
                    {
                        Name         = "data",
                        Description  = $"The data for the {schemaName} content.",
                        DefaultValue = null,
                        ResolvedType = new NonNullGraphType(inputType),
                    },
                    new QueryArgument(AllTypes.None)
                    {
                        Name         = "expectedVersion",
                        Description  = "The expected version",
                        DefaultValue = EtagVersion.Any,
                        ResolvedType = AllTypes.Int
                    }
                },
                ResolvedType = new NonNullGraphType(resultType),
                Resolver     = ResolveAsync(async(c, publish) =>
                {
                    var contentId   = c.GetArgument <Guid>("id");
                    var contentData = GetContentData(c);

                    var command = new PatchContent {
                        ContentId = contentId, Data = contentData
                    };
                    var commandContext = await publish(command);

                    var result = commandContext.Result <ContentDataChangedResult>();

                    return(result);
                }),
                Description = $"Patch a {schemaName} content."
            });
        }
Beispiel #21
0
        public ContentDomainObject Patch(PatchContent command)
        {
            Guard.Valid(command, nameof(command), () => "Cannot patch content");

            VerifyCreatedAndNotDeleted();

            var newData = Data.MergeInto(command.Data);

            if (!newData.Equals(Data))
            {
                RaiseEvent(SimpleMapper.Map(command, new ContentUpdated {
                    Data = newData
                }));
            }

            return(this);
        }
Beispiel #22
0
        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(sut.Snapshot);

            Assert.Single(LastEvents);

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<update-script>"))
            .MustNotHaveHappened();
        }
Beispiel #23
0
        public ContentDomainObject Patch(PatchContent command)
        {
            VerifyCreatedAndNotDeleted();

            var newData = command.Data.MergeInto(Snapshot.Data);

            if (!newData.Equals(Snapshot.Data))
            {
                var @event = SimpleMapper.Map(command, new ContentUpdated());

                @event.Data = newData;

                RaiseEvent(@event);
            }

            return(this);
        }
Beispiel #24
0
        public async Task Patch_should_not_create_event_for_same_data()
        {
            var command = new PatchContent {
                Data = data
            };

            await ExecuteCreateAsync();

            var result = await PublishAsync(command);

            result.ShouldBeEquivalent(sut.Snapshot);

            Assert.Single(LastEvents);

            A.CallTo(() => scriptEngine.TransformAsync(A <ScriptVars> ._, "<update-script>", ScriptOptions()))
            .MustNotHaveHappened();
        }
        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(new ContentDataChangedResult(otherData, 1));

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

            A.CallTo(() => scriptEngine.ExecuteAndTransform(A <ScriptContext> .Ignored, "<update-script>"))
            .MustHaveHappened();
        }
Beispiel #26
0
        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(ScriptContext(patched, data, Status.Draft, default), "<update-script>"))
            .MustHaveHappened();
        }
Beispiel #27
0
        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();
        }
Beispiel #28
0
        public TerrainModelContent Build(ContentProcessorContext context)
        {
            // TODO: i think numlevels is log2, or something like that

            // calculate number of levels, based on patch size
            int nCurrent  = (_patchSize - 1) * 2;
            int numLevels = 0;

            while (nCurrent != 1)
            {
                nCurrent /= 2;
                numLevels++;
            }

            int numPatchesX = (_heightMap.Width - 1) / (_patchSize - 1);
            int numPatchesY = (_heightMap.Height - 1) / (_patchSize - 1);

            // create patches
            PatchContent[,] patches = new PatchContent[numPatchesX, numPatchesY];
            for (int y = 0; y < numPatchesY; y++)
            {
                for (int x = 0; x < numPatchesX; x++)
                {
                    PatchContentBuilder patchContentBuilder = new PatchContentBuilder(_patchSize, x, y, _heightMap, numLevels, _detailTextureTiling, _horizontalScale);
                    patches[x, y] = patchContentBuilder.Build();
                }
            }

            return(new TerrainModelContent
            {
                NumPatchesX = numPatchesX,
                NumPatchesY = numPatchesY,
                Patches = patches,
                HeightMap = _heightMap,
                Tau = _tau,
                Material = _material
            });
        }
Beispiel #29
0
        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();
            }
        }
Beispiel #30
0
        protected async Task On(PatchContent command, CommandContext context)
        {
            await ValidateAsync(command, () => "Failed to patch content");

            await handler.UpdateAsync <ContentDomainObject>(context, c => c.Patch(command));
        }