public void TestRestoreDeletedItemsToNewDestination()

in AdlsDotNetSDKUnitTest/SdkUnitTest.cs [2683:2758]


        public void TestRestoreDeletedItemsToNewDestination()
        {
            // Restore file
            string streamName = GetFileOrFolderName("file");
            SetupTrashFile(streamName, "file");

            string path = $"{UnitTestDir}/" + streamName;
            _adlsClient.CreateFile(path, IfExists.Overwrite);

            Thread.Sleep(3000);

            IEnumerable<TrashEntry> trashEntries = _adlsClient.EnumerateDeletedItems(streamName, null, 1, null);
            Assert.IsTrue(trashEntries.Count() == 1);
            Assert.IsTrue(trashEntries.ElementAt(0).Type == TrashEntryType.FILE);

            string restoreToken = trashEntries.ElementAt(0).TrashDirPath;
            string destPath = trashEntries.ElementAt(0).OriginalPath;
            
            try
            {
                _adlsClient.RestoreDeletedItems(restoreToken, destPath, "file");
                Assert.IsTrue(false);
            }
            catch (AdlsException ex)
            {
                Assert.IsTrue(ex.HttpStatus == HttpStatusCode.Conflict);
            }

            destPath.Substring(0, destPath.LastIndexOf('/') + 1);
            String newName = GetFileOrFolderName("file");
            destPath += newName;

            _adlsClient.RestoreDeletedItems(restoreToken, destPath, "file");

            // Get file status on restored entry
            path.Substring(0, path.LastIndexOf('/') + 1);
            path += newName;
            DirectoryEntry diren = _adlsClient.GetDirectoryEntry(path);

            // Restore Directory
            string dirName = GetFileOrFolderName("directory");
            SetupTrashFile(dirName, "directory");

            path = $"{UnitTestDir}/" + dirName;
            bool result = _adlsClient.CreateDirectory(path);
            Assert.IsTrue(result);

            Thread.Sleep(3000);
            trashEntries = _adlsClient.EnumerateDeletedItems(dirName, null, 1, null);
            Assert.IsTrue(trashEntries.Count() == 1);
            Assert.IsTrue(trashEntries.ElementAt(0).Type == TrashEntryType.DIRECTORY);

            restoreToken = trashEntries.ElementAt(0).TrashDirPath;
            destPath = trashEntries.ElementAt(0).OriginalPath;
            
            try
            {
                _adlsClient.RestoreDeletedItems(restoreToken, destPath, "directory");
                Assert.IsTrue(false);
            }
            catch (AdlsException ex)
            {
                Assert.IsTrue(ex.HttpStatus == HttpStatusCode.Conflict);
            }

            destPath.Substring(0, destPath.LastIndexOf('/') + 1);
            newName = GetFileOrFolderName("file");
            destPath += newName;

            _adlsClient.RestoreDeletedItems(restoreToken, destPath, "directory");

            // Get file status on restored entry
            path.Substring(0, path.LastIndexOf('/') + 1);
            path += newName;
            diren = _adlsClient.GetDirectoryEntry(path);
        }