Example #1
0
        public void Clean_WithEmptyFolder_DoesNothing()
        {
            CreateTempFiles(_tempFolder, 6, TimeSpan.Zero);

            _folderCleaner.Clean(_tempFolder);

            Assert.IsTrue(Directory.Exists(_tempFolder), "The directory did not exist after cleaning up: " + _tempFolder);
        }
Example #2
0
        public void Clean_WithNonexistingPath_DoesNothing()
        {
            Directory.Delete(_tempFolder);

            var cleaner = new FolderCleaner(@"C:\SomeFolderThatDoesnotExist\With\Some\Sub\Folder");

            cleaner.Clean();
        }
Example #3
0
        public void Clean_WithEmptyFolder_DoesNothing()
        {
            CreateTempFiles(folderName: _tempFolder, numberOfFiles: 6, age: TimeSpan.Zero);

            var cleaner = new FolderCleaner(_tempFolder);

            cleaner.Clean();

            Assert.IsTrue(Directory.Exists(_tempFolder), "The directory did not exist after cleaning up: " + _tempFolder);
        }
Example #4
0
        public void Clean_WithSomeFiles_CleansAllFiles()
        {
            CreateTempFiles(_tempFolder, 4, TimeSpan.Zero);

            var cleaner = new FolderCleaner(_tempFolder);

            cleaner.Clean();

            Assert.IsTrue(Directory.Exists(_tempFolder), "The directory did not exist after cleaning up: " + _tempFolder);
            Assert.IsFalse(Directory.EnumerateFileSystemEntries(_tempFolder).Any(), "The directory is not empty after cleaning up: " + _tempFolder);
        }
        private void CleanFolder(string folder)
        {
            var folderCleaner = new FolderCleaner(folder);

            folderCleaner.Clean(_timeSpan);

            if (folderCleaner.CleanupExceptions.Any())
            {
                var exception = folderCleaner.CleanupExceptions.First();
                _logger.Debug($"Exception while cleaning up {exception.Key}: {exception.Value}");
            }
        }
Example #6
0
        public void Clean_WithSomeFilesAndSubfolder_CleansAllFilesAndRemovesSubfolders()
        {
            CreateTempFiles(_tempFolder, 6, TimeSpan.Zero);
            var subFolder = Path.Combine(_tempFolder, "Subfolder");

            Directory.CreateDirectory(subFolder);
            CreateTempFiles(subFolder, 6, TimeSpan.Zero);

            var cleaner = new FolderCleaner(_tempFolder);

            cleaner.Clean();

            Assert.IsTrue(Directory.Exists(_tempFolder), "The directory did not exist after cleaning up: " + _tempFolder);
            Assert.IsFalse(Directory.EnumerateFileSystemEntries(_tempFolder).Any(), "The directory is not empty after cleaning up: " + _tempFolder);
        }
Example #7
0
        public void CleanWithTimeSpan_WithSomeFiles_CleansAllFilesOlderThanTimeSpan()
        {
            CreateTempFiles(_tempFolder, 6, TimeSpan.FromDays(2));
            CreateSubFolderWithSomeFiles(6, TimeSpan.FromDays(2));
            var files = CreateSubFolderWithSomeFiles(1, TimeSpan.Zero);

            var cleaner = new FolderCleaner(_tempFolder);

            cleaner.Clean(TimeSpan.FromDays(1));

            Assert.IsTrue(Directory.Exists(_tempFolder), "The directory did not exist after cleaning up: " + _tempFolder);
            Assert.AreEqual(1, Directory.GetDirectories(_tempFolder).Count(), "There was more than one folder left");
            Assert.AreEqual(1, Directory.GetFiles(_tempFolder, "*", SearchOption.AllDirectories).Count(), "Found more than the one file after cleaning up");
            Assert.AreEqual(files.First(), Directory.GetFiles(_tempFolder, "*", SearchOption.AllDirectories).First());
        }