public async Task RenameAsync(ITableCategory category, TaskContext context) { var authentication = context.Authentication; var categoryName = RandomUtility.NextIdentifier(); if (context.AllowException == false) { if (await VerifyAsync() == false) { return; } } await category.RenameAsync(authentication, categoryName); async Task <bool> VerifyAsync() { if ((await category.GetAllRelationTablesAsync(item => item.TableState != TableState.None)).Any() == true) { return(false); } return(await category.Dispatcher.InvokeAsync(() => { if (category.Parent == null) { return false; } if (category.Name == categoryName) { return false; } return true; })); } }
private async Task MoveTableCategoryAsync(Authentication authentication, ITableCategory sourceCategory, string newPath) { var destPath = new DataBasePath(newPath); var destObject = await this.GetObjectAsync(authentication, destPath.Path); var dataBase = sourceCategory.GetService(typeof(IDataBase)) as IDataBase; var tables = sourceCategory.GetService(typeof(ITableCollection)) as ITableCollection; if (destPath.DataBaseName != dataBase.Name) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destPath.Context != CremaSchema.TableDirectory) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (destObject is ITable) { throw new InvalidOperationException($"cannot move to : {destPath}"); } using (await UsingDataBase.SetAsync(dataBase, authentication)) { if (destObject is ITableCategory destCategory) { if (sourceCategory.Parent != destCategory) { await sourceCategory.MoveAsync(authentication, destCategory.Path); } } else { if (NameValidator.VerifyCategoryPath(destPath.ItemPath) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } var itemName = new ItemName(destPath.ItemPath); var categories = sourceCategory.GetService(typeof(ITableCategoryCollection)) as ITableCategoryCollection; if (await categories.ContainsAsync(itemName.CategoryPath) == false) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Name != itemName.Name && await tables.ContainsAsync(itemName.Name) == true) { throw new InvalidOperationException($"cannot move to : {destPath}"); } if (sourceCategory.Parent.Path != itemName.CategoryPath) { await sourceCategory.MoveAsync(authentication, itemName.CategoryPath); } if (sourceCategory.Name != itemName.Name) { await sourceCategory.RenameAsync(authentication, itemName.Name); } } } }
public async Task CategoryLockRenameTestAsync() { var newName = RandomUtility.NextIdentifier(); var parentPath = category.Parent.Path; var categoryPath = new CategoryName(parentPath, newName); await category.LockAsync(authentication, string.Empty); await category.RenameAsync(authentication, newName); Assert.AreEqual(categoryPath, category.Path); Assert.AreEqual(newName, category.Name); }