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);
        }
        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);
        }
        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);
        }