コード例 #1
0
        public void RecycleBinEnumTest()
        {
            // Setup files to delete
            var paths       = new Stack <string>();
            var sb          = new StringBuilder(Kernel32.MAX_PATH);
            var fileContent = new string('0', 1024);

            for (int i = 0; i < 5; i++)
            {
                MakeFile(tempDir);
            }
            for (int i = 0; i < 5; i++)
            {
                MakeFile(tempDir2);
            }

            try
            {
                var startCount = RecycleBin.Count;
                // Delete files to bin
                RecycleBin.DeleteToRecycleBin(paths, true);
                // Get details
                TestContext.WriteLine($"cnt={RecycleBin.Count}; sz={RecycleBin.Size}");
                Assert.That(RecycleBin.Count, Is.EqualTo(startCount + paths.Count));
                // Restore files
                RecycleBin.Restore(paths.Select(p => RecycleBin.GetItemFromOriginalPath(p)));
                Assert.That(RecycleBin.Count, Is.EqualTo(startCount));
            }
            finally
            {
                // Delete files completely
                while (paths.Count > 0)
                {
                    File.Delete(paths.Pop());
                }
            }

            void MakeFile(string dir)
            {
                Kernel32.GetTempFileName(dir, "tmp", 0, sb);
                paths.Push(sb.ToString());
                File.WriteAllText(paths.Peek(), fileContent);
            }
        }