Example #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);
        }
Example #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"));
        }
Example #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);
        }
        public async Task Update_ChangedFileIndexItemNameContent()
        {
            var createAnImage = new CreateAnImage();

            InsertSearchData();
            var serviceScopeFactory = NewScopeFactory();

            var fakeIMetaUpdateService = _serviceProvider.GetService <IMetaUpdateService>() as
                                         FakeIMetaUpdateService;

            Assert.IsNotNull(fakeIMetaUpdateService);
            fakeIMetaUpdateService.ChangedFileIndexItemNameContent =
                new List <Dictionary <string, List <string> > >();

            var selectorStorage = new FakeSelectorStorage(new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger()));

            var metaPreflight = new MetaPreflight(_query,
                                                  _appSettings, selectorStorage, new FakeIWebLogger());
            var metaUpdateService = new MetaUpdateService(_query, _exifTool,
                                                          selectorStorage, new FakeMetaPreflight(),
                                                          new FakeIWebLogger(), new FakeReadMetaSubPathStorage());

            var controller = new MetaUpdateController(metaPreflight, metaUpdateService, new FakeIUpdateBackgroundTaskQueue(),
                                                      new FakeIWebLogger(), serviceScopeFactory)
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };
            var input = new FileIndexItem
            {
                Tags = "test"
            };
            var jsonResult = await controller.UpdateAsync(input,
                                                          createAnImage.DbPath, false, false) as JsonResult;

            if (jsonResult == null)
            {
                Console.WriteLine("json should not be null");
                throw new NullReferenceException(nameof(jsonResult));
            }

            Assert.IsNotNull(fakeIMetaUpdateService);
            Assert.AreEqual(1, fakeIMetaUpdateService.ChangedFileIndexItemNameContent.Count);

            var actual = JsonSerializer.Serialize(
                fakeIMetaUpdateService.ChangedFileIndexItemNameContent[0],
                DefaultJsonSerializer.CamelCase);

            var expected = "{\"" + createAnImage.DbPath + "\":[\"tags\"]}";

            Assert.AreEqual(expected, actual);
        }
Example #5
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);
        }
Example #6
0
        public async Task ApplyOrGenerateUpdatedFileHash_Should_Update_WhenNotNull()
        {
            var detailView = new DetailView
            {
                FileIndexItem = new FileIndexItem("/test.jpg")
            };

            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.ApplyOrGenerateUpdatedFileHash(new List <string>(), detailView.FileIndexItem);

            Assert.IsNotNull(detailView.FileIndexItem.FileHash);
        }
Example #7
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);
        }
        public async Task Update_AllDataIncluded_WithFakeExifTool()
        {
            var createAnImage = new CreateAnImage();

            InsertSearchData();

            var selectorStorage = new FakeSelectorStorage(new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger()));

            var metaPreflight = new MetaPreflight(_query, _appSettings,
                                                  selectorStorage, new FakeIWebLogger());
            var metaUpdateService = new MetaUpdateService(_query, _exifTool,
                                                          selectorStorage, new FakeMetaPreflight(),
                                                          new FakeIWebLogger(), new FakeReadMetaSubPathStorage());

            var controller = new MetaUpdateController(metaPreflight, metaUpdateService, _bgTaskQueue,
                                                      new FakeIWebLogger(), NewScopeFactory());

            var input = new FileIndexItem
            {
                Tags = "test"
            };
            var jsonResult = await controller.UpdateAsync(input, createAnImage.DbPath, false,
                                                          false) as JsonResult;

            if (jsonResult == null)
            {
                Console.WriteLine("json should not be null");
                throw new NullReferenceException(nameof(jsonResult));
            }
            var fileModel = jsonResult.Value as List <FileIndexItem>;

            //you could not test because exiftool is an external dependency

            if (fileModel == null)
            {
                throw new NullReferenceException(nameof(fileModel));
            }
            Assert.AreNotEqual(null, fileModel.FirstOrDefault()?.Tags);
        }
Example #9
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
        }
Example #10
0
        public async Task Update_SourceImageMissingOnDisk_WithFakeExifTool()
        {
            await _query.AddItemAsync(new FileIndexItem
            {
                FileName        = "ApiController_Update_SourceImageMissingOnDisk_WithFakeExifTool.jpg",
                ParentDirectory = "/",
                FileHash        = "ApiController_Update_SourceImageMissingOnDisk_WithFakeExifTool"
            });

            var selectorStorage = new FakeSelectorStorage(new StorageSubPathFilesystem(_appSettings, new FakeIWebLogger()));

            var metaPreflight = new MetaPreflight(_query,
                                                  _appSettings, selectorStorage, new FakeIWebLogger());
            var metaUpdateService = new MetaUpdateService(_query, _exifTool,
                                                          selectorStorage, new FakeMetaPreflight(),
                                                          new FakeIWebLogger(), new FakeReadMetaSubPathStorage());

            var controller = new MetaUpdateController(metaPreflight, metaUpdateService, _bgTaskQueue,
                                                      new FakeIWebLogger(), NewScopeFactory())
            {
                ControllerContext = { HttpContext = new DefaultHttpContext() }
            };

            // Not Found --> 404
            var testElement    = new FileIndexItem();
            var notFoundResult = await controller.UpdateAsync(testElement, "/ApiController_Update_SourceImageMissingOnDisk_WithFakeExifTool.jpg",
                                                              false, false) as NotFoundObjectResult;

            if (notFoundResult == null)
            {
                throw new NullReferenceException(nameof(notFoundResult));
            }

            Assert.AreEqual(404, notFoundResult.StatusCode);

            await _query.RemoveItemAsync(_query.SingleItem("/ApiController_Update_SourceImageMissingOnDisk_WithFakeExifTool.jpg").FileIndexItem);
        }