Пример #1
0
        private void InsertSearchData()
        {
            if (!string.IsNullOrEmpty(
                    _query.GetSubPathByHash("09876543456789")))
            {
                return;
            }

            _insertSearchDatahiJpgInput = _query.AddItem(new FileIndexItem
            {
                FileName        = "hi.jpg",
                ParentDirectory = "/basic",
                FileHash        = "09876543456789",
                ColorClass      = ColorClassParser.Color.Winner,            // 1
                Tags            = "",
                Title           = "",
                IsDirectory     = false
            });

            _insertSearchDatahi2JpgInput = _query.AddItem(new FileIndexItem
            {
                FileName        = "hi2.jpg",
                Tags            = "!delete!",
                ParentDirectory = "/basic",
                IsDirectory     = false
            });

            _insertSearchDatahi2SubfolderJpgInput = _query.AddItem(new FileIndexItem
            {
                FileName        = "hi2.jpg",
                ParentDirectory = "/basic/subfolder",
                FileHash        = "234567876543",
                IsDirectory     = false
            });
        }
Пример #2
0
        private FileIndexItem InsertSearchData()
        {
            _iStorage = new FakeIStorage(new List <string> {
                "/"
            },
                                         new List <string> {
                _createAnImage.DbPath
            });
            var fileHashCode = new FileHash(_iStorage).GetHashCode(_createAnImage.DbPath).Key;

            if (string.IsNullOrEmpty(_query.GetSubPathByHash(fileHashCode)))
            {
                _query.AddItem(new FileIndexItem
                {
                    FileName        = "/",
                    ParentDirectory = "/",
                    IsDirectory     = true
                });

                _query.AddItem(new FileIndexItem
                {
                    FileName        = _createAnImage.FileName,
                    ParentDirectory = "/",
                    FileHash        = fileHashCode,
                    ColorClass      = ColorClassParser.Color.Winner,                // 1
                });
            }

            return(_query.GetObjectByFilePath(_createAnImage.DbPath));
        }
Пример #3
0
        public void CacheIndexController_CheckIfCacheIsRemoved_CleanCache()
        {
            // Act
            var controller = new CacheIndexController(_query, _appSettings);

            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            _query.AddItem(new FileIndexItem
            {
                FileName        = "cacheDeleteTest",
                ParentDirectory = "/",
                IsDirectory     = true
            });

            _query.AddItem(new FileIndexItem
            {
                FileName        = "file.jpg",
                ParentDirectory = "/cacheDeleteTest",
                IsDirectory     = false
            });

            Assert.AreEqual(true, _query.DisplayFileFolders("/cacheDeleteTest").Any());

            // Ask the cache
            _query.DisplayFileFolders("/cacheDeleteTest");

            // Don't notify the cache that there is an update
            var newItem = new FileIndexItem
            {
                FileName        = "file2.jpg",
                ParentDirectory = "/cacheDeleteTest",
                IsDirectory     = false
            };

            _context.FileIndex.Add(newItem);
            _context.SaveChanges();
            // Write changes to database

            // Check if there is one item in the cache
            var beforeQuery = _query.DisplayFileFolders("/cacheDeleteTest");

            Assert.AreEqual(1, beforeQuery.Count());

            // Act, remove content from cache
            var actionResult = controller.RemoveCache("/cacheDeleteTest") as JsonResult;

            Assert.AreEqual("cache successful cleared", actionResult.Value);

            // Check if there are now two items in the cache
            var newQuery = _query.DisplayFileFolders("/cacheDeleteTest");

            Assert.AreEqual(2, newQuery.Count());
        }
Пример #4
0
        public void ExportControllerTest__ThumbTrue__FilePathToFileName()
        {
            var storage         = new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger());
            var selectorStorage = new FakeSelectorStorage(storage);
            var export          = new ExportService(_query, _appSettings, selectorStorage, new FakeIWebLogger());
            var filePaths       = new List <string>
            {
                Path.Combine("test", "thumb.jpg")
            };

            _query.AddItem(new FileIndexItem
            {
                FileName        = "file.jpg",
                ParentDirectory = "/test",
                FileHash        = "thumb"
            });

            var fileNames = export.FilePathToFileName(filePaths, true);

            Assert.AreEqual("file.jpg", fileNames.FirstOrDefault());

            // This is a strange one:
            // We use thumb as base32 fileHashes but export
            // as file.jpg or the nice original name
        }
Пример #5
0
        public void UpdateService_Update_defaultTest()
        {
            var item0 = _query.AddItem(new FileIndexItem
            {
                Status          = FileIndexItem.ExifStatus.Ok,
                Tags            = "thisKeywordHasChanged",
                FileName        = "test_default.jpg",
                Description     = "noChanges",
                ParentDirectory = "/"
            });

            var changedFileIndexItemName = new Dictionary <string, List <string> >
            {
                {
                    "/test_default.jpg", new List <string>
                    {
                        nameof(FileIndexItem.Tags)
                    }
                },
            };

            var fileIndexResultsList = new List <FileIndexItem>
            {
                new FileIndexItem
                {
                    Status          = FileIndexItem.ExifStatus.Ok,
                    Tags            = "initial tags (from database)",
                    FileName        = "test_default.jpg",
                    ParentDirectory = "/",
                    Description     = "keep",
                }
            };

            var updateItem = new FileIndexItem
            {
                Status          = FileIndexItem.ExifStatus.Ok,
                Tags            = "only used when Caching is disabled",
                FileName        = "test_default.jpg",
                Description     = "noChanges",
                ParentDirectory = "/"
            };

            var readMeta = new ReadMetaSubPathStorage(
                new FakeSelectorStorage(_iStorageFake), _appSettings,
                _memoryCache);
            var service = new MetaUpdateService(_query, _exifTool,
                                                new FakeSelectorStorage(_iStorageFake), new FakeMetaPreflight(),
                                                new FakeIWebLogger(), readMeta);

            service.UpdateAsync(changedFileIndexItemName, fileIndexResultsList, updateItem, false, false, 0);

            // check for item (Referenced)
            Assert.AreEqual("thisKeywordHasChanged", item0.Tags);
            // db
            Assert.AreEqual("thisKeywordHasChanged", _query.SingleItem("/test_default.jpg").FileIndexItem.Tags);

            Assert.AreEqual("noChanges", _query.SingleItem("/test_default.jpg").FileIndexItem.Description);

            _query.RemoveItem(item0);
        }
Пример #6
0
        private FileIndexItem InsertSearchData()
        {
            var fileHash = "home0012304590";
            var item     = new FileIndexItem
            {
                FileName        = "test.jpg",
                ParentDirectory = "/",
                FileHash        = fileHash,
                ColorClass      = ColorClassParser.Color.Winner            // 1
            };

            if (string.IsNullOrEmpty(_query.GetSubPathByHash(fileHash)))
            {
                _query.AddItem(item);
            }
            return(item);
        }
Пример #7
0
        private void InsertSearchData()
        {
            if (string.IsNullOrEmpty(_query.GetSubPathByHash("home0012304590")))
            {
                _query.AddItem(new FileIndexItem
                {
                    FileName        = "hi.jpg",
                    ParentDirectory = "/homecontrollertest",
                    FileHash        = "home0012304590",
                    ColorClass      = ColorClassParser.Color.Winner                // 1
                });

                // There must be a parent folder
                _query.AddItem(new FileIndexItem
                {
                    FileName        = "homecontrollertest",
                    ParentDirectory = "",
                    IsDirectory     = true
                });
            }
        }
Пример #8
0
        private FileIndexItem InsertSearchData(bool delete = false)
        {
            var fileHashCode = new FileHash(_iStorage).GetHashCode(_createAnImage.DbPath).Key;

            if (string.IsNullOrEmpty(_query.GetSubPathByHash(fileHashCode)))
            {
                var isDelete = string.Empty;
                if (delete)
                {
                    isDelete = "!delete!";
                }
                _query.AddItem(new FileIndexItem
                {
                    FileName        = _createAnImage.FileName,
                    ParentDirectory = "/",
                    FileHash        = fileHashCode,
                    ColorClass      = ColorClassParser.Color.Winner,                // 1
                    Tags            = isDelete
                });
            }
            return(_query.GetObjectByFilePath(_createAnImage.DbPath));
        }
Пример #9
0
        public void SearchControllerTest_Index_OneKeyword()
        {
            var item0 = _query.AddItem(new FileIndexItem
            {
                FileName        = "Test.jpg",
                ParentDirectory = "/",
                Tags            = "test"
            });
            var controller       = new SearchController(_search);
            var jsonResult       = controller.Index("test", 0) as JsonResult;
            var searchViewResult = jsonResult.Value as SearchViewModel;

            // some values
            Assert.AreEqual(1, searchViewResult.SearchCount);
            Assert.AreEqual(1, searchViewResult.FileIndexItems.Count);
            Assert.AreEqual(SearchViewModel.SearchForOptionType.Equal, searchViewResult.SearchForOptions[0]);
            Assert.AreEqual("test", searchViewResult.SearchQuery);
            Assert.AreEqual(nameof(FileIndexItem.Tags), searchViewResult.SearchIn[0]);

            _query.RemoveItem(item0);
        }