mirror of https://github.com/Squidex/squidex.git
10 changed files with 814 additions and 1352 deletions
@ -1,145 +1,133 @@ |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.IO;
|
|||
//using System.Threading.Tasks;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Entities.Assets.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Infrastructure.Assets;
|
|||
//using Squidex.Infrastructure.Commands;
|
|||
//using Squidex.Infrastructure.Tasks;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Assets
|
|||
//{
|
|||
// public class AssetCommandMiddlewareTests : HandlerTestBase<AssetDomainObject>
|
|||
// {
|
|||
// private readonly IAssetThumbnailGenerator assetThumbnailGenerator = A.Fake<IAssetThumbnailGenerator>();
|
|||
// private readonly IAssetStore assetStore = A.Fake<IAssetStore>();
|
|||
// private readonly Guid assetId = Guid.NewGuid();
|
|||
// private readonly Stream stream = new MemoryStream();
|
|||
// private readonly ImageInfo image = new ImageInfo(2048, 2048);
|
|||
// private readonly AssetDomainObject asset = new AssetDomainObject();
|
|||
// private readonly AssetFile file;
|
|||
// private readonly AssetCommandMiddleware sut;
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return assetId; }
|
|||
// }
|
|||
|
|||
// public AssetCommandMiddlewareTests()
|
|||
// {
|
|||
// file = new AssetFile("my-image.png", "image/png", 1024, () => stream);
|
|||
|
|||
// sut = new AssetCommandMiddleware(Handler, assetStore, assetThumbnailGenerator);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_create_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new CreateAsset { AssetId = assetId, File = file });
|
|||
|
|||
// SetupStore(0, context.ContextId);
|
|||
// SetupImageInfo();
|
|||
|
|||
// await TestCreate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(assetId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);
|
|||
|
|||
// AssertAssetHasBeenUploaded(0, context.ContextId);
|
|||
// AssertAssetImageChecked();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Update_should_update_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new UpdateAsset { AssetId = assetId, File = file });
|
|||
|
|||
// SetupStore(1, context.ContextId);
|
|||
// SetupImageInfo();
|
|||
|
|||
// CreateAsset();
|
|||
|
|||
// await TestUpdate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// AssertAssetHasBeenUploaded(1, context.ContextId);
|
|||
// AssertAssetImageChecked();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Rename_should_update_domain_object()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// var context = CreateContextForCommand(new RenameAsset { AssetId = assetId, FileName = "my-new-image.png" });
|
|||
|
|||
// await TestUpdate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Delete_should_update_domain_object()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// var command = CreateContextForCommand(new DeleteAsset { AssetId = assetId });
|
|||
|
|||
// await TestUpdate(asset, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(command);
|
|||
// });
|
|||
// }
|
|||
|
|||
// private void CreateAsset()
|
|||
// {
|
|||
// asset.Create(CreateCommand(new CreateAsset { File = file }));
|
|||
// }
|
|||
|
|||
// private void SetupImageInfo()
|
|||
// {
|
|||
// A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream))
|
|||
// .Returns(image);
|
|||
// }
|
|||
|
|||
// private void SetupStore(long version, Guid commitId)
|
|||
// {
|
|||
// A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream))
|
|||
// .Returns(TaskHelper.Done);
|
|||
// A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null))
|
|||
// .Returns(TaskHelper.Done);
|
|||
// A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString()))
|
|||
// .Returns(TaskHelper.Done);
|
|||
// }
|
|||
|
|||
// private void AssertAssetImageChecked()
|
|||
// {
|
|||
// A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream))
|
|||
// .MustHaveHappened();
|
|||
// }
|
|||
|
|||
// private void AssertAssetHasBeenUploaded(long version, Guid commitId)
|
|||
// {
|
|||
// A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream))
|
|||
// .MustHaveHappened();
|
|||
// A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null))
|
|||
// .MustHaveHappened();
|
|||
// A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString()))
|
|||
// .MustHaveHappened();
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Orleans; |
|||
using Orleans.Core; |
|||
using Orleans.Runtime; |
|||
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|||
using Squidex.Domain.Apps.Entities.Assets.State; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Infrastructure.Assets; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.States; |
|||
using Squidex.Infrastructure.Tasks; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Assets |
|||
{ |
|||
public class AssetCommandMiddlewareTests : HandlerTestBase<AssetGrain, AssetState> |
|||
{ |
|||
private readonly IAssetThumbnailGenerator assetThumbnailGenerator = A.Fake<IAssetThumbnailGenerator>(); |
|||
private readonly IAssetStore assetStore = A.Fake<IAssetStore>(); |
|||
private readonly IGrainFactory grainFactory = A.Fake<IGrainFactory>(); |
|||
private readonly Guid assetId = Guid.NewGuid(); |
|||
private readonly Stream stream = new MemoryStream(); |
|||
private readonly ImageInfo image = new ImageInfo(2048, 2048); |
|||
private readonly AssetGrain asset; |
|||
private readonly AssetFile file; |
|||
private readonly AssetCommandMiddleware sut; |
|||
|
|||
public class MyAssetGrain : AssetGrain |
|||
{ |
|||
public MyAssetGrain(IStore<Guid> store, IGrainIdentity identity, IGrainRuntime runtime) |
|||
: base(store, identity, runtime) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return assetId; } |
|||
} |
|||
|
|||
public AssetCommandMiddlewareTests() |
|||
{ |
|||
file = new AssetFile("my-image.png", "image/png", 1024, () => stream); |
|||
|
|||
asset = new MyAssetGrain(Store, Identity, Runtime); |
|||
asset.OnActivateAsync(); |
|||
|
|||
A.CallTo(() => grainFactory.GetGrain<IAssetGrain>(Id, null)) |
|||
.Returns(asset); |
|||
|
|||
sut = new AssetCommandMiddleware(grainFactory, assetStore, assetThumbnailGenerator); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new CreateAsset { AssetId = assetId, File = file }); |
|||
|
|||
SetupStore(0, context.ContextId); |
|||
SetupImageInfo(); |
|||
|
|||
await sut.HandleAsync(context); |
|||
|
|||
Assert.Equal(assetId, context.Result<EntityCreatedResult<Guid>>().IdOrValue); |
|||
|
|||
AssertAssetHasBeenUploaded(0, context.ContextId); |
|||
AssertAssetImageChecked(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_update_domain_object() |
|||
{ |
|||
var context = CreateContextForCommand(new UpdateAsset { AssetId = assetId, File = file }); |
|||
|
|||
SetupStore(1, context.ContextId); |
|||
SetupImageInfo(); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
await sut.HandleAsync(context); |
|||
|
|||
AssertAssetHasBeenUploaded(1, context.ContextId); |
|||
AssertAssetImageChecked(); |
|||
} |
|||
|
|||
private Task ExecuteCreateAsync() |
|||
{ |
|||
return asset.ExecuteAsync(J(CreateCommand(new CreateAsset { AssetId = Id, File = file }))); |
|||
} |
|||
|
|||
private void SetupStore(long version, Guid commitId) |
|||
{ |
|||
A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream)) |
|||
.Returns(TaskHelper.Done); |
|||
A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null)) |
|||
.Returns(TaskHelper.Done); |
|||
A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString())) |
|||
.Returns(TaskHelper.Done); |
|||
} |
|||
|
|||
private void AssertAssetHasBeenUploaded(long version, Guid commitId) |
|||
{ |
|||
A.CallTo(() => assetStore.UploadTemporaryAsync(commitId.ToString(), stream)) |
|||
.MustHaveHappened(); |
|||
A.CallTo(() => assetStore.CopyTemporaryAsync(commitId.ToString(), assetId.ToString(), version, null)) |
|||
.MustHaveHappened(); |
|||
A.CallTo(() => assetStore.DeleteTemporaryAsync(commitId.ToString())) |
|||
.MustHaveHappened(); |
|||
} |
|||
|
|||
private void SetupImageInfo() |
|||
{ |
|||
A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream)) |
|||
.Returns(image); |
|||
} |
|||
|
|||
private void AssertAssetImageChecked() |
|||
{ |
|||
A.CallTo(() => assetThumbnailGenerator.GetImageInfoAsync(stream)) |
|||
.MustHaveHappened(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -1,220 +0,0 @@ |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.IO;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Entities.Assets.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Domain.Apps.Events.Assets;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.Assets;
|
|||
//using Squidex.Infrastructure.States;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Assets
|
|||
//{
|
|||
// public class AssetDomainObjectTests : HandlerTestBase<AssetDomainObject>
|
|||
// {
|
|||
// private readonly ImageInfo image = new ImageInfo(2048, 2048);
|
|||
// private readonly Guid assetId = Guid.NewGuid();
|
|||
// private readonly AssetFile file = new AssetFile("my-image.png", "image/png", 1024, () => new MemoryStream());
|
|||
// private readonly AssetDomainObject sut = new AssetDomainObject();
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return assetId; }
|
|||
// }
|
|||
|
|||
// public AssetDomainObjectTests()
|
|||
// {
|
|||
// sut.ActivateAsync(Id, A.Fake<IStore<Guid>>());
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_throw_exception_if_created()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Create(CreateAssetCommand(new CreateAsset { File = file }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_create_events()
|
|||
// {
|
|||
// sut.Create(CreateAssetCommand(new CreateAsset { File = file, ImageInfo = image }));
|
|||
|
|||
// Assert.Equal(0, sut.Snapshot.FileVersion);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetCreated
|
|||
// {
|
|||
// IsImage = true,
|
|||
// FileName = file.FileName,
|
|||
// FileSize = file.FileSize,
|
|||
// FileVersion = 0,
|
|||
// MimeType = file.MimeType,
|
|||
// PixelWidth = image.PixelWidth,
|
|||
// PixelHeight = image.PixelHeight
|
|||
// })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset { File = file }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_asset_is_deleted()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// DeleteAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_create_events()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset { File = file, ImageInfo = image }));
|
|||
|
|||
// Assert.Equal(1, sut.Snapshot.FileVersion);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetUpdated
|
|||
// {
|
|||
// IsImage = true,
|
|||
// FileSize = file.FileSize,
|
|||
// FileVersion = 1,
|
|||
// MimeType = file.MimeType,
|
|||
// PixelWidth = image.PixelWidth,
|
|||
// PixelHeight = image.PixelHeight
|
|||
// })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Rename_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Rename(CreateAssetCommand(new RenameAsset { FileName = "new-file.png" }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Rename_should_throw_exception_if_asset_is_deleted()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// DeleteAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Rename_should_create_events()
|
|||
// {
|
|||
// CreateAsset();
|
|||
|
|||
// sut.Rename(CreateAssetCommand(new RenameAsset { FileName = "my-new-image.png" }));
|
|||
|
|||
// Assert.Equal("my-new-image.png", sut.Snapshot.FileName);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetRenamed { FileName = "my-new-image.png" })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_already_deleted()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// DeleteAsset();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_create_events_with_total_file_size()
|
|||
// {
|
|||
// CreateAsset();
|
|||
// UpdateAsset();
|
|||
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
|
|||
// Assert.True(sut.Snapshot.IsDeleted);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateAssetEvent(new AssetDeleted { DeletedSize = 2048 })
|
|||
// );
|
|||
// }
|
|||
|
|||
// private void CreateAsset()
|
|||
// {
|
|||
// sut.Create(CreateAssetCommand(new CreateAsset { File = file }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void UpdateAsset()
|
|||
// {
|
|||
// sut.Update(CreateAssetCommand(new UpdateAsset { File = file }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void DeleteAsset()
|
|||
// {
|
|||
// sut.Delete(CreateAssetCommand(new DeleteAsset()));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// protected T CreateAssetEvent<T>(T @event) where T : AssetEvent
|
|||
// {
|
|||
// @event.AssetId = assetId;
|
|||
|
|||
// return CreateEvent(@event);
|
|||
// }
|
|||
|
|||
// protected T CreateAssetCommand<T>(T command) where T : AssetCommand
|
|||
// {
|
|||
// command.AssetId = assetId;
|
|||
|
|||
// return CreateCommand(command);
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -0,0 +1,182 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.IO; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Orleans.Core; |
|||
using Orleans.Runtime; |
|||
using Squidex.Domain.Apps.Entities.Assets.Commands; |
|||
using Squidex.Domain.Apps.Entities.Assets.State; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Assets; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Assets; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Assets |
|||
{ |
|||
public class AssetGrainTests : HandlerTestBase<AssetGrain, AssetState> |
|||
{ |
|||
private readonly ImageInfo image = new ImageInfo(2048, 2048); |
|||
private readonly Guid assetId = Guid.NewGuid(); |
|||
private readonly AssetFile file = new AssetFile("my-image.png", "image/png", 1024, () => new MemoryStream()); |
|||
private readonly AssetGrain sut; |
|||
|
|||
public class MyAssetGrain : AssetGrain |
|||
{ |
|||
public MyAssetGrain(IStore<Guid> store, IGrainIdentity identity, IGrainRuntime runtime) |
|||
: base(store, identity, runtime) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return assetId; } |
|||
} |
|||
|
|||
public AssetGrainTests() |
|||
{ |
|||
sut = new MyAssetGrain(Store, Identity, Runtime); |
|||
sut.OnActivateAsync(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Command_should_throw_exception_if_rule_is_deleted() |
|||
{ |
|||
await ExecuteCreateAsync(); |
|||
await ExecuteDeleteAsync(); |
|||
|
|||
await Assert.ThrowsAsync<DomainException>(ExecuteUpdateAsync); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_events() |
|||
{ |
|||
var command = new CreateAsset { File = file, ImageInfo = image }; |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateAssetCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new AssetSavedResult(0, 0)); |
|||
|
|||
Assert.Equal(0, sut.Snapshot.FileVersion); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetCreated |
|||
{ |
|||
IsImage = true, |
|||
FileName = file.FileName, |
|||
FileSize = file.FileSize, |
|||
FileVersion = 0, |
|||
MimeType = file.MimeType, |
|||
PixelWidth = image.PixelWidth, |
|||
PixelHeight = image.PixelHeight |
|||
}) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_create_events() |
|||
{ |
|||
var command = new UpdateAsset { File = file, ImageInfo = image }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateAssetCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new AssetSavedResult(1, 1)); |
|||
|
|||
Assert.Equal(1, sut.Snapshot.FileVersion); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetUpdated |
|||
{ |
|||
IsImage = true, |
|||
FileSize = file.FileSize, |
|||
FileVersion = 1, |
|||
MimeType = file.MimeType, |
|||
PixelWidth = image.PixelWidth, |
|||
PixelHeight = image.PixelHeight |
|||
}) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Rename_should_create_events() |
|||
{ |
|||
var command = new RenameAsset { FileName = "my-new-image.png" }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateAssetCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(1)); |
|||
|
|||
Assert.Equal("my-new-image.png", sut.Snapshot.FileName); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetRenamed { FileName = "my-new-image.png" }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Delete_should_create_events_with_total_file_size() |
|||
{ |
|||
var command = new DeleteAsset(); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteUpdateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateAssetCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.True(sut.Snapshot.IsDeleted); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateAssetEvent(new AssetDeleted { DeletedSize = 2048 }) |
|||
); |
|||
} |
|||
|
|||
private Task ExecuteCreateAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateAssetCommand(new CreateAsset { File = file }))); |
|||
} |
|||
|
|||
private Task ExecuteUpdateAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateAssetCommand(new UpdateAsset { File = file }))); |
|||
} |
|||
|
|||
private Task ExecuteDeleteAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateAssetCommand(new DeleteAsset()))); |
|||
} |
|||
|
|||
protected T CreateAssetEvent<T>(T @event) where T : AssetEvent |
|||
{ |
|||
@event.AssetId = assetId; |
|||
|
|||
return CreateEvent(@event); |
|||
} |
|||
|
|||
protected T CreateAssetCommand<T>(T command) where T : AssetCommand |
|||
{ |
|||
command.AssetId = assetId; |
|||
|
|||
return CreateCommand(command); |
|||
} |
|||
} |
|||
} |
|||
@ -1,280 +0,0 @@ |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.Collections.Generic;
|
|||
//using System.Threading.Tasks;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Core.Schemas;
|
|||
//using Squidex.Domain.Apps.Entities.Schemas.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.Commands;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Schemas
|
|||
//{
|
|||
// public class SchemaCommandMiddlewareTests : HandlerTestBase<SchemaDomainObject>
|
|||
// {
|
|||
// private readonly IAppProvider appProvider = A.Fake<IAppProvider>();
|
|||
// private readonly SchemaCommandMiddleware sut;
|
|||
// private readonly SchemaDomainObject schema;
|
|||
// private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry());
|
|||
// private readonly string fieldName = "age";
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return SchemaId; }
|
|||
// }
|
|||
|
|||
// public SchemaCommandMiddlewareTests()
|
|||
// {
|
|||
// schema = new SchemaDomainObject(registry);
|
|||
|
|||
// sut = new SchemaCommandMiddleware(Handler, appProvider);
|
|||
|
|||
// A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName))
|
|||
// .Returns((ISchemaEntity)null);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Create_should_create_schema_domain_object()
|
|||
// {
|
|||
// var context = CreateContextForCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId });
|
|||
|
|||
// await TestCreate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(SchemaId, context.Result<EntityCreatedResult<Guid>>().IdOrValue);
|
|||
|
|||
// A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName)).MustHaveHappened();
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UpdateSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateSchema { Properties = new SchemaProperties() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ReorderSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new ReorderFields { FieldIds = new List<long>() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task PublishSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new PublishSchema());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UnpublishSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// PublishSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new UnpublishSchema());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ConfigureScripts_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new ConfigureScripts());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DeleteSchema_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new DeleteSchema());
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task Add_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// var context = CreateContextForCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
|
|||
// Assert.Equal(1, context.Result<EntityCreatedResult<long>>().IdOrValue);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task UpdateField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task LockField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new LockField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task HideField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new HideField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task ShowField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// HideField();
|
|||
|
|||
// var context = CreateContextForCommand(new ShowField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DisableField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new DisableField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task EnableField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// DisableField();
|
|||
|
|||
// var context = CreateContextForCommand(new EnableField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public async Task DeleteField_should_update_domain_object()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// var context = CreateContextForCommand(new DeleteField { FieldId = 1 });
|
|||
|
|||
// await TestUpdate(schema, async _ =>
|
|||
// {
|
|||
// await sut.HandleAsync(context);
|
|||
// });
|
|||
// }
|
|||
|
|||
// private void CreateSchema()
|
|||
// {
|
|||
// schema.Create(CreateCommand(new CreateSchema { Name = SchemaName }));
|
|||
// }
|
|||
|
|||
// private void PublishSchema()
|
|||
// {
|
|||
// schema.Publish(CreateCommand(new PublishSchema()));
|
|||
// }
|
|||
|
|||
// private void CreateField()
|
|||
// {
|
|||
// schema.Add(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() }));
|
|||
// }
|
|||
|
|||
// private void HideField()
|
|||
// {
|
|||
// schema.HideField(CreateCommand(new HideField { FieldId = 1 }));
|
|||
// }
|
|||
|
|||
// private void DisableField()
|
|||
// {
|
|||
// schema.DisableField(CreateCommand(new DisableField { FieldId = 1 }));
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -1,665 +0,0 @@ |
|||
//// ==========================================================================
|
|||
//// Squidex Headless CMS
|
|||
//// ==========================================================================
|
|||
//// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
//// All rights reserved. Licensed under the MIT license.
|
|||
//// ==========================================================================
|
|||
|
|||
//using System;
|
|||
//using System.Collections.Generic;
|
|||
//using System.Linq;
|
|||
//using FakeItEasy;
|
|||
//using Squidex.Domain.Apps.Core.Schemas;
|
|||
//using Squidex.Domain.Apps.Entities.Schemas.Commands;
|
|||
//using Squidex.Domain.Apps.Entities.TestHelpers;
|
|||
//using Squidex.Domain.Apps.Events.Schemas;
|
|||
//using Squidex.Infrastructure;
|
|||
//using Squidex.Infrastructure.States;
|
|||
//using Xunit;
|
|||
|
|||
//namespace Squidex.Domain.Apps.Entities.Schemas
|
|||
//{
|
|||
// public class SchemaDomainObjectTests : HandlerTestBase<SchemaDomainObject>
|
|||
// {
|
|||
// private readonly string fieldName = "age";
|
|||
// private readonly NamedId<long> fieldId;
|
|||
// private readonly SchemaDomainObject sut;
|
|||
|
|||
// protected override Guid Id
|
|||
// {
|
|||
// get { return SchemaId; }
|
|||
// }
|
|||
|
|||
// public SchemaDomainObjectTests()
|
|||
// {
|
|||
// fieldId = new NamedId<long>(1, fieldName);
|
|||
|
|||
// var fieldRegistry = new FieldRegistry(new TypeNameRegistry());
|
|||
|
|||
// sut = new SchemaDomainObject(fieldRegistry);
|
|||
// sut.ActivateAsync(Id, A.Fake<IStore<Guid>>());
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_throw_exception_if_created()
|
|||
// {
|
|||
// sut.Create(CreateCommand(new CreateSchema { Name = SchemaName }));
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Create(CreateCommand(new CreateSchema { Name = SchemaName }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_create_schema_and_create_events()
|
|||
// {
|
|||
// var properties = new SchemaProperties();
|
|||
|
|||
// sut.Create(CreateCommand(new CreateSchema { Name = SchemaName, SchemaId = SchemaId, Properties = properties }));
|
|||
|
|||
// Assert.Equal(AppId, sut.Snapshot.AppId.Id);
|
|||
|
|||
// Assert.Equal(SchemaName, sut.Snapshot.Name);
|
|||
// Assert.Equal(SchemaName, sut.Snapshot.SchemaDef.Name);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Create_should_create_schema_with_initial_fields()
|
|||
// {
|
|||
// var properties = new SchemaProperties();
|
|||
|
|||
// var fields = new List<CreateSchemaField>
|
|||
// {
|
|||
// new CreateSchemaField { Name = "field1", Properties = ValidProperties() },
|
|||
// new CreateSchemaField { Name = "field2", Properties = ValidProperties() }
|
|||
// };
|
|||
|
|||
// sut.Create(CreateCommand(new CreateSchema { Name = SchemaName, Properties = properties, Fields = fields }));
|
|||
|
|||
// var @event = (SchemaCreated)sut.GetUncomittedEvents().Single().Payload;
|
|||
|
|||
// Assert.Equal(AppId, sut.Snapshot.AppId.Id);
|
|||
// Assert.Equal(SchemaName, sut.Snapshot.Name);
|
|||
// Assert.Equal(SchemaName, sut.Snapshot.SchemaDef.Name);
|
|||
|
|||
// Assert.Equal(2, @event.Fields.Count);
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateCommand(new UpdateSchema { Properties = new SchemaProperties() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Update(CreateCommand(new UpdateSchema { Properties = new SchemaProperties() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Update_should_refresh_properties_and_create_events()
|
|||
// {
|
|||
// var properties = new SchemaProperties();
|
|||
|
|||
// CreateSchema();
|
|||
|
|||
// sut.Update(CreateCommand(new UpdateSchema { Properties = properties }));
|
|||
|
|||
// Assert.Equal(properties, sut.Snapshot.SchemaDef.Properties);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new SchemaUpdated { Properties = properties })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ConfigureScripts_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ConfigureScripts(CreateCommand(new ConfigureScripts()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ConfigureScripts_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ConfigureScripts(CreateCommand(new ConfigureScripts()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ConfigureScripts_should_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// sut.ConfigureScripts(CreateCommand(new ConfigureScripts
|
|||
// {
|
|||
// ScriptQuery = "<script-query>",
|
|||
// ScriptCreate = "<script-create>",
|
|||
// ScriptUpdate = "<script-update>",
|
|||
// ScriptDelete = "<script-delete>",
|
|||
// ScriptChange = "<script-change>"
|
|||
// }));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new ScriptsConfigured
|
|||
// {
|
|||
// ScriptQuery = "<script-query>",
|
|||
// ScriptCreate = "<script-create>",
|
|||
// ScriptUpdate = "<script-update>",
|
|||
// ScriptDelete = "<script-delete>",
|
|||
// ScriptChange = "<script-change>"
|
|||
// })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Reorder_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Reorder(CreateCommand(new ReorderFields { FieldIds = new List<long>() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Reorder_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Reorder(CreateCommand(new ReorderFields { FieldIds = new List<long>() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Reorder_should_refresh_properties_and_create_events()
|
|||
// {
|
|||
// var fieldIds = new List<long> { 1, 2 };
|
|||
|
|||
// CreateSchema();
|
|||
|
|||
// sut.Add(CreateCommand(new AddField { Name = "field1", Properties = ValidProperties() }));
|
|||
// sut.Add(CreateCommand(new AddField { Name = "field2", Properties = ValidProperties() }));
|
|||
|
|||
// sut.ClearUncommittedEvents();
|
|||
|
|||
// sut.Reorder(CreateCommand(new ReorderFields { FieldIds = fieldIds }));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new SchemaFieldsReordered { FieldIds = fieldIds })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Publish_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Publish(CreateCommand(new PublishSchema()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Publish_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Publish(CreateCommand(new PublishSchema()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Publish_should_refresh_properties_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// sut.Publish(CreateCommand(new PublishSchema()));
|
|||
|
|||
// Assert.True(sut.Snapshot.SchemaDef.IsPublished);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new SchemaPublished())
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Unpublish_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Unpublish(CreateCommand(new UnpublishSchema()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Unpublish_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Unpublish(CreateCommand(new UnpublishSchema()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Unpublish_should_refresh_properties_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// PublishSchema();
|
|||
|
|||
// sut.Unpublish(CreateCommand(new UnpublishSchema()));
|
|||
|
|||
// Assert.False(sut.Snapshot.SchemaDef.IsPublished);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new SchemaUnpublished())
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateCommand(new DeleteSchema()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_throw_exception_if_already_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Delete(CreateCommand(new DeleteSchema()));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Delete_should_refresh_properties_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
|
|||
// sut.Delete(CreateCommand(new DeleteSchema()));
|
|||
|
|||
// Assert.True(sut.Snapshot.IsDeleted);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new SchemaDeleted())
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AddField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Add(CreateCommand(new AddField { Name = fieldName, Properties = ValidProperties() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void AddField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.Add(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void Add_should_update_schema_and_create_events()
|
|||
// {
|
|||
// var properties = new NumberFieldProperties();
|
|||
|
|||
// CreateSchema();
|
|||
|
|||
// sut.Add(CreateCommand(new AddField { Name = fieldName, Properties = properties }));
|
|||
|
|||
// Assert.Equal(properties, sut.Snapshot.SchemaDef.FieldsById[1].RawProperties);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldAdded { Name = fieldName, FieldId = fieldId, Properties = properties })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = new NumberFieldProperties() }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void UpdateField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// var properties = new NumberFieldProperties();
|
|||
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.UpdateField(CreateCommand(new UpdateField { FieldId = 1, Properties = properties }));
|
|||
|
|||
// Assert.Equal(properties, sut.Snapshot.SchemaDef.FieldsById[1].RawProperties);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldUpdated { FieldId = fieldId, Properties = properties })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void LockField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.LockField(CreateCommand(new LockField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void LockField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.LockField(CreateCommand(new LockField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void LockField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.LockField(CreateCommand(new LockField { FieldId = 1 }));
|
|||
|
|||
// Assert.False(sut.Snapshot.SchemaDef.FieldsById[1].IsDisabled);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldLocked { FieldId = fieldId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void HideField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.HideField(CreateCommand(new HideField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void HideField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.HideField(CreateCommand(new HideField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void HideField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.HideField(CreateCommand(new HideField { FieldId = 1 }));
|
|||
|
|||
// Assert.True(sut.Snapshot.SchemaDef.FieldsById[1].IsHidden);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldHidden { FieldId = fieldId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ShowField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ShowField(CreateCommand(new ShowField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ShowField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.ShowField(CreateCommand(new ShowField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void ShowField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.HideField(CreateCommand(new HideField { FieldId = 1 }));
|
|||
// sut.ShowField(CreateCommand(new ShowField { FieldId = 1 }));
|
|||
|
|||
// Assert.False(sut.Snapshot.SchemaDef.FieldsById[1].IsHidden);
|
|||
|
|||
// sut.GetUncomittedEvents().Skip(1)
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldShown { FieldId = fieldId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DisableField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.DisableField(CreateCommand(new DisableField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DisableField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.DisableField(CreateCommand(new DisableField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DisableField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.DisableField(CreateCommand(new DisableField { FieldId = 1 }));
|
|||
|
|||
// Assert.True(sut.Snapshot.SchemaDef.FieldsById[1].IsDisabled);
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldDisabled { FieldId = fieldId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void EnableField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.EnableField(CreateCommand(new EnableField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void EnableField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.EnableField(CreateCommand(new EnableField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void EnableField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.DisableField(CreateCommand(new DisableField { FieldId = 1 }));
|
|||
// sut.EnableField(CreateCommand(new EnableField { FieldId = 1 }));
|
|||
|
|||
// Assert.False(sut.Snapshot.SchemaDef.FieldsById[1].IsDisabled);
|
|||
|
|||
// sut.GetUncomittedEvents().Skip(1)
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldEnabled { FieldId = fieldId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DeleteField_should_throw_exception_if_not_created()
|
|||
// {
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.DeleteField(CreateCommand(new DeleteField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DeleteField_should_throw_exception_if_schema_is_deleted()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// DeleteSchema();
|
|||
|
|||
// Assert.Throws<DomainException>(() =>
|
|||
// {
|
|||
// sut.DeleteField(CreateCommand(new DeleteField { FieldId = 1 }));
|
|||
// });
|
|||
// }
|
|||
|
|||
// [Fact]
|
|||
// public void DeleteField_should_update_schema_and_create_events()
|
|||
// {
|
|||
// CreateSchema();
|
|||
// CreateField();
|
|||
|
|||
// sut.DeleteField(CreateCommand(new DeleteField { FieldId = 1 }));
|
|||
|
|||
// Assert.False(sut.Snapshot.SchemaDef.FieldsById.ContainsKey(1));
|
|||
|
|||
// sut.GetUncomittedEvents()
|
|||
// .ShouldHaveSameEvents(
|
|||
// CreateEvent(new FieldDeleted { FieldId = fieldId })
|
|||
// );
|
|||
// }
|
|||
|
|||
// private void CreateField()
|
|||
// {
|
|||
// sut.Add(CreateCommand(new AddField { Name = fieldName, Properties = new NumberFieldProperties() }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void CreateSchema()
|
|||
// {
|
|||
// sut.Create(CreateCommand(new CreateSchema { Name = SchemaName }));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void PublishSchema()
|
|||
// {
|
|||
// sut.Publish(CreateCommand(new PublishSchema()));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private void DeleteSchema()
|
|||
// {
|
|||
// sut.Delete(CreateCommand(new DeleteSchema()));
|
|||
// sut.ClearUncommittedEvents();
|
|||
// }
|
|||
|
|||
// private static StringFieldProperties ValidProperties()
|
|||
// {
|
|||
// return new StringFieldProperties { MinLength = 10, MaxLength = 20 };
|
|||
// }
|
|||
|
|||
// private static StringFieldProperties InvalidProperties()
|
|||
// {
|
|||
// return new StringFieldProperties { MinLength = 20, MaxLength = 10 };
|
|||
// }
|
|||
// }
|
|||
//}
|
|||
@ -0,0 +1,439 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschränkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Orleans.Core; |
|||
using Orleans.Runtime; |
|||
using Squidex.Domain.Apps.Core.Schemas; |
|||
using Squidex.Domain.Apps.Entities.Schemas.Commands; |
|||
using Squidex.Domain.Apps.Entities.Schemas.State; |
|||
using Squidex.Domain.Apps.Entities.TestHelpers; |
|||
using Squidex.Domain.Apps.Events.Schemas; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.States; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Schemas |
|||
{ |
|||
public class SchemaGrainTests : HandlerTestBase<SchemaGrain, SchemaState> |
|||
{ |
|||
private readonly IAppProvider appProvider = A.Fake<IAppProvider>(); |
|||
private readonly FieldRegistry registry = new FieldRegistry(new TypeNameRegistry()); |
|||
private readonly string fieldName = "age"; |
|||
private readonly NamedId<long> fieldId; |
|||
private readonly SchemaGrain sut; |
|||
|
|||
public sealed class MySchemaGrain : SchemaGrain |
|||
{ |
|||
public MySchemaGrain(IStore<Guid> store, IAppProvider appProvider, FieldRegistry registry, IGrainIdentity identity, IGrainRuntime runtime) |
|||
: base(store, appProvider, registry, identity, runtime) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
protected override Guid Id |
|||
{ |
|||
get { return SchemaId; } |
|||
} |
|||
|
|||
public SchemaGrainTests() |
|||
{ |
|||
A.CallTo(() => appProvider.GetSchemaAsync(AppId, SchemaName)) |
|||
.Returns((ISchemaEntity)null); |
|||
|
|||
fieldId = new NamedId<long>(1, fieldName); |
|||
|
|||
sut = new MySchemaGrain(Store, appProvider, registry, Identity, Runtime); |
|||
sut.OnActivateAsync().Wait(); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Command_should_throw_exception_if_rule_is_deleted() |
|||
{ |
|||
await ExecuteCreateAsync(); |
|||
await ExecuteDeleteAsync(); |
|||
|
|||
await Assert.ThrowsAsync<DomainException>(ExecutePublishAsync); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_schema_and_create_events() |
|||
{ |
|||
var properties = new SchemaProperties(); |
|||
|
|||
var command = new CreateSchema { Name = SchemaName, SchemaId = SchemaId, Properties = properties }; |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(EntityCreatedResult.Create(Id, 0)); |
|||
|
|||
Assert.Equal(AppId, sut.Snapshot.AppId.Id); |
|||
|
|||
Assert.Equal(SchemaName, sut.Snapshot.Name); |
|||
Assert.Equal(SchemaName, sut.Snapshot.SchemaDef.Name); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new SchemaCreated { Name = SchemaName, Properties = properties }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Create_should_create_schema_with_initial_fields() |
|||
{ |
|||
var properties = new SchemaProperties(); |
|||
|
|||
var fields = new List<CreateSchemaField> |
|||
{ |
|||
new CreateSchemaField { Name = "field1", Properties = ValidProperties() }, |
|||
new CreateSchemaField { Name = "field2", Properties = ValidProperties() } |
|||
}; |
|||
|
|||
var command = new CreateSchema { Name = SchemaName, SchemaId = SchemaId, Properties = properties, Fields = fields }; |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(EntityCreatedResult.Create(Id, 0)); |
|||
|
|||
var @event = (SchemaCreated)LastEvents.Single().Payload; |
|||
|
|||
Assert.Equal(AppId, sut.Snapshot.AppId.Id); |
|||
Assert.Equal(SchemaName, sut.Snapshot.Name); |
|||
Assert.Equal(SchemaName, sut.Snapshot.SchemaDef.Name); |
|||
|
|||
Assert.Equal(2, @event.Fields.Count); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Update_should_create_events_and_update_state() |
|||
{ |
|||
var command = new UpdateSchema { Properties = new SchemaProperties() }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(1)); |
|||
|
|||
Assert.Equal(command.Properties, sut.Snapshot.SchemaDef.Properties); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new SchemaUpdated { Properties = command.Properties }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ConfigureScripts_should_create_events() |
|||
{ |
|||
var command = new ConfigureScripts |
|||
{ |
|||
ScriptQuery = "<script-query>", |
|||
ScriptCreate = "<script-create>", |
|||
ScriptUpdate = "<script-update>", |
|||
ScriptDelete = "<script-delete>", |
|||
ScriptChange = "<script-change>" |
|||
}; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(1)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new ScriptsConfigured |
|||
{ |
|||
ScriptQuery = "<script-query>", |
|||
ScriptCreate = "<script-create>", |
|||
ScriptUpdate = "<script-update>", |
|||
ScriptDelete = "<script-delete>", |
|||
ScriptChange = "<script-change>" |
|||
}) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Reorder_should_create_events_and_update_state() |
|||
{ |
|||
var command = new ReorderFields { FieldIds = new List<long> { 1, 2 } }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync("field1"); |
|||
await ExecuteAddFieldAsync("field2"); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(3)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new SchemaFieldsReordered { FieldIds = command.FieldIds }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Publish_should_create_events_and_update_state() |
|||
{ |
|||
var command = new PublishSchema(); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(1)); |
|||
|
|||
Assert.True(sut.Snapshot.SchemaDef.IsPublished); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new SchemaPublished()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Unpublish_should_create_events_and_update_state() |
|||
{ |
|||
var command = new UnpublishSchema(); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecutePublishAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.False(sut.Snapshot.SchemaDef.IsPublished); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new SchemaUnpublished()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Delete_should_create_events_and_update_state() |
|||
{ |
|||
var command = new DeleteSchema(); |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(1)); |
|||
|
|||
Assert.True(sut.Snapshot.IsDeleted); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new SchemaDeleted()) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Add_should_create_events_and_update_state() |
|||
{ |
|||
var command = new AddField { Name = fieldName, Properties = ValidProperties() }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(EntityCreatedResult.Create(1, 1)); |
|||
|
|||
Assert.Equal(command.Properties, sut.Snapshot.SchemaDef.FieldsById[1].RawProperties); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldAdded { Name = fieldName, FieldId = fieldId, Properties = command.Properties }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task UpdateField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new UpdateField { FieldId = 1, Properties = new StringFieldProperties() }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.Equal(command.Properties, sut.Snapshot.SchemaDef.FieldsById[1].RawProperties); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldUpdated { FieldId = fieldId, Properties = command.Properties }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task LockField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new LockField { FieldId = 1 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.False(sut.Snapshot.SchemaDef.FieldsById[1].IsDisabled); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldLocked { FieldId = fieldId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task HideField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new HideField { FieldId = 1 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.True(sut.Snapshot.SchemaDef.FieldsById[1].IsHidden); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldHidden { FieldId = fieldId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task ShowField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new ShowField { FieldId = 1 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
await ExecuteHideFieldAsync(1); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(3)); |
|||
|
|||
Assert.False(sut.Snapshot.SchemaDef.FieldsById[1].IsHidden); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldShown { FieldId = fieldId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DisableField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new DisableField { FieldId = 1 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.True(sut.Snapshot.SchemaDef.FieldsById[1].IsDisabled); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldDisabled { FieldId = fieldId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task EnableField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new EnableField { FieldId = 1 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
await ExecuteDisableFieldAsync(1); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(3)); |
|||
|
|||
Assert.False(sut.Snapshot.SchemaDef.FieldsById[1].IsDisabled); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldEnabled { FieldId = fieldId }) |
|||
); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task DeleteField_should_create_events_and_update_state() |
|||
{ |
|||
var command = new DeleteField { FieldId = 1 }; |
|||
|
|||
await ExecuteCreateAsync(); |
|||
await ExecuteAddFieldAsync(fieldName); |
|||
|
|||
var result = await sut.ExecuteAsync(J(CreateCommand(command))); |
|||
|
|||
result.ShouldBeEquaivalent(new EntitySavedResult(2)); |
|||
|
|||
Assert.False(sut.Snapshot.SchemaDef.FieldsById.ContainsKey(1)); |
|||
|
|||
LastEvents |
|||
.ShouldHaveSameEvents( |
|||
CreateEvent(new FieldDeleted { FieldId = fieldId }) |
|||
); |
|||
} |
|||
|
|||
private Task ExecuteCreateAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new CreateSchema { Name = SchemaName }))); |
|||
} |
|||
|
|||
private Task ExecuteAddFieldAsync(string name) |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new AddField { Properties = ValidProperties(), Name = name }))); |
|||
} |
|||
|
|||
private Task ExecuteHideFieldAsync(long id) |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new HideField { FieldId = id }))); |
|||
} |
|||
|
|||
private Task ExecuteDisableFieldAsync(long id) |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new DisableField { FieldId = id }))); |
|||
} |
|||
|
|||
private Task ExecutePublishAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new PublishSchema()))); |
|||
} |
|||
|
|||
private Task ExecuteDeleteAsync() |
|||
{ |
|||
return sut.ExecuteAsync(J(CreateCommand(new DeleteSchema()))); |
|||
} |
|||
|
|||
private static StringFieldProperties ValidProperties() |
|||
{ |
|||
return new StringFieldProperties { MinLength = 10, MaxLength = 20 }; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue