public async Task Should_throw_exception_when_workflow_status_not_valid() { var context = CreateContext(CreateContent(Status.Draft), normalSchema); A.CallTo(() => contentWorkflow.GetInfoAsync(((ContentEntity)context.Content), Status.Archived)) .Returns(Task.FromResult <StatusInfo?>(null)); await Assert.ThrowsAsync <ValidationException>(() => context.CheckStatusAsync(Status.Archived)); }
public async Task Should_throw_exception_if_workflow_status_not_valid() { var operation = Operation(CreateContent(Status.Draft), normalSchema); A.CallTo(() => contentWorkflow.GetInfoAsync((ContentEntity)operation.Snapshot, Status.Archived)) .Returns(ValueTask.FromResult <StatusInfo?>(null)); await Assert.ThrowsAsync <ValidationException>(() => operation.CheckStatusAsync(Status.Archived)); }
public async Task Should_enrich_content_with_status_color() { var content = CreateContent(); A.CallTo(() => contentWorkflow.GetInfoAsync(content)) .Returns(new StatusInfo(Status.Published, StatusColors.Published)); await sut.EnrichAsync(requestContext, new[] { content }, schemaProvider); Assert.Equal(StatusColors.Published, content.StatusColor); }
public async Task Should_enrich_content_with_status_color() { var content = new ContentEntity { SchemaId = schemaId }; A.CallTo(() => workflow.GetInfoAsync(content, content.Status)) .Returns(new StatusInfo(Status.Published, StatusColors.Published)); await sut.EnrichAsync(requestContext, new[] { content }, null !); Assert.Equal(StatusColors.Published, content.StatusColor); }
public async Task Should_enrich_content_with_status_color() { var source = new ContentEntity { Status = Status.Published, SchemaId = schemaId }; A.CallTo(() => workflow.GetInfoAsync(Status.Published)) .Returns(new StatusInfo(Status.Published, StatusColors.Published)); var result = await sut.EnrichAsync(source); Assert.Equal(StatusColors.Published, result.StatusColor); }
public async Task Should_add_app_version_and_schema_as_dependency() { var source = new ContentEntity { Status = Status.Published, SchemaId = schemaId }; A.CallTo(() => contentWorkflow.GetInfoAsync(source)) .Returns(new StatusInfo(Status.Published, StatusColors.Published)); var result = await sut.EnrichAsync(source, requestContext); Assert.Contains(requestContext.App.Version.ToString(), result.CacheDependencies); Assert.Contains(schema.Id.ToString(), result.CacheDependencies); Assert.Contains(schema.Version.ToString(), result.CacheDependencies); }
public static async Task CanChangeStatus(ChangeContentStatus command, IContentEntity content, IContentWorkflow contentWorkflow, IContentRepository contentRepository, ISchemaEntity schema) { Guard.NotNull(command, nameof(command)); CheckPermission(content, command, Permissions.AppContentsChangeStatus, Permissions.AppContentsUpsert); var newStatus = command.Status; if (schema.SchemaDef.IsSingleton) { if (content.NewStatus == null || newStatus != Status.Published) { throw new DomainException(T.Get("contents.singletonNotChangeable")); } return; } var oldStatus = content.NewStatus ?? content.Status; if (oldStatus == Status.Published && command.CheckReferrers) { var hasReferrer = await contentRepository.HasReferrersAsync(content.AppId.Id, command.ContentId, SearchScope.Published); if (hasReferrer) { throw new DomainException(T.Get("contents.referenced")); } } await Validate.It(async e => { if (!command.DoNotValidateWorkflow) { if (!await contentWorkflow.CanMoveToAsync(content, oldStatus, newStatus, command.User)) { var values = new { oldStatus, newStatus }; e(T.Get("contents.statusTransitionNotAllowed", values), "Status"); } } else { var info = await contentWorkflow.GetInfoAsync(content, newStatus); if (info == null) { e(T.Get("contents.statusNotValid"), "Status"); } } }); }
public async Task CanChangeStatus_should_throw_exception_if_status_valid() { var content = CreateContent(Status.Draft); var command = CreateCommand(new ChangeContentStatus { Status = new Status("Invalid"), DoNotValidateWorkflow = true }); A.CallTo(() => workflow.GetInfoAsync(content, command.Status)) .Returns(Task.FromResult <StatusInfo?>(null)); await ValidationAssert.ThrowsAsync(() => GuardContent.CanChangeStatus(command, content, workflow, contentRepository, schema), new ValidationError("Status is not defined in the workflow.", "Status")); }