Пример #1
0
        private void AlphaFS_DirectoryInfo_MoveTo_DelayUntilReboot(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var folder = Alphaleonis.Win32.Filesystem.Directory.CreateDirectory(tempRoot.RandomDirectoryFullPath);

                var pendingEntry = folder.FullName;

                Console.WriteLine("Src Directory Path: [{0}]", pendingEntry);


                if (isNetwork)
                {
                    // Trigger DelayUntilReboot.
                    UnitTestAssert.ThrowsException <ArgumentException>(() => folder.MoveTo(null, Alphaleonis.Win32.Filesystem.MoveOptions.DelayUntilReboot));
                }

                else
                {
                    // Trigger DelayUntilReboot.
                    folder.MoveTo(null, Alphaleonis.Win32.Filesystem.MoveOptions.DelayUntilReboot);


                    UnitTestAssert.RegistryContainsPendingEntry(pendingEntry);
                }
            }

            Console.WriteLine();
        }
        private void AlphaFS_File_Move_DelayUntilReboot(bool isNetwork)
        {
            using (var tempRoot = new TemporaryDirectory(isNetwork))
            {
                var pendingEntry = tempRoot.CreateFile();

                var fileLength = pendingEntry.Length;

                Console.WriteLine("Src File Path: [{0}]", pendingEntry.FullName);


                if (isNetwork)
                {
                    UnitTestAssert.ThrowsException <ArgumentException>(() => Alphaleonis.Win32.Filesystem.File.Move(pendingEntry.FullName, null, Alphaleonis.Win32.Filesystem.MoveOptions.DelayUntilReboot));
                }

                else
                {
                    var moveResult = Alphaleonis.Win32.Filesystem.File.Move(pendingEntry.FullName, null, Alphaleonis.Win32.Filesystem.MoveOptions.DelayUntilReboot);


                    UnitTestConstants.Dump(moveResult);


                    UnitTestAssert.RegistryContainsPendingEntry(pendingEntry.FullName);


                    // Test against moveResult results.

                    Assert.IsFalse(moveResult.IsCopy);

                    Assert.IsTrue(moveResult.IsMove);

                    Assert.IsFalse(moveResult.IsDirectory);

                    Assert.IsTrue(moveResult.IsFile);

                    Assert.AreEqual(1, moveResult.TotalFiles);

                    Assert.AreEqual(0, moveResult.TotalFolders);

                    Assert.AreEqual(fileLength, moveResult.TotalBytes);

                    Assert.IsNull(moveResult.Destination);

                    Assert.IsTrue(System.IO.File.Exists(pendingEntry.FullName), "The file does not exists, but it is expected.");
                }
            }


            Console.WriteLine();
        }