Beispiel #1
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);
        }
Beispiel #2
0
        public async Task Update_Write_GPX()
        {
            var changedFileIndexItemName = new Dictionary <string, List <string> > {
                {
                    "/test.gpx", new List <string> {
                        "Tags"
                    }
                }
            };

            await _iStorageFake.WriteStreamAsync(new MemoryStream(CreateAnGpx.Bytes), "/test.gpx");

            var updateItem = new FileIndexItem("/test.gpx")
            {
                Tags   = "test",
                Status = FileIndexItem.ExifStatus.Ok
            };

            var query = new FakeIQuery();
            await query.AddItemAsync(updateItem);

            var fileIndexResultsList = new List <FileIndexItem> {
                updateItem
            };

            var readMeta = new FakeReadMetaSubPathStorage();
            var service  = new MetaUpdateService(query, _exifTool,
                                                 new FakeSelectorStorage(_iStorageFake), new FakeMetaPreflight(),
                                                 new FakeIWebLogger(), readMeta);

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

            Assert.IsTrue(_iStorageFake.ExistFile("/.starsky.test.gpx.json"));
        }
Beispiel #3
0
        public async Task UpdateService_Update_NoChangedFileIndexItemName_AndHasChanged()
        {
            var databaseItem = await _query.AddItemAsync(new FileIndexItem
            {
                Status          = FileIndexItem.ExifStatus.Ok,
                Tags            = "databaseItem",
                FileName        = "test.jpg",
                ParentDirectory = "/",
                IsDirectory     = false
            });

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

            var toUpdateItem = new FileIndexItem
            {
                Status          = FileIndexItem.ExifStatus.Ok,
                Tags            = "databaseItem",
                FileName        = "test.jpg",
                ParentDirectory = "/",
                IsDirectory     = false
            };

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

            await service.UpdateAsync(null, fileIndexResultsList,
                                      toUpdateItem, false, false, 0);

            // Second one is null

            // check for item (Referenced)
            Assert.AreEqual("databaseItem", toUpdateItem.Tags);
            // db
            Assert.AreEqual("databaseItem", _query.SingleItem("/test.jpg").FileIndexItem.Tags);

            _query.RemoveItem(databaseItem);
        }
Beispiel #4
0
        public async Task UpdateService_Update_toDelete()
        {
            var query = new FakeIQuery();
            await query.AddItemAsync(new FileIndexItem
            {
                Status          = FileIndexItem.ExifStatus.Ok,
                Tags            = "",
                FileName        = "test_delete.jpg",
                Description     = "noChanges",
                ParentDirectory = "/delete",
                Id = 9
            });

            var item0 = query.GetObjectByFilePath("/delete/test_delete.jpg");

            item0.Tags = "!delete!";

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

            var fileIndexResultsList = new List <FileIndexItem>
            {
                item0
            };

            var readMeta = new FakeReadMetaSubPathStorage();
            var service  = new MetaUpdateService(query, _exifTool,
                                                 new FakeSelectorStorage(_iStorageFake), new FakeMetaPreflight(),
                                                 new FakeIWebLogger(), readMeta);

            await service.UpdateAsync(changedFileIndexItemName, fileIndexResultsList, null, false, false, 0);

            // Deleted status is done in the Preflight stage
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, fileIndexResultsList[0].Status);

            // db
            Assert.AreEqual("!delete!", query.GetObjectByFilePath("/delete/test_delete.jpg").Tags);

            Assert.AreEqual("noChanges", query.GetObjectByFilePath("/delete/test_delete.jpg").Description);

            await query.RemoveItemAsync(item0);
        }
Beispiel #5
0
        public async Task UpdateRotate()
        {
            var changedFileIndexItemName = new Dictionary <string, List <string> > {
                {
                    "/test.jpg", new List <string> {
                        "orientation"
                    }
                }
            };
            await _iStorageFake.WriteStreamAsync(new MemoryStream(CreateAnImage.Bytes), "/test.jpg");

            var updateItem = new FileIndexItem("/test.jpg")
            {
                Orientation = FileIndexItem.Rotation.Horizontal,
                Status      = FileIndexItem.ExifStatus.Ok,
                FileHash    = "test"
            };

            var query = new FakeIQuery();
            await query.AddItemAsync(updateItem);

            var fileIndexResultsList = new List <FileIndexItem> {
                updateItem
            };

            var readMeta = new FakeReadMetaSubPathStorage();
            var service  = new MetaUpdateService(query, _exifTool,
                                                 new FakeSelectorStorage(_iStorageFake), new FakeMetaPreflight(),
                                                 new FakeIWebLogger(), readMeta);

            await service
            .UpdateAsync(changedFileIndexItemName, fileIndexResultsList, updateItem, false,
                         false, 1);

            // so there is something changed
            Assert.AreNotEqual("test", updateItem.FileHash);

            await _query.RemoveItemAsync(updateItem);
        }
Beispiel #6
0
        public async Task Update_Exception_MissingInList()
        {
            var changedFileIndexItemName = new Dictionary <string, List <string> >();
            var fileIndexResultList      = new List <FileIndexItem>
            {
                new FileIndexItem("/test.jpg")
                {
                    Status = FileIndexItem.ExifStatus.Ok
                }
            };

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

            await service.UpdateAsync(changedFileIndexItemName, fileIndexResultList,
                                      null, false, false, 0);

            // expect exception
        }