Beispiel #1
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);
            }
        }
Beispiel #2
0
        public void CreateRowViewModel()
        {
            const string file1Name = "File1";
            const string file2Name = "File2";

            using (var leftDirectory = new Infrastructure.TestDirectory())
                using (var rightDirectory = new Infrastructure.TestDirectory())
                {
                    leftDirectory.CreateFiles(new Dictionary <string, DateTime>
                    {
                        { file1Name, DateTime.Now },
                        { file2Name, DateTime.Now }
                    });
                    rightDirectory.CreateFiles(new Dictionary <string, DateTime>
                    {
                        { file1Name, DateTime.Now },
                        { file2Name, DateTime.Now }
                    });
                    bool useAddRowEvent = false;

                    var synchronizedDirectories = GetSynchronizedDirectories(leftDirectory.FullPath, rightDirectory.FullPath);
                    var factory = new RowViewModelFactory();
                    factory.AddRowEvent += (IRowViewModel parent, IRowViewModel child) => { useAddRowEvent = true; };
                    var rowViewModel = factory.CreateRowViewModel(synchronizedDirectories);

                    // Пока не выполнялась загрузка, события добавления записи происходить не должны.
                    Assert.False(useAddRowEvent);

                    Assert.Empty(rowViewModel.ChildRows);
                }
        }
Beispiel #3
0
        public async Task CreateRowViewModel_Tree()
        {
            const string name1           = "1";
            const string name2           = "2";
            byte         useAddRowsCount = 0;

            using (var leftDirectory = new Infrastructure.TestDirectory())
                using (var rightDirectory = new Infrastructure.TestDirectory())
                {
                    Infrastructure.TestDirectory.CreateFiles(leftDirectory.CreateDirectory(name1), new Dictionary <string, DateTime>
                    {
                        { name1, DateTime.Now }
                    });
                    Infrastructure.TestDirectory.CreateFiles(rightDirectory.CreateDirectory(name1), new Dictionary <string, DateTime>
                    {
                        { name1, DateTime.Now }
                    });

                    Infrastructure.TestDirectory.CreateFiles(leftDirectory.CreateDirectory(name2), new Dictionary <string, DateTime>
                    {
                        { name1, DateTime.Now }
                    });
                    Infrastructure.TestDirectory.CreateFiles(rightDirectory.CreateDirectory(name2), new Dictionary <string, DateTime>
                    {
                        { name1, DateTime.Now }
                    });

                    var synchronizedDirectories = GetSynchronizedDirectories(leftDirectory.FullPath, rightDirectory.FullPath);
                    var factory = new RowViewModelFactory();
                    factory.AddRowEvent += (IRowViewModel parent, IRowViewModel child) => { useAddRowsCount++; };
                    var rowViewModel = factory.CreateRowViewModel(synchronizedDirectories);

                    await synchronizedDirectories.Load();

                    Assert.Equal(4, useAddRowsCount);     // Две директории, в каждой директории по одному файлу.

                    Assert.Empty(rowViewModel.ChildRows); // А записей не прибавилось, потому что фабрика их не прибавляет.
                }
        }