public async Task RefreshRightItemStatusesAndCommandsFromChilds_CheckCommands(string strRightStatus)
        {
            var rightStatus = Enum.Parse <ItemStatusEnum>(strRightStatus);

            var usedCommands = new List <string>(); // Наименования элемнтов, чьи команды будут выполнены.

            var testSynchronizedItems = new TestSynchronizedItems(null);

            for (byte i = 0; i < 4; i++)
            {
                var childSynchronizedItems = new TestSynchronizedItems("Test" + i.ToString());
                testSynchronizedItems.ChildItemsList.Add(childSynchronizedItems);

                // Запишем команды синхронизации для каждого элемента.
                childSynchronizedItems.RightItem.SyncCommand.SetCommandAction(() =>
                {
                    return(Task.Run(() => usedCommands.Add(childSynchronizedItems.RightItem.Name)));
                });

                // Лишь половина элементов будет иметь статус для синхронизации и лишь команды этих элементов должны быть выполнены.
                childSynchronizedItems.RightItem.UpdateStatus(i % 2 == 0 ? rightStatus : ItemStatusEnum.Equally);
            }

            var synchronizedItemsStatusAndCommandsUpdater = new SynchronizedItemsStatusAndCommandsUpdater(null);

            synchronizedItemsStatusAndCommandsUpdater.RefreshRightItemStatusesAndCommandsFromChilds(testSynchronizedItems);
            await testSynchronizedItems.RightItem.SyncCommand.Process();

            Assert.Equal(2, usedCommands.Count);
            Assert.Equal("Test0", usedCommands[0]);
            Assert.Equal("Test2", usedCommands[1]);
        }
        public void RefreshRightItemStatusesAndCommandsFromChilds_UnknownChild()
        {
            var testSynchronizedItems = new TestSynchronizedItems(null);

            var childSynchronizedDirectories = new TestSynchronizedItems(null);

            childSynchronizedDirectories.RightItem.UpdateStatus(ItemStatusEnum.Unknown);
            testSynchronizedItems.ChildItemsList.Add(childSynchronizedDirectories);

            var level2Child1 = new TestSynchronizedItems(null);

            level2Child1.RightItem.UpdateStatus(ItemStatusEnum.Older);
            level2Child1.RightItem.SyncCommand.SetCommandAction(() => { return(Task.FromResult(true)); });
            childSynchronizedDirectories.ChildItemsList.Add(level2Child1);

            var level2Child2 = new TestSynchronizedItems(null);

            level2Child2.RightItem.UpdateStatus(ItemStatusEnum.ThereIs);
            level2Child2.RightItem.SyncCommand.SetCommandAction(() => { return(Task.FromResult(true)); });
            childSynchronizedDirectories.ChildItemsList.Add(level2Child2);

            var synchronizedItemsStatusAndCommandsUpdater = new SynchronizedItemsStatusAndCommandsUpdater(null);

            synchronizedItemsStatusAndCommandsUpdater.RefreshRightItemStatusesAndCommandsFromChilds(testSynchronizedItems);

            // У дочерней строки должен остаться неопределённый статус.
            Assert.Equal(ItemStatusEnum.Unknown, childSynchronizedDirectories.RightItem.Status.StatusEnum);

            // Статусы родительской строки должны измениться на неопредёлённые.
            Assert.Equal(ItemStatusEnum.Unknown, testSynchronizedItems.RightItem.Status.StatusEnum);

            // Команд не должно быть ни у дочерней строки, ни у родительской.
            Assert.Null(childSynchronizedDirectories.RightItem.SyncCommand.CommandAction);
            Assert.Null(testSynchronizedItems.RightItem.SyncCommand.CommandAction);
        }
Esempio n. 3
0
        public async Task DeleteDirectoryRowEvent()
        {
            IRowViewModel deleteRowEventParent = null, deleteRowEventChild = null;

            using (var testDirectory = new Infrastructure.TestDirectory())
            {
                Infrastructure.TestDirectory.CreateFiles(testDirectory.CreateDirectory("Dir"), new Dictionary <string, DateTime>
                {
                    { "File", DateTime.Now }
                });

                var synchronizedDirectories = new TestSynchronizedItems(new Directory(testDirectory.FullPath, null, new ItemFactory()));
                var factory = new RowViewModelFactory();
                factory.DeleteRowEvent += (IRowViewModel parent, IRowViewModel child) =>
                {
                    deleteRowEventParent = parent;
                    deleteRowEventChild  = child;
                };

                var rowViewModel = factory.CreateRowViewModel(synchronizedDirectories);

                await synchronizedDirectories.Load();

                var level1Child = synchronizedDirectories.ChildItems[0];
                var level2Child = level1Child.ChildItems[0];

                ((TestSynchronizedItems)level1Child).IsDeleted();

                Assert.NotNull(deleteRowEventParent);
                Assert.NotNull(deleteRowEventChild);
                Assert.Equal(synchronizedDirectories.LeftItem.Name, deleteRowEventParent.LeftItem.Name);
                Assert.Equal(level1Child.LeftItem.Name, deleteRowEventChild.LeftItem.Name);
            }
        }
Esempio n. 4
0
 public void LoadChildItems()
 {
     if (_item is IDirectory)
     {
         foreach (var item in ((IDirectory)_item).Items)
         {
             var child = new TestSynchronizedItems(item);
             _childItems.Add(child);
             child.LoadChildItems();
         }
     }
 }
        public void RefreshRightItemStatusesAndCommandsFromChilds_CheckStatus(string rightStartStatus, string[] rightItemsStatuses, string rightExpectedStatus)
        {
            var testSynchronizedItems = new TestSynchronizedItems(null);

            testSynchronizedItems.RightItem.UpdateStatus((ItemStatusEnum)Enum.Parse(typeof(ItemStatusEnum), rightStartStatus));

            foreach (var rightItemStatus in rightItemsStatuses)
            {
                var childSynchronizedItems = new TestSynchronizedItems(null);
                childSynchronizedItems.RightItem.UpdateStatus((ItemStatusEnum)Enum.Parse(typeof(ItemStatusEnum), rightItemStatus));
                testSynchronizedItems.ChildItemsList.Add(childSynchronizedItems);
            }

            var synchronizedItemsStatusAndCommandsUpdater = new SynchronizedItemsStatusAndCommandsUpdater(null);

            synchronizedItemsStatusAndCommandsUpdater.RefreshRightItemStatusesAndCommandsFromChilds(testSynchronizedItems);

            Assert.Equal(rightExpectedStatus, testSynchronizedItems.RightItem.Status.StatusEnum.ToString());
        }