Example #1
0
        public async Task GeoBackgroundTask_WithResults_NoGps()
        {
            _appSettings.Verbose = true;
            var storage = new FakeIStorage(new List <string> {
                "/"
            },
                                           new List <string> {
            },
                                           new List <byte[]> {
            }
                                           );
            var storageSelector = new FakeSelectorStorage(storage);

            var geoReverseLookup = new FakeIGeoReverseLookup(new List <FileIndexItem>
            {
                new FileIndexItem("/test.jpg")
                {
                    FileHash = "2QOYZWMPACZAJ2MABGMOZ6CCPY"
                }
            });

            var controller = new GeoBackgroundTask(_appSettings, storageSelector,
                                                   _geoLocationWrite, _memoryCache, new FakeIWebLogger(),
                                                   geoReverseLookup);

            var results = await controller.GeoBackgroundTaskAsync();

            Assert.AreEqual(1, results.Count);
        }
Example #2
0
        public async Task GeoCliInput_AbsolutePath_HappyFlow()
        {
            var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary <string, HttpContent>
            {
            });
            var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, new FakeIWebLogger());

            var storage = new FakeIStorage(new List <string> {
                "/"
            },
                                           new List <string> {
                "/test.jpg"
            },
                                           new List <byte[]> {
                CreateAnImage.Bytes
            });

            var appSettings = new AppSettings {
                Verbose = true
            };
            var geoWrite  = new FakeIGeoLocationWrite();
            var geoLookup = new FakeIGeoReverseLookup();
            var console   = new FakeConsoleWrapper();
            var geoCli    = new GeoCli(geoLookup, geoWrite,
                                       new FakeSelectorStorage(storage), appSettings,
                                       console, new FakeIGeoFileDownload(), new FakeExifToolDownload());
            await geoCli.CommandLineAsync(new List <string> {
                "-p", "/test"
            }.ToArray());

            Assert.AreEqual(appSettings.StorageFolder, "/test" + Path.DirectorySeparatorChar);
            Assert.AreEqual(1, geoLookup.Count);
            Assert.IsTrue(storage.ExistFile("/test.jpg"));
        }
Example #3
0
        public async Task GeoCliInput_Default_HappyFlow()
        {
            var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary <string, HttpContent>
            {
            });
            var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, new FakeIWebLogger());

            var storage = new FakeIStorage(new List <string> {
                "/"
            },
                                           new List <string> {
                "/test.jpg"
            },
                                           new List <byte[]> {
                CreateAnImage.Bytes
            });
            var hash = (await new FileHash(storage).GetHashCodeAsync("/test.jpg")).Key;

            storage.FileCopy("/test.jpg", $"/{hash}.jpg");

            var geoWrite  = new FakeIGeoLocationWrite();
            var geoLookup = new FakeIGeoReverseLookup();
            var console   = new FakeConsoleWrapper();
            var geoCli    = new GeoCli(geoLookup, geoWrite,
                                       new FakeSelectorStorage(storage), new AppSettings(),
                                       console, new FakeIGeoFileDownload(), new FakeExifToolDownload());
            await geoCli.CommandLineAsync(new List <string> {
                "-p",
            }.ToArray());

            Assert.AreEqual(1, geoLookup.Count);
            Assert.IsTrue(storage.ExistFile($"/{hash}.jpg"));
            Assert.IsTrue(storage.ExistFile("/test.jpg"));
        }
Example #4
0
        public void GeoBackgroundTask_IsNotCalled()
        {
            var storage          = new FakeIStorage();    // <= main folder not found
            var storageSelector  = new FakeSelectorStorage(storage);
            var geoReverseLookup = new FakeIGeoReverseLookup();

            var controller = new GeoBackgroundTask(_appSettings, storageSelector,
                                                   _geoLocationWrite, _memoryCache,
                                                   new FakeIWebLogger(),
                                                   geoReverseLookup);

            controller.GeoBackgroundTaskAsync();

            Assert.AreEqual(0, geoReverseLookup.Count);
        }
Example #5
0
        public async Task GeoCliInput_RelativeUrl_HappyFlow()
        {
            var fakeIHttpProvider = new FakeIHttpProvider(new Dictionary <string, HttpContent>
            {
            });
            var httpClientHelper = new HttpClientHelper(fakeIHttpProvider, _serviceScopeFactory, new FakeIWebLogger());

            var relativeParentFolder = new AppSettings().DatabasePathToFilePath(
                new StructureService(new FakeIStorage(), new AppSettings().Structure)
                .ParseSubfolders(0), false);

            var storage = new FakeIStorage(new List <string> {
                "/"
            },
                                           new List <string> {
                "/test.jpg"
            },
                                           new List <byte[]> {
                CreateAnImage.Bytes
            });

            var appSettings = new AppSettings();
            var geoWrite    = new FakeIGeoLocationWrite();
            var geoLookup   = new FakeIGeoReverseLookup();
            var console     = new FakeConsoleWrapper();
            var geoCli      = new GeoCli(geoLookup, geoWrite,
                                         new FakeSelectorStorage(storage), appSettings,
                                         console, new FakeIGeoFileDownload(), new FakeExifToolDownload());
            await geoCli.CommandLineAsync(new List <string> {
                "-g", "0"
            }.ToArray());

            Assert.AreEqual(appSettings.StorageFolder, relativeParentFolder + Path.DirectorySeparatorChar);
            Assert.AreEqual(1, geoLookup.Count);
            Assert.IsTrue(storage.ExistFile("/test.jpg"));
        }