Beispiel #1
0
        public async Task Should_throw_exception_if_workflow_permits_update()
        {
            var operation = Operation(CreateContent(Status.Draft), normalSchema);

            A.CallTo(() => contentWorkflow.CanUpdateAsync(operation.Snapshot, operation.Snapshot.EditingStatus(), operation.User))
            .Returns(false);

            await Assert.ThrowsAsync <DomainException>(() => operation.CheckUpdateAsync());
        }
        public async Task Should_throw_exception_when_workflow_permits_update()
        {
            var context = CreateContext(CreateContent(Status.Draft), normalSchema);

            A.CallTo(() => contentWorkflow.CanUpdateAsync(context.Content, context.Content.EditingStatus(), context.User))
            .Returns(false);

            await Assert.ThrowsAsync <DomainException>(() => context.CheckUpdateAsync());
        }
Beispiel #3
0
        public async Task Should_enrich_content_with_can_update()
        {
            var content = new ContentEntity {
                SchemaId = schemaId
            };

            A.CallTo(() => workflow.CanUpdateAsync(content, content.Status, requestContext.User))
            .Returns(true);

            var ctx = requestContext.Clone(b => b.WithResolveFlow(false));

            await sut.EnrichAsync(ctx, new[] { content }, null !);

            Assert.True(content.CanUpdate);
        }
Beispiel #4
0
        public async Task Should_enrich_content_with_can_update()
        {
            requestContext.WithResolveFlow(true);

            var source = new ContentEntity {
                SchemaId = schemaId
            };

            A.CallTo(() => contentWorkflow.CanUpdateAsync(source))
            .Returns(true);

            var result = await sut.EnrichAsync(source, requestContext);

            Assert.True(result.CanUpdate);
        }
        public async Task Should_enrich_content_with_can_update()
        {
            var content = new ContentEntity {
                SchemaId = schemaId
            };

            A.CallTo(() => contentWorkflow.CanUpdateAsync(content, requestContext.User))
            .Returns(true);

            var ctx = requestContext.WithResolveFlow(true);

            await sut.EnrichAsync(ctx, new[] { content }, schemaProvider);

            Assert.True(content.CanUpdate);
        }
Beispiel #6
0
 private static async Task ValidateCanUpdate(ContentState content, IContentWorkflow contentWorkflow, ClaimsPrincipal user)
 {
     if (!await contentWorkflow.CanUpdateAsync(content, content.EditingStatus, user))
     {
         throw new DomainException($"The workflow does not allow updates at status {content.Status}");
     }
 }
Beispiel #7
0
 private static async Task ValidateCanUpdate(ContentState content, IContentWorkflow contentWorkflow, ClaimsPrincipal user)
 {
     if (!await contentWorkflow.CanUpdateAsync(content, content.EditingStatus, user))
     {
         throw new DomainException(T.Get("contents.workflowErrorUpdate", new { status = content.EditingStatus }));
     }
 }
Beispiel #8
0
 private static async Task ValidateCanUpdate(IContentEntity content, IContentWorkflow contentWorkflow)
 {
     if (!await contentWorkflow.CanUpdateAsync(content))
     {
         throw new DomainException($"The workflow does not allow updates at status {content.Status}");
     }
 }
Beispiel #9
0
        private static async Task ValidateCanUpdate(IContentEntity content, IContentWorkflow contentWorkflow, ClaimsPrincipal user)
        {
            var status = content.NewStatus ?? content.Status;

            if (!await contentWorkflow.CanUpdateAsync(content, status, user))
            {
                throw new DomainException(T.Get("contents.workflowErrorUpdate", new { status }));
            }
        }
Beispiel #10
0
        public static async Task CanUpdate(UpdateContent command, IContentEntity content, IContentWorkflow contentWorkflow)
        {
            Guard.NotNull(command, nameof(command));

            CheckPermission(content, command, Permissions.AppContentsUpdate, Permissions.AppContentsUpsert);

            if (!command.DoNotValidateWorkflow)
            {
                var status = content.NewStatus ?? content.Status;

                if (!await contentWorkflow.CanUpdateAsync(content, status, command.User))
                {
                    throw new DomainException(T.Get("contents.workflowErrorUpdate", new { status }));
                }
            }

            Validate.It(e =>
            {
                if (command.Data == null)
                {
                    e(Not.Defined(nameof(command.Data)), nameof(command.Data));
                }
            });
        }
Beispiel #11
0
        private async Task EnrichCanUpdateAsync(ContentEntity content, Context context)
        {
            var editingStatus = content.NewStatus ?? content.Status;

            content.CanUpdate = await contentWorkflow.CanUpdateAsync(content, editingStatus, context.User);
        }
Beispiel #12
0
 private void SetupCanUpdate(bool canUpdate)
 {
     A.CallTo(() => contentWorkflow.CanUpdateAsync(A <IContentEntity> ._, A <Status> ._, user))
     .Returns(canUpdate);
 }
Beispiel #13
0
 private async Task EnrichCanUpdateAsync(IContentEntity content, ContentEntity result, Context context)
 {
     result.CanUpdate = await contentWorkflow.CanUpdateAsync(content, context.User);
 }
Beispiel #14
0
 private void SetupCanUpdate(bool canUpdate)
 {
     A.CallTo(() => contentWorkflow.CanUpdateAsync(A <IContentEntity> .Ignored))
     .Returns(canUpdate);
 }
Beispiel #15
0
 private async Task ResolveCanUpdateAsync(IContentEntity content, ContentEntity result)
 {
     result.CanUpdate = await contentWorkflow.CanUpdateAsync(content);
 }