Beispiel #1
0
        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);
        }
Beispiel #2
0
        public async Task ThumbnailCleanerTestAsync_Cleaner_WithDifferentSizes()
        {
            var fakeStorage = new FakeIStorage(new List <string> {
                "/"
            },
                                               new List <string>
            {
                ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.Large),
                ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.ExtraLarge),
                ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.TinyMeta),
                ThumbnailNameHelper.Combine("exist", ThumbnailSize.TinyMeta),
                ThumbnailNameHelper.Combine("exist", ThumbnailSize.ExtraLarge),
                ThumbnailNameHelper.Combine("exist", ThumbnailSize.TinyMeta),
                ThumbnailNameHelper.Combine("exist", ThumbnailSize.Large),
                ThumbnailNameHelper.Combine("12234456677", ThumbnailSize.ExtraLarge),
            });

            var fakeQuery = new FakeIQuery(new List <FileIndexItem>
            {
                new FileIndexItem("/test.jpg")
                {
                    FileHash = "exist"
                }
            });

            var thumbnailCleaner = new ThumbnailCleaner(fakeStorage, fakeQuery,
                                                        new FakeIWebLogger());

            await thumbnailCleaner.CleanAllUnusedFilesAsync(1);

            Assert.IsTrue(fakeStorage.ExistFile(
                              ThumbnailNameHelper.Combine("exist", ThumbnailSize.TinyMeta)));
            Assert.IsTrue(fakeStorage.ExistFile(
                              ThumbnailNameHelper.Combine("exist", ThumbnailSize.ExtraLarge)));
            Assert.IsTrue(fakeStorage.ExistFile(
                              ThumbnailNameHelper.Combine("exist", ThumbnailSize.Large)));
            Assert.IsTrue(fakeStorage.ExistFile(
                              ThumbnailNameHelper.Combine("exist", ThumbnailSize.TinyMeta)));

            Assert.IsFalse(fakeStorage.ExistFile(
                               ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.TinyMeta)));
            Assert.IsFalse(fakeStorage.ExistFile(
                               ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.ExtraLarge)));
            Assert.IsFalse(fakeStorage.ExistFile(
                               ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.Large)));
            Assert.IsFalse(fakeStorage.ExistFile(
                               ThumbnailNameHelper.Combine("12234456677", ThumbnailSize.ExtraLarge)));
        }
Beispiel #3
0
        public async Task ThumbnailCleanerTestAsync_CatchException()
        {
            var fakeStorage = new FakeIStorage(new List <string> {
                "/"
            },
                                               new List <string>
            {
                ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.Large),
            });

            var fakeQuery = new FakeIQueryException(new Microsoft.EntityFrameworkCore.Storage.RetryLimitExceededException());

            var thumbnailCleaner = new ThumbnailCleaner(fakeStorage, fakeQuery,
                                                        new FakeIWebLogger());

            await thumbnailCleaner.CleanAllUnusedFilesAsync();

            // the file is there even the connection is crashed
            Assert.IsTrue(fakeStorage.ExistFile(
                              ThumbnailNameHelper.Combine("hash1234", ThumbnailSize.Large)));
        }