public StorageThumbnailFilesystemTest() { var createNewImage = new CreateAnImage(); var appSettings = new AppSettings { ThumbnailTempFolder = createNewImage.BasePath }; _thumbnailStorage = new StorageThumbnailFilesystem(appSettings, new FakeIWebLogger()); _fileNameWithoutExtension = FilenamesHelper.GetFileNameWithoutExtension(createNewImage.FileName); }
public async Task ThumbnailCleanerTestAsync_Cleaner() { var createAnImage = new CreateAnImage(); var existFullDir = createAnImage.BasePath + Path.DirectorySeparatorChar + "thumb"; if (!Directory.Exists(existFullDir)) { Directory.CreateDirectory(existFullDir); } if (!File.Exists(Path.Join(existFullDir, "EXIST.jpg"))) { File.Copy(createAnImage.FullFilePath, Path.Join(existFullDir, "EXIST.jpg")); } if (!File.Exists(Path.Join(existFullDir, "DELETE.jpg"))) { File.Copy(createAnImage.FullFilePath, Path.Join(existFullDir, "DELETE.jpg")); } await _query.AddItemAsync(new FileIndexItem { FileHash = "EXIST", FileName = "exst2" }); var appSettings = new AppSettings { ThumbnailTempFolder = existFullDir, Verbose = true }; var thumbnailStorage = new StorageThumbnailFilesystem(appSettings, new FakeIWebLogger()); var thumbnailCleaner = new ThumbnailCleaner(thumbnailStorage, _query, new FakeIWebLogger()); // there are now two files inside this dir var allThumbnailFilesBefore = thumbnailStorage.GetAllFilesInDirectory("/"); Assert.AreEqual(2, allThumbnailFilesBefore.Count()); await thumbnailCleaner.CleanAllUnusedFilesAsync(); // DELETE.jpg is removed > is missing in database var allThumbnailFilesAfter = thumbnailStorage.GetAllFilesInDirectory("/"); Assert.AreEqual(1, allThumbnailFilesAfter.Count()); new StorageHostFullPathFilesystem().FolderDelete(existFullDir); }