Esempio n. 1
0
        private static void TestMoveDir()
        {
            string undoFileName = VirtualDrive.VirtualFileName(
                "TestFileCopyProcessorUndoFile.txt");

            string srcDir   = VirtualDrive.VirtualFileName(@"srcFolder\folder0");
            string srcFile0 = Path.Combine(srcDir, "t0.bin");
            string srcFile1 = Path.Combine(srcDir, "t1.bin");

            string dstDir   = VirtualDrive.VirtualFileName(@"dstFolder\folder1");
            string dstFile0 = Path.Combine(dstDir, "t0.bin");
            string dstFile1 = Path.Combine(dstDir, "t1.bin");

            VirtualDrive.Store(VirtualDrive.VirtualFileName(srcFile0), null);
            VirtualDrive.Store(VirtualDrive.VirtualFileName(srcFile1), null);

            UnitTest.Test(VirtualDrive.ExistsDirectory(srcDir));
            UnitTest.Test(!VirtualDrive.ExistsDirectory(dstDir));
            UnitTest.Test(VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(srcFile1));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileOperationProcessor p = new FileOperationProcessor();
                p.Operation = FileOperationProcessor.FileOperation.Move;
                p.UndoFile  = undoFileWriter;
                p.NewName   = dstDir;

                p.Process(new DirectoryInfo(srcDir));
            }

            UnitTest.Test(!VirtualDrive.ExistsDirectory(srcDir));
            UnitTest.Test(VirtualDrive.ExistsDirectory(dstDir));
            UnitTest.Test(VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(dstFile1));

            UndoFilePlayer.Undo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsDirectory(srcDir));
            UnitTest.Test(!VirtualDrive.ExistsDirectory(dstDir));
            UnitTest.Test(VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(srcFile1));
            UnitTest.Test(!VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(dstFile1));

            UndoFilePlayer.Redo(undoFileName);

            UnitTest.Test(!VirtualDrive.ExistsDirectory(srcDir));
            UnitTest.Test(VirtualDrive.ExistsDirectory(dstDir));
            UnitTest.Test(!VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(srcFile1));
            UnitTest.Test(VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(dstFile1));

            VirtualDrive.DeleteDirectory(dstDir, true);
        }
Esempio n. 2
0
        private static void TestCopyDir()
        {
            string undoFileName = VirtualDrive.VirtualFileName(
                "TestFileCopyProcessorUndoFile.txt");

            string folder0    = VirtualDrive.VirtualFileName("folder0");
            string filename00 = Path.Combine(folder0, "t0.bin");
            string filename01 = Path.Combine(folder0, "t1.bin");

            string folder1    = VirtualDrive.VirtualFileName("folder1");
            string filename10 = Path.Combine(folder1, "t0.bin");
            string filename11 = Path.Combine(folder1, "t1.bin");

            VirtualDrive.Store(VirtualDrive.VirtualFileName(filename00), null);
            VirtualDrive.Store(VirtualDrive.VirtualFileName(filename01), null);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(!VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename00));
            UnitTest.Test(VirtualDrive.ExistsFile(filename01));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileOperationProcessor p = new FileOperationProcessor();
                p.Operation = FileOperationProcessor.FileOperation.Copy;
                p.UndoFile  = undoFileWriter;
                p.NewName   = folder1;

                p.Process(new DirectoryInfo(folder0));
            }

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(VirtualDrive.ExistsFile(filename11));

            UndoFilePlayer.Undo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(!VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename00));
            UnitTest.Test(VirtualDrive.ExistsFile(filename01));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename11));

            UndoFilePlayer.Redo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(VirtualDrive.ExistsFile(filename11));

            VirtualDrive.DeleteDirectory(folder0, true);
            VirtualDrive.DeleteDirectory(folder1, true);
        }
Esempio n. 3
0
        private static void TestMoveFile_AlreadyExists_Overwrite()
        {
            SetupRecycleBin();

            string undoFileName = VirtualDrive.VirtualFileName(
                "TestMoveFile_AlreadyExists_Overwrite.txt");

            string folder0   = VirtualDrive.VirtualFileName("folder0");
            string filename0 = Path.Combine(folder0, "t0.bin");
            string filename1 = Path.Combine(folder0, "t1.bin");

            string recycleBin   = VirtualDrive.VirtualFileName(@"recycle");
            string recycleFile0 = Path.Combine(recycleBin, "1.trash");

            byte[] data0 = new byte[] { 0 };
            VirtualDrive.Store(filename0, data0);

            byte[] data1 = new byte[] { 1 };
            VirtualDrive.Store(filename1, data1);

            UnitTest.Test(VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(VirtualDrive.ExistsFile(filename1));
            UnitTest.Test(!VirtualDrive.ExistsFile(recycleFile0));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileOperationProcessor p = new FileOperationProcessor();
                p.Operation = FileOperationProcessor.FileOperation.Move;
                p.UndoFile  = undoFileWriter;
                p.NewName   = "t1.bin";
                p.Conflicts = FileOperationProcessor.ConflictSolving.Overwrite;

                p.Process(new FileInfo(filename0));
            }

            UnitTest.Test(!VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(VirtualDrive.ExistsFile(filename1));
            UnitTest.Test(VirtualDrive.ExistsFile(recycleFile0));
            UnitTest.Test(VirtualDrive.Load(filename1).SequenceEqual(data0));

            UndoFilePlayer.Undo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(VirtualDrive.ExistsFile(filename1));
            UnitTest.Test(!VirtualDrive.ExistsFile(recycleFile0));

            UndoFilePlayer.Redo(undoFileName);

            UnitTest.Test(!VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(VirtualDrive.ExistsFile(filename1));
            UnitTest.Test(VirtualDrive.ExistsFile(recycleFile0));
        }
Esempio n. 4
0
        private static void TestCopyFile()
        {
            string undoFileName = VirtualDrive.VirtualFileName(
                "TestFileCopyProcessorUndoFile.txt");

            string folder0   = VirtualDrive.VirtualFileName("folder0");
            string filename0 = Path.Combine(folder0, "t0.bin");
            string filename1 = Path.Combine(folder0, "t1.bin");

            byte[] data = new byte[] { 0 };
            VirtualDrive.Store(filename0, data);

            UnitTest.Test(VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename1));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileOperationProcessor p = new FileOperationProcessor();
                p.Operation = FileOperationProcessor.FileOperation.Copy;
                p.UndoFile  = undoFileWriter;
                p.NewName   = "t1.bin";

                p.Process(new FileInfo(filename0));
            }

            UnitTest.Test(VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(VirtualDrive.ExistsFile(filename1));

            UndoFilePlayer.Undo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename1));

            UndoFilePlayer.Redo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsFile(filename0));
            UnitTest.Test(VirtualDrive.ExistsFile(filename1));

            VirtualDrive.DeleteDirectory(folder0, true);
        }
Esempio n. 5
0
        private static void TestMoveDir_AlreadyExists_Overwrite()
        {
            SetupRecycleBin();

            string undoFileName = VirtualDrive.VirtualFileName(
                "TestFileCopyProcessorUndoFile.txt");

            string folder0 = VirtualDrive.VirtualFileName(@"fold00\folder0");
            string folder1 = VirtualDrive.VirtualFileName(@"fold01\folder1");

            string srcFile0     = Path.Combine(folder0, "t0.bin");
            string replaceFile0 = Path.Combine(folder1, "t1.bin");
            string dstFile0     = Path.Combine(folder1, "t0.bin");

            string recycleBin   = VirtualDrive.VirtualFileName(@"recycle");
            string recycleFile0 = Path.Combine(Path.Combine(recycleBin, "0"), "t1.bin");

            VirtualDrive.Store(VirtualDrive.VirtualFileName(srcFile0), null);
            VirtualDrive.Store(VirtualDrive.VirtualFileName(replaceFile0), null);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(replaceFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(recycleFile0));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileOperationProcessor p = new FileOperationProcessor();
                p.Operation = FileOperationProcessor.FileOperation.Move;
                p.UndoFile  = undoFileWriter;
                p.NewName   = folder1;
                p.Conflicts = FileOperationProcessor.ConflictSolving.Overwrite;

                p.Process(new DirectoryInfo(folder0));
            }

            UnitTest.Test(!VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(!VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(replaceFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(recycleFile0));

            UndoFilePlayer.Undo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(replaceFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(recycleFile0));

            UndoFilePlayer.Redo(undoFileName);

            UnitTest.Test(!VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(!VirtualDrive.ExistsFile(srcFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(dstFile0));
            UnitTest.Test(!VirtualDrive.ExistsFile(replaceFile0));
            UnitTest.Test(VirtualDrive.ExistsFile(recycleFile0));

            VirtualDrive.DeleteDirectory(folder1, true);
            VirtualDrive.DeleteDirectory(recycleBin, true);
        }
Esempio n. 6
0
        private static void TestMoveDir_AlreadyExists_Skip()
        {
            string undoFileName = VirtualDrive.VirtualFileName(
                "TestMoveDir_AlreadyExists_Skip.txt");

            string folder0    = VirtualDrive.VirtualFileName(@"fold00\folder0");
            string filename00 = Path.Combine(folder0, "t0.bin");
            string filename01 = Path.Combine(folder0, "t1.bin");

            string folder1    = VirtualDrive.VirtualFileName(@"fold01\folder1");
            string filename10 = Path.Combine(folder1, "t0.bin");
            string filename11 = Path.Combine(folder1, "t1.bin");

            VirtualDrive.Store(VirtualDrive.VirtualFileName(filename00), null);
            VirtualDrive.Store(VirtualDrive.VirtualFileName(filename01), null);
            VirtualDrive.Store(VirtualDrive.VirtualFileName(filename10), null);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename00));
            UnitTest.Test(VirtualDrive.ExistsFile(filename01));
            UnitTest.Test(VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename11));

            using (UndoFileWriter undoFileWriter = new UndoFileWriter(undoFileName))
            {
                FileOperationProcessor p = new FileOperationProcessor();
                p.Operation = FileOperationProcessor.FileOperation.Move;
                p.UndoFile  = undoFileWriter;
                p.NewName   = folder1;
                p.Conflicts = FileOperationProcessor.ConflictSolving.Skip;

                p.Process(new DirectoryInfo(folder0));
            }

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename00));
            UnitTest.Test(VirtualDrive.ExistsFile(filename01));
            UnitTest.Test(VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename11));

            UndoFilePlayer.Undo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename00));
            UnitTest.Test(VirtualDrive.ExistsFile(filename01));
            UnitTest.Test(VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename11));

            UndoFilePlayer.Redo(undoFileName);

            UnitTest.Test(VirtualDrive.ExistsDirectory(folder0));
            UnitTest.Test(VirtualDrive.ExistsDirectory(folder1));
            UnitTest.Test(VirtualDrive.ExistsFile(filename00));
            UnitTest.Test(VirtualDrive.ExistsFile(filename01));
            UnitTest.Test(VirtualDrive.ExistsFile(filename10));
            UnitTest.Test(!VirtualDrive.ExistsFile(filename11));

            VirtualDrive.DeleteDirectory(folder0, true);
            VirtualDrive.DeleteDirectory(folder1, true);
        }