|
|
|
@ -17,6 +17,7 @@ using Squidex.Domain.Apps.Core.Scripting; |
|
|
|
using Squidex.Domain.Apps.Core.ValidateContent; |
|
|
|
using Squidex.Domain.Apps.Entities.Apps; |
|
|
|
using Squidex.Domain.Apps.Entities.Contents.Commands; |
|
|
|
using Squidex.Domain.Apps.Entities.Contents.Repositories; |
|
|
|
using Squidex.Domain.Apps.Entities.Contents.State; |
|
|
|
using Squidex.Domain.Apps.Entities.Schemas; |
|
|
|
using Squidex.Domain.Apps.Entities.TestHelpers; |
|
|
|
@ -35,6 +36,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
private readonly IAppEntity app; |
|
|
|
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|
|
|
private readonly IContentWorkflow contentWorkflow = A.Fake<IContentWorkflow>(x => x.Wrapping(new DefaultContentWorkflow())); |
|
|
|
private readonly IContentRepository contentRepository = A.Fake<IContentRepository>(); |
|
|
|
private readonly ISchemaEntity schema; |
|
|
|
private readonly IScriptEngine scriptEngine = A.Fake<IScriptEngine>(); |
|
|
|
|
|
|
|
@ -105,9 +107,11 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
patched = patch.MergeInto(data); |
|
|
|
|
|
|
|
var context = new ContentOperationContext(appProvider, Enumerable.Repeat(new DefaultValidatorsFactory(), 1), scriptEngine, A.Fake<ISemanticLog>()); |
|
|
|
var validators = Enumerable.Repeat(new DefaultValidatorsFactory(), 1); |
|
|
|
|
|
|
|
sut = new ContentDomainObject(Store, contentWorkflow, context, A.Dummy<ISemanticLog>()); |
|
|
|
var context = new ContentOperationContext(appProvider, validators, scriptEngine, A.Fake<ISemanticLog>()); |
|
|
|
|
|
|
|
sut = new ContentDomainObject(Store, A.Dummy<ISemanticLog>(), contentWorkflow, contentRepository, context); |
|
|
|
sut.Setup(Id); |
|
|
|
} |
|
|
|
|
|
|
|
@ -125,7 +129,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
{ |
|
|
|
var command = new CreateContent { Data = data }; |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -148,7 +152,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
{ |
|
|
|
var command = new CreateContent { Data = data, Publish = true }; |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -171,7 +175,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
{ |
|
|
|
var command = new CreateContent { Data = invalidData }; |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() => PublishAsync(CreateContentCommand(command))); |
|
|
|
await Assert.ThrowsAsync<ValidationException>(() => PublishAsync(command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -181,7 +185,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -205,7 +209,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
await ExecutePublishAsync(); |
|
|
|
await ExecuteCreateDraftAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -227,7 +231,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -244,7 +248,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<ValidationException>(() => PublishAsync(CreateContentCommand(command))); |
|
|
|
await Assert.ThrowsAsync<ValidationException>(() => PublishAsync(command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
@ -254,7 +258,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -278,7 +282,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
await ExecutePublishAsync(); |
|
|
|
await ExecuteCreateDraftAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -300,7 +304,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -317,7 +321,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -339,7 +343,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -362,7 +366,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
await ExecuteCreateAsync(); |
|
|
|
await ExecutePublishAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -386,7 +390,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
await ExecutePublishAsync(); |
|
|
|
await ExecuteCreateDraftAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -410,7 +414,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -441,7 +445,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
A.CallTo(() => contentWorkflow.CanMoveToAsync(A<IContentEntity>._, Status.Draft, Status.Archived, User)) |
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -469,7 +473,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
A.CallTo(() => contentWorkflow.CanMoveToAsync(A<IContentEntity>._, Status.Draft, Status.Published, User)) |
|
|
|
.Returns(false); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -491,7 +495,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(new EntitySavedResult(1)); |
|
|
|
|
|
|
|
@ -506,6 +510,32 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
.MustHaveHappened(); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Delete_should_throw_exception_if_referenced_by_other_item() |
|
|
|
{ |
|
|
|
var command = new DeleteContent { CheckReferrers = true }; |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
A.CallTo(() => contentRepository.HasReferrersAsync(Id)) |
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<DomainException>(() => PublishAsync(command)); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task Delete_should_not_throw_exception_if_referenced_by_other_item_but_forced() |
|
|
|
{ |
|
|
|
var command = new DeleteContent(); |
|
|
|
|
|
|
|
await ExecuteCreateAsync(); |
|
|
|
|
|
|
|
A.CallTo(() => contentRepository.HasReferrersAsync(Id)) |
|
|
|
.Returns(true); |
|
|
|
|
|
|
|
await PublishAsync(command); |
|
|
|
} |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public async Task CreateDraft_should_create_events_and_update_new_state() |
|
|
|
{ |
|
|
|
@ -514,7 +544,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
await ExecuteCreateAsync(); |
|
|
|
await ExecutePublishAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(sut.Snapshot); |
|
|
|
|
|
|
|
@ -535,7 +565,7 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
await ExecutePublishAsync(); |
|
|
|
await ExecuteCreateDraftAsync(); |
|
|
|
|
|
|
|
var result = await PublishAsync(CreateContentCommand(command)); |
|
|
|
var result = await PublishAsync(command); |
|
|
|
|
|
|
|
result.ShouldBeEquivalent(new EntitySavedResult(3)); |
|
|
|
|
|
|
|
@ -549,22 +579,22 @@ namespace Squidex.Domain.Apps.Entities.Contents |
|
|
|
|
|
|
|
private Task ExecuteCreateAsync() |
|
|
|
{ |
|
|
|
return PublishAsync(CreateContentCommand(new CreateContent { Data = data })); |
|
|
|
return PublishAsync(new CreateContent { Data = data }); |
|
|
|
} |
|
|
|
|
|
|
|
private Task ExecuteUpdateAsync() |
|
|
|
{ |
|
|
|
return PublishAsync(CreateContentCommand(new UpdateContent { Data = otherData })); |
|
|
|
return PublishAsync(new UpdateContent { Data = otherData }); |
|
|
|
} |
|
|
|
|
|
|
|
private Task ExecuteCreateDraftAsync() |
|
|
|
{ |
|
|
|
return PublishAsync(CreateContentCommand(new CreateContentDraft())); |
|
|
|
return PublishAsync(new CreateContentDraft()); |
|
|
|
} |
|
|
|
|
|
|
|
private Task ExecuteChangeStatusAsync(Status status, Instant? dueTime = null) |
|
|
|
{ |
|
|
|
return PublishAsync(CreateContentCommand(new ChangeContentStatus { Status = status, DueTime = dueTime })); |
|
|
|
return PublishAsync(new ChangeContentStatus { Status = status, DueTime = dueTime }); |
|
|
|
} |
|
|
|
|
|
|
|
private Task ExecuteDeleteAsync() |
|
|
|
|