private AssetCommand CreateCommandCore(BulkTask task) { var job = task.CommandJob; switch (job.Type) { case BulkUpdateAssetType.Annotate: { var command = new AnnotateAsset(); EnrichAndCheckPermission(task, command, Permissions.AppAssetsUpdate); return(command); } case BulkUpdateAssetType.Move: { var command = new MoveAsset(); EnrichAndCheckPermission(task, command, Permissions.AppAssetsUpdate); return(command); } case BulkUpdateAssetType.Delete: { var command = new DeleteAsset(); EnrichAndCheckPermission(task, command, Permissions.AppAssetsDelete); return(command); } default: throw new NotSupportedException(); } }
public async Task CanMove_should_not_throw_exception_when_folder_has_not_changed() { var command = new MoveAsset { AppId = appId, ParentId = DomainId.NewGuid() }; await GuardAsset.CanMove(command, assetQuery, command.ParentId); }
public async Task CanMove_should_not_throw_exception_when_added_to_root() { var command = new MoveAsset { AppId = appId }; await GuardAsset.CanMove(command, assetQuery, DomainId.NewGuid()); }
public async Task CanMove_should_not_throw_exception_if_added_to_root() { var command = new MoveAsset { AppId = appId }; await GuardAsset.CanMove(command, Asset(), assetQuery); }
public async Task CanMove_should_throw_exception_when_folder_has_not_changed() { var command = new MoveAsset { ParentId = Guid.NewGuid() }; await ValidationAssert.ThrowsAsync(() => GuardAsset.CanMove(command, assetQuery, command.ParentId), new ValidationError("Asset is already part of this folder.", "ParentId")); }
public async Task CanMove_should_not_throw_exception_if_folder_has_not_changed() { var parentId = DomainId.NewGuid(); var command = new MoveAsset { AppId = appId, ParentId = parentId }; await GuardAsset.CanMove(command, Asset(parentId : parentId), assetQuery); }
public async Task CanMove_should_throw_exception_when_folder_not_found() { var command = new MoveAsset { AppId = appId, ParentId = DomainId.NewGuid() }; A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) .Returns(new List <IAssetFolderEntity>()); await ValidationAssert.ThrowsAsync(() => GuardAsset.CanMove(command, assetQuery, DomainId.NewGuid()), new ValidationError("Asset folder does not exist.", "ParentId")); }
public static Task CanMove(MoveAsset command, IAssetQueryService assetQuery, Guid oldParentId) { Guard.NotNull(command); return(Validate.It(() => "Cannot move asset.", async e => { if (command.ParentId != oldParentId) { await CheckPathAsync(command.ParentId, assetQuery, e); } })); }
public static Task CanMove(MoveAsset command, IAssetEntity asset, IAssetQueryService assetQuery) { Guard.NotNull(command, nameof(command)); return(Validate.It(async e => { if (command.ParentId != asset.ParentId) { await CheckPathAsync(command.AppId.Id, command.ParentId, assetQuery, e); } })); }
public async Task CanMove_should_not_throw_exception_when_folder_found() { var command = new MoveAsset { AppId = appId, ParentId = DomainId.NewGuid() }; A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) .Returns(new List <IAssetFolderEntity> { CreateFolder() }); await GuardAsset.CanMove(command, assetQuery, DomainId.NewGuid()); }
public async Task CanMove_should_not_throw_exception_if_folder_not_found_but_optimized() { var parentId = DomainId.NewGuid(); var command = new MoveAsset { AppId = appId, ParentId = parentId, OptimizeValidation = true }; A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) .Returns(new List <IAssetFolderEntity>()); await GuardAsset.CanMove(command, Asset(), assetQuery); }
private async Task MoveCore(MoveAsset move, AssetOperation operation) { if (!move.OptimizeValidation) { await operation.MustMoveToValidFolder(move.ParentId); } if (!move.DoNotScript) { await operation.ExecuteMoveScriptAsync(move); } Move(move); }
public async Task CanMove_should_not_throw_exception_if_folder_found() { var parentId = DomainId.NewGuid(); var command = new MoveAsset { AppId = appId, ParentId = parentId }; A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, default)) .Returns(new List <IAssetFolderEntity> { AssetFolder() }); await GuardAsset.CanMove(command, Asset(), assetQuery); }
public static Task CanMove(MoveAsset command, IAssetQueryService assetQuery, Guid oldParentId) { Guard.NotNull(command); return(Validate.It(() => "Cannot move asset.", async e => { if (command.ParentId == oldParentId) { e("Asset is already part of this folder.", nameof(command.ParentId)); } else { await CheckPathAsync(command.ParentId, assetQuery, e); } })); }
public static Task CanMove(MoveAsset command, IAssetEntity asset, IAssetQueryService assetQuery) { Guard.NotNull(command, nameof(command)); return(Validate.It(async e => { var parentId = command.ParentId; if (parentId != asset.ParentId && parentId != DomainId.Empty && !command.OptimizeValidation) { var path = await assetQuery.FindAssetFolderAsync(command.AppId.Id, parentId); if (path.Count == 0) { e(T.Get("assets.folderNotFound"), nameof(MoveAsset.ParentId)); } } })); }
public async Task Move_should_create_events_and_update_state() { var command = new MoveAsset { ParentId = parentId }; await ExecuteCreateAsync(); var result = await PublishIdempotentAsync(command); result.ShouldBeEquivalent2(sut.Snapshot); Assert.Equal(parentId, sut.Snapshot.ParentId); LastEvents .ShouldHaveSameEvents( CreateAssetEvent(new AssetMoved { ParentId = parentId }) ); }
public static async Task ExecuteMoveScriptAsync(this AssetOperation operation, MoveAsset move) { var script = operation.App.AssetScripts?.Move; if (string.IsNullOrWhiteSpace(script)) { return; } var parentPath = await GetPathAsync(operation, move.ParentId); var vars = new ScriptVars { // Use a dictionary for better performance, because no reflection is involved. [ScriptKeys.Command] = new Dictionary <string, object?> { [ScriptKeys.ParentId] = move.ParentId, [ScriptKeys.ParentPath] = parentPath }, [ScriptKeys.Operation] = "Move" }; await ExecuteScriptAsync(operation, script, vars); }
public static async Task ExecuteMoveScriptAsync(this AssetOperation operation, MoveAsset move) { var script = operation.App.AssetScripts?.Move; if (string.IsNullOrWhiteSpace(script)) { return; } var parentPath = await GetPathAsync(operation, move.ParentId); // Script vars are just wrappers over dictionaries for better performance. var vars = new AssetScriptVars { Command = new AssetCommandScriptVars { ParentId = move.ParentId, ParentPath = parentPath }, Operation = "Move" }; await ExecuteScriptAsync(operation, script, vars); }
private void Move(MoveAsset command) { Raise(command, new AssetMoved()); }
private async Task MoveCore(MoveAsset move) { await GuardAsset.CanMove(move, Snapshot, assetQuery); Move(move); }
public void Move(MoveAsset command) { RaiseEvent(SimpleMapper.Map(command, new AssetMoved())); }
public void Move(MoveAsset command) { Raise(command, new AssetMoved()); }