|
|
|
@ -34,7 +34,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
private readonly ISchemaEntity schema = A.Fake<ISchemaEntity>(); |
|
|
|
private readonly IScriptEngine scriptEngine = A.Fake<IScriptEngine>(); |
|
|
|
private readonly IContentRepository contentRepository = A.Dummy<IContentRepository>(); |
|
|
|
private readonly IContentWorkflow contentWorkflow = A.Fake<IContentWorkflow>(); |
|
|
|
private readonly IContentWorkflow contentWorkflow = A.Fake<IContentWorkflow>(x => x.Wrapping(new DefaultContentWorkflow())); |
|
|
|
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|
|
|
private readonly IAppEntity app = A.Fake<IAppEntity>(); |
|
|
|
private readonly LanguagesConfig languagesConfig = LanguagesConfig.Build(Language.DE); |
|
|
|
@ -102,12 +102,6 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, A<string>.Ignored)) |
|
|
|
.ReturnsLazily(x => x.GetArgument<ScriptContext>(0).Data); |
|
|
|
|
|
|
|
A.CallTo(() => contentWorkflow.CanUpdateAsync(A<IContentEntity>.Ignored)) |
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
A.CallTo(() => contentWorkflow.CanMoveToAsync(A<IContentEntity>.Ignored, A<Status>.Ignored)) |
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
patched = patch.MergeInto(data); |
|
|
|
|
|
|
|
sut = new ContentGrain(Store, A.Dummy<ISemanticLog>(), appProvider, A.Dummy<IAssetRepository>(), scriptEngine, contentWorkflow, contentRepository); |
|
|
|
@ -132,9 +126,12 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
Assert.Equal(Status.Draft, sut.Snapshot.Status); |
|
|
|
Assert.Equal(StatusColors.Draft, sut.Snapshot.StatusColor); |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentCreated { Data = data }) |
|
|
|
CreateContentEvent(new ContentCreated { Data = data, Status = Status.Draft, StatusColor = StatusColors.Draft }) |
|
|
|
); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<create-script>")) |
|
|
|
@ -143,26 +140,6 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
.MustNotHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Create_should_create_events_and_update_state_with_custom_initial_status() |
|
|
|
{ |
|
|
|
var command = new CreateContent { Data = data }; |
|
|
|
|
|
|
|
A.CallTo(() => contentWorkflow.GetInitialStatusAsync(schema)) |
|
|
|
.Returns(Status.Archived); |
|
|
|
|
|
|
|
var result = await sut.ExecuteAsync(CreateContentCommand(command)); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
Assert.Equal(Status.Archived, sut.Snapshot.Status); |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentCreated { Data = data, Status = Status.Archived }) |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Create_should_also_publish() |
|
|
|
{ |
|
|
|
@ -172,10 +149,22 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
Assert.Equal(Status.Published, sut.Snapshot.Status); |
|
|
|
Assert.Equal(StatusColors.Published, sut.Snapshot.StatusColor); |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentCreated { Data = data }), |
|
|
|
CreateContentEvent(new ContentStatusChanged { Status = Status.Published }) |
|
|
|
CreateContentEvent(new ContentCreated |
|
|
|
{ |
|
|
|
Data = data, |
|
|
|
Status = Status.Draft, |
|
|
|
StatusColor = StatusColors.Draft |
|
|
|
}), |
|
|
|
CreateContentEvent(new ContentStatusChanged |
|
|
|
{ |
|
|
|
Status = Status.Published, |
|
|
|
StatusColor = StatusColors.Published |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<create-script>")) |
|
|
|
@ -246,10 +235,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentCreated { Data = data }) |
|
|
|
); |
|
|
|
Assert.Single(LastEvents); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<update-script>")) |
|
|
|
.MustNotHaveHappened(); |
|
|
|
@ -319,10 +305,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentCreated { Data = data }) |
|
|
|
); |
|
|
|
Assert.Single(LastEvents); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.ExecuteAndTransform(A<ScriptContext>.Ignored, "<update-script>")) |
|
|
|
.MustNotHaveHappened(); |
|
|
|
@ -343,7 +326,12 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentStatusChanged { Status = Status.Published, Change = StatusChange.Published }) |
|
|
|
CreateContentEvent(new ContentStatusChanged |
|
|
|
{ |
|
|
|
Change = StatusChange.Published, |
|
|
|
Status = Status.Published, |
|
|
|
StatusColor = StatusColors.Published |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")) |
|
|
|
@ -365,7 +353,11 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) |
|
|
|
CreateContentEvent(new ContentStatusChanged |
|
|
|
{ |
|
|
|
Status = Status.Archived, |
|
|
|
StatusColor = StatusColors.Archived |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")) |
|
|
|
@ -388,7 +380,12 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentStatusChanged { Status = Status.Draft, Change = StatusChange.Unpublished }) |
|
|
|
CreateContentEvent(new ContentStatusChanged |
|
|
|
{ |
|
|
|
Change = StatusChange.Unpublished, |
|
|
|
Status = Status.Draft, |
|
|
|
StatusColor = StatusColors.Draft |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")) |
|
|
|
@ -411,7 +408,11 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
LastEvents |
|
|
|
.ShouldHaveSameEvents( |
|
|
|
CreateContentEvent(new ContentStatusChanged { Status = Status.Draft }) |
|
|
|
CreateContentEvent(new ContentStatusChanged |
|
|
|
{ |
|
|
|
Status = Status.Draft, |
|
|
|
StatusColor = StatusColors.Draft |
|
|
|
}) |
|
|
|
); |
|
|
|
|
|
|
|
A.CallTo(() => scriptEngine.Execute(A<ScriptContext>.Ignored, "<change-script>")) |
|
|
|
@ -472,11 +473,11 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
public async Task ChangeStatus_should_refresh_properties_and_revert_scheduling_when_invoked_by_scheduler() |
|
|
|
{ |
|
|
|
await ExecuteCreateAsync(); |
|
|
|
await ExecuteScheduledAsync(); |
|
|
|
await ExecuteChangeStatusAsync(Status.Published, Instant.MaxValue); |
|
|
|
|
|
|
|
var command = new ChangeContentStatus { Status = Status.Draft, JobId = sut.Snapshot.ScheduleJob.Id }; |
|
|
|
var command = new ChangeContentStatus { Status = Status.Published, JobId = sut.Snapshot.ScheduleJob.Id }; |
|
|
|
|
|
|
|
A.CallTo(() => contentWorkflow.CanMoveToAsync(sut.Snapshot, command.Status)) |
|
|
|
A.CallTo(() => contentWorkflow.CanMoveToAsync(A<IContentEntity>.Ignored, Status.Published)) |
|
|
|
.Returns(false); |
|
|
|
|
|
|
|
var result = await sut.ExecuteAsync(CreateContentCommand(command)); |
|
|
|
@ -549,9 +550,9 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
return sut.ExecuteAsync(CreateContentCommand(new UpdateContent { Data = otherData, AsDraft = true })); |
|
|
|
} |
|
|
|
|
|
|
|
private Task ExecuteScheduledAsync() |
|
|
|
private Task ExecuteChangeStatusAsync(Status status, Instant? dueTime = null) |
|
|
|
{ |
|
|
|
return sut.ExecuteAsync(CreateContentCommand(new ChangeContentStatus { Status = Status.Published, DueTime = Instant.MaxValue })); |
|
|
|
return sut.ExecuteAsync(CreateContentCommand(new ChangeContentStatus { Status = status, DueTime = dueTime })); |
|
|
|
} |
|
|
|
|
|
|
|
private Task ExecuteDeleteAsync() |
|
|
|
|