Exemplo n.º 1
0
        public async Task ItemsRenamed_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var categoryFilter = new TypeCategoryFilter()
            {
                HasParent = true
            };
            var category = await categoryFilter.GetTypeCategoryAsync(dataBase);

            var actualName    = string.Empty;
            var actualPath    = string.Empty;
            var actualOldName = string.Empty;
            var actualOldPath = string.Empty;
            var expectedName  = await category.Parent.GenerateNewCategoryNameAsync();

            var expectedOldName = category.Name;
            var expectedOldPath = category.Path;
            await typeContext.AddItemsRenamedEventHandlerAsync(TypeContext_ItemsRenamed);

            await category.RenameAsync(authentication, expectedName);

            Assert.AreEqual(expectedName, actualName);
            Assert.AreEqual(category.Path, actualPath);
            Assert.AreEqual(expectedOldName, actualOldName);
            Assert.AreEqual(expectedOldPath, actualOldPath);
            await typeContext.RemoveItemsRenamedEventHandlerAsync(TypeContext_ItemsRenamed);

            await category.RenameAsync(authentication, RandomUtility.NextName());

            Assert.AreEqual(expectedName, actualName);
            Assert.AreNotEqual(category.Path, actualPath);
            Assert.AreEqual(expectedOldName, actualOldName);
            Assert.AreEqual(expectedOldPath, actualOldPath);

            void TypeContext_ItemsRenamed(object sender, ItemsRenamedEventArgs <ITypeItem> e)
            {
                var typeItem = e.Items.Single();

                actualName    = typeItem.Name;
                actualPath    = typeItem.Path;
                actualOldName = e.OldNames.Single();
                actualOldPath = e.OldPaths.Single();
            }
        }