Example #1
0
        public async Task ItemsMoved_TestAsync()
        {
            var authentication = await this.TestContext.LoginRandomAsync(Authority.Admin);

            var typeItemFilter = new TypeItemFilter()
            {
                HasParent = true
            };
            var typeItem = await typeItemFilter.GetTypeItemAsync(dataBase);

            var parentItemFilter1 = new TypeItemFilter()
            {
                TargetToMove = typeItem
            };
            var parentItem1 = await parentItemFilter1.GetTypeItemAsync(dataBase);

            var actualPath            = string.Empty;
            var actualOldPath         = string.Empty;
            var actualOldParentPath   = string.Empty;
            var expectedOldPath       = typeItem.Path;
            var expectedOldParentPath = typeItem.Parent.Path;
            await typeContext.AddItemsMovedEventHandlerAsync(TypeContext_ItemsMoved);

            await typeItem.MoveAsync(authentication, parentItem1.Path);

            Assert.AreEqual(typeItem.Path, actualPath);
            Assert.AreEqual(expectedOldPath, actualOldPath);
            Assert.AreEqual(expectedOldParentPath, actualOldParentPath);
            var parentItemFilter2 = new TypeItemFilter()
            {
                TargetToMove = typeItem, ExcludedItems = new ITypeItem[] { parentItem1 }
            };
            var parentItem2 = await parentItemFilter2.GetTypeItemAsync(dataBase);

            await typeContext.RemoveItemsMovedEventHandlerAsync(TypeContext_ItemsMoved);

            await typeItem.MoveAsync(authentication, parentItem2.Path);

            Assert.AreNotEqual(typeItem.Path, actualPath);
            Assert.AreEqual(expectedOldPath, actualOldPath);
            Assert.AreEqual(expectedOldParentPath, actualOldParentPath);

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

                actualPath          = typeItem.Path;
                actualOldPath       = e.OldPaths.Single();
                actualOldParentPath = e.OldParentPaths.Single();
            }
        }