public void Add_RemoveImageAddNewImage_Ok() { using var fs = new TestFS(DbTest1ArchiveUrl, nameof(DdbFactoryTest)); _settings.StoragePath = fs.TestFolder; _appSettingsMock.Setup(o => o.Value).Returns(_settings); var factory = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger); var ddb = factory.Get(MagicStrings.PublicOrganizationSlug, _datasetGuid); const string fileName = "DJI_0028.JPG"; ddb.Remove(fileName); var path = Path.Combine(TestDataFolder, fileName); if (!File.Exists(path)) { CommonUtils.SmartDownloadFile("https://github.com/DroneDB/test_data/raw/master/test-datasets/drone_dataset_brighton_beach/" + fileName, path); } ddb.Add(fileName, File.ReadAllBytes(path)); ddb.Search(fileName).Should().HaveCount(1); }
public void Tag_HappyPath_Ok() { const string goodTag = "pippo/pluto"; const string goodTagWithRegistry = "https://test.com/pippo/pluto"; using var test = new TestFS(Test3ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, DdbFolder); var tag = DDBWrapper.GetTag(ddbPath); tag.Should().BeNull(); DDBWrapper.SetTag(ddbPath, goodTag); tag = DDBWrapper.GetTag(ddbPath); tag.Should().Be(goodTag); DDBWrapper.SetTag(ddbPath, goodTagWithRegistry); tag = DDBWrapper.GetTag(ddbPath); tag.Should().Be(goodTagWithRegistry); }
public void Tag_ErrorCases_Ok() { const string badTag = "pippo"; const string badTag2 = "����+���+�AAadff_-.-.,"; using var test = new TestFS(Test3ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, DdbFolder); Action act = () => DDBWrapper.SetTag(ddbPath, badTag); act.Should().Throw <DDBException>(); act = () => DDBWrapper.SetTag(ddbPath, badTag2); act.Should().Throw <DDBException>(); act = () => DDBWrapper.SetTag(ddbPath, string.Empty); act.Should().Throw <DDBException>(); act = () => DDBWrapper.SetTag(ddbPath, null); act.Should().Throw <ArgumentException>(); }
public void Delta_HappyPath_Ok() { using var source = new TestFS(TestDelta2ArchiveUrl, BaseTestFolder); using var destination = new TestFS(TestDelta1ArchiveUrl, BaseTestFolder); var delta = DDBWrapper.Delta(source.TestFolder, destination.TestFolder); delta.Adds.Length.Should().BeGreaterThan(0); delta.Removes.Length.Should().BeGreaterThan(0); }
public void Chaddr_NullAttr_Exception() { using var test = new TestFS(Test3ArchiveUrl, BaseTestFolder); var ddbPath = test.TestFolder; Action act = () => DDBWrapper.ChangeAttributes(ddbPath, null); act.Should().Throw <ArgumentException>(); }
public void MoveEntry_SimpleRename_Ok() { using var test = new TestFS(TestDelta2ArchiveUrl, BaseTestFolder); DDBWrapper.MoveEntry(test.TestFolder, "plutone.txt", "test.txt"); var res = DDBWrapper.List(test.TestFolder, test.TestFolder, true); res.Should().HaveCount(11); res[8].Path.Should().Be("test.txt"); }
public void Stamp_HappyPath_Ok() { using var test = new TestFS(Test3ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, DdbFolder); var stamp = DDBWrapper.GetStamp(ddbPath); stamp.Checksum.Should().NotBeNull(); stamp.Entries.Count.Should().BeGreaterThan(0); }
public void Remove_NonexistantFile_Exception() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); const string fileName = "elaiuyhrfboeawuyirgfb"; var ddbPath = Path.Combine(test.TestFolder, "public", "default"); Action act = () => DDBWrapper.Remove(ddbPath, Path.Combine(ddbPath, fileName)); act.Should().Throw <DDBException>(); }
public async Task AddListRemove_HappyPath_Ok() { await using var context = GetTest1Context(); using var test = new TestFS(Test4ArchiveUrl, BaseTestFolder); var settings = JsonConvert.DeserializeObject <AppSettings>(_settingsJson); settings.DatasetsPath = Path.Combine(test.TestFolder, DdbFolder); _appSettingsMock.Setup(o => o.Value).Returns(settings); _authManagerMock.Setup(o => o.IsUserAdmin()).Returns(Task.FromResult(true)); _authManagerMock.Setup(o => o.IsOwnerOrAdmin(It.IsAny <Dataset>())).Returns(Task.FromResult(true)); var ddbManager = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger); var webUtils = new WebUtils(_authManagerMock.Object, context, _appSettingsMock.Object, _httpContextAccessorMock.Object, ddbManager); var metaManager = new MetaManager(_metaManagerLogger, ddbManager, _authManagerMock.Object, webUtils); var a = await metaManager.Add(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations", "{\"test\":123}"); a.Data["test"].ToObject <int>().Should().Be(123); var res = await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug); res.Should().HaveCount(1); res.First().Count.Should().Be(1); res.First().Key.Should().Be("annotations"); var a2 = await metaManager.Add(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations", "{\"test\":4124,\"pippo\":\"ciao\"}"); a2.Data["test"].ToObject <int>().Should().Be(4124); a2.Data["pippo"].ToObject <string>().Should().Be("ciao"); (await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug)).Should().HaveCount(1); (await metaManager.Get(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations")) .Should().HaveCount(2); (await metaManager.Remove(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, a.Id)).Should().Be(1); (await metaManager.Get(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations")) .Should().HaveCount(1); (await metaManager.Unset(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug, "annotations")).Should().Be(1); (await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug)).Should() .BeEmpty(); }
public void Remove_AllFiles_Ok() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); const string fileName = "."; var ddbPath = Path.Combine(test.TestFolder, "public", "default"); DDBWrapper.Remove(ddbPath, Path.Combine(ddbPath, fileName)); var res = DDBWrapper.List(ddbPath, ".", true); res.Should().HaveCount(0); }
public void List_AllFiles_Ok() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, "public", "default"); var res = DDBWrapper.List(ddbPath, Path.Combine(ddbPath, "."), true); res.Should().HaveCount(26); res = DDBWrapper.List(ddbPath, ddbPath, true); res.Should().HaveCount(26); }
public void Search_MissingEntry_Empty() { using var fs = new TestFS(DbTest1ArchiveUrl, nameof(DdbFactoryTest)); _settings.StoragePath = fs.TestFolder; _appSettingsMock.Setup(o => o.Value).Returns(_settings); var factory = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger); var ddb = factory.Get(MagicStrings.PublicOrganizationSlug, _datasetGuid); var res = ddb.Search("asasdadas.jpg"); res.Should().BeEmpty(); }
public void Password_HappyPath_Ok() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, "public", "default"); DDBWrapper.VerifyPassword(ddbPath, string.Empty).Should().BeTrue(); DDBWrapper.AppendPassword(ddbPath, "testpassword"); DDBWrapper.VerifyPassword(ddbPath, "testpassword").Should().BeTrue(); DDBWrapper.VerifyPassword(ddbPath, "wrongpassword").Should().BeFalse(); DDBWrapper.ClearPasswords(ddbPath); DDBWrapper.VerifyPassword(ddbPath, "testpassword").Should().BeFalse(); }
public void List_ExistingFile_Ok() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, "public", "default"); var res = DDBWrapper.List(ddbPath, Path.Combine(ddbPath, "DJI_0027.JPG")); res.Should().HaveCount(1); var entry = res.First(); Entry expectedEntry = JsonConvert.DeserializeObject <Entry>( "{\"depth\":0,\"hash\":\"3157958dd4f2562c8681867dfd6ee5bf70b6e9595b3e3b4b76bbda28342569ed\",\"properties\":{\"cameraPitch\":-89.9000015258789,\"cameraRoll\":0.0,\"cameraYaw\":-131.3000030517578,\"captureTime\":1466699584000.0,\"focalLength\":3.4222222222222225,\"focalLength35\":20.0,\"height\":2250,\"make\":\"DJI\",\"model\":\"FC300S\",\"orientation\":1,\"sensor\":\"dji fc300s\",\"sensorHeight\":3.4650000000000003,\"sensorWidth\":6.16,\"width\":4000},\"mtime\":1491156087,\"path\":\"DJI_0027.JPG\",\"point_geom\":{\"crs\":{\"properties\":{\"name\":\"EPSG:4326\"},\"type\":\"name\"},\"geometry\":{\"coordinates\":[-91.99408299999999,46.84260499999999,198.5099999999999],\"type\":\"Point\"},\"properties\":{},\"type\":\"Feature\"},\"polygon_geom\":{\"crs\":{\"properties\":{\"name\":\"EPSG:4326\"},\"type\":\"name\"},\"geometry\":{\"coordinates\":[[[-91.99397836402999,46.8422402913,158.5099999999999],[-91.99357489543,46.84247729175999,158.5099999999999],[-91.99418894036,46.84296945989999,158.5099999999999],[-91.99459241001999,46.8427324573,158.5099999999999],[-91.99397836402999,46.8422402913,158.5099999999999]]],\"type\":\"Polygon\"},\"properties\":{},\"type\":\"Feature\"},\"size\":3185449,\"type\":3}"); entry.Should().BeEquivalentTo(expectedEntry); }
public void IsBuildable_PointCloud_True() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, "public", "default"); using var tempFile = new TempFile(TestPointCloudUrl, BaseTestFolder); var destPath = Path.Combine(ddbPath, Path.GetFileName(tempFile.FilePath)); File.Move(tempFile.FilePath, destPath); var res = DDBWrapper.Add(ddbPath, destPath); res.Count.Should().Be(1); DDBWrapper.IsBuildable(ddbPath, Path.GetFileName(destPath)).Should().BeTrue(); }
public void Chaddr_HappyPath_Ok() { using var test = new TestFS(Test3ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder); var res = DDBWrapper.ChangeAttributes(ddbPath, new Dictionary <string, object> { { "public", true } }); res["public"].Should().Be(true); res = DDBWrapper.ChangeAttributes(ddbPath, new Dictionary <string, object> { { "public", false } }); res["public"].Should().Be(false); }
public void Add_ImageFile_Ok() { using var test = new TestFS(Test1ArchiveUrl, BaseTestFolder); var ddbPath = Path.Combine(test.TestFolder, "public", "default"); using var tempFile = new TempFile(TestFileUrl, BaseTestFolder); DDBWrapper.Remove(ddbPath, Path.Combine(ddbPath, "DJI_0023.JPG")); var destPath = Path.Combine(ddbPath, Path.GetFileName(tempFile.FilePath)); File.Move(tempFile.FilePath, destPath); var res = DDBWrapper.Add(ddbPath, destPath); res.Count.Should().Be(1); }
public void Search_ExistingEntry_Entry1() { using var fs = new TestFS(DbTest1ArchiveUrl, nameof(DdbFactoryTest)); _settings.StoragePath = fs.TestFolder; _appSettingsMock.Setup(o => o.Value).Returns(_settings); const string fileName = "Sub/20200610_144436.jpg"; const int expectedDepth = 1; const int expectedSize = 8248241; const EntryType expectedType = EntryType.GeoImage; const string expectedHash = "f27ddc96daf9aeff3c026de8292681296c3e9d952b647235878c50f2b7b39e94"; var expectedModifiedTime = new DateTime(2020, 06, 10, 14, 44, 36); var expectedMeta = JsonConvert.DeserializeObject <Dictionary <string, object> >( "{\"captureTime\":1591800276004.8,\"focalLength\":4.16,\"focalLength35\":26.0,\"height\":3024,\"make\":\"samsung\",\"model\":\"SM-G950F\",\"orientation\":1,\"sensor\":\"samsung sm-g950f\",\"sensorHeight\":4.32,\"sensorWidth\":5.76,\"width\":4032}"); const double expectedLatitude = 45.50027; const double expectedLongitude = 10.60667; const double expectedAltitude = 141; var factory = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger); var ddb = factory.Get(MagicStrings.PublicOrganizationSlug, _datasetGuid); var list = ddb.Search(fileName).ToArray(); list.Should().HaveCount(1); var res = list.First(); res.Path.Should().Be(fileName); // TODO: Handle different timezones res.ModifiedTime.Should().BeCloseTo(expectedModifiedTime, new TimeSpan(6, 0, 0)); res.Hash.Should().Be(expectedHash); res.Depth.Should().Be(expectedDepth); res.Size.Should().Be(expectedSize); res.Type.Should().Be(expectedType); res.Properties.Should().BeEquivalentTo(expectedMeta); res.PointGeometry["geometry"]["coordinates"][0].Value <double>().Should().BeApproximately(expectedLongitude, 0.00001); res.PointGeometry["geometry"]["coordinates"][1].Value <double>().Should().BeApproximately(expectedLatitude, 0.00001); res.PointGeometry["geometry"]["coordinates"][2].Value <double>().Should().BeApproximately(expectedAltitude, 0.1); }
public void List_ExistingFileSubFolder_Ok() { using var fs = new TestFS(Test1ArchiveUrl, nameof(DDBWrapperTests)); const string fileName = "Sub/20200610_144436.jpg"; const int expectedDepth = 1; const int expectedSize = 8248241; var expectedType = EntryType.GeoImage; const string expectedHash = "f27ddc96daf9aeff3c026de8292681296c3e9d952b647235878c50f2b7b39e94"; var expectedModifiedTime = new DateTime(2020, 06, 10, 14, 44, 36); var expectedMeta = JsonConvert.DeserializeObject <Dictionary <string, object> >( "{\"captureTime\":1591800276004.8,\"focalLength\":4.16,\"focalLength35\":26.0,\"height\":3024,\"make\":\"samsung\",\"model\":\"SM-G950F\",\"orientation\":1,\"sensor\":\"samsung sm-g950f\",\"sensorHeight\":4.32,\"sensorWidth\":5.76,\"width\":4032}"); //const double expectedLatitude = 45.50027; //const double expectedLongitude = 10.60667; //const double expectedAltitude = 141; var ddbPath = Path.Combine(fs.TestFolder, "public", "default"); var res = DDBWrapper.List(ddbPath, Path.Combine(ddbPath, fileName)); res.Should().HaveCount(1); var file = res.First(); file.Path.Should().Be(fileName); // TODO: Handle different timezones file.ModifiedTime.Should().BeCloseTo(expectedModifiedTime, new TimeSpan(6, 0, 0)); file.Hash.Should().Be(expectedHash); file.Depth.Should().Be(expectedDepth); file.Size.Should().Be(expectedSize); file.Type.Should().Be(expectedType); file.Properties.Should().BeEquivalentTo(expectedMeta); file.PointGeometry.Should().NotBeNull(); //file.PointGeometry.Coordinates.Latitude.Should().BeApproximately(expectedLatitude, 0.00001); //file.PointGeometry.Coordinates.Longitude.Should().BeApproximately(expectedLongitude, 0.00001); //file.PointGeometry.Coordinates.Altitude.Should().Be(expectedAltitude); }
public async Task List_Empty_NoMeta() { await using var context = GetTest1Context(); using var test = new TestFS(Test4ArchiveUrl, BaseTestFolder); var settings = JsonConvert.DeserializeObject <AppSettings>(_settingsJson); settings.DatasetsPath = Path.Combine(test.TestFolder, DdbFolder); _appSettingsMock.Setup(o => o.Value).Returns(settings); _authManagerMock.Setup(o => o.IsUserAdmin()).Returns(Task.FromResult(true)); var ddbManager = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger); var webUtils = new WebUtils(_authManagerMock.Object, context, _appSettingsMock.Object, _httpContextAccessorMock.Object, ddbManager); var metaManager = new MetaManager(_metaManagerLogger, ddbManager, _authManagerMock.Object, webUtils); var res = await metaManager.List(MagicStrings.PublicOrganizationSlug, MagicStrings.DefaultDatasetSlug); res.Should().BeEmpty(); }
public async Task Initialize_WithOrgWithoutDataset_GeneratedTag() { // INITIALIZATION & SETUP const string userName = "******"; using var test = new TestFS(Test4ArchiveUrl, BaseTestFolder, true); await using var context = GetTest1Context(); await using var appContext = GetAppTest1Context(); var settings = JsonConvert.DeserializeObject <AppSettings>(_settingsJson); settings.DatasetsPath = test.TestFolder; _appSettingsMock.Setup(o => o.Value).Returns(settings); _authManagerMock.Setup(o => o.IsUserAdmin()).Returns(Task.FromResult(true)); _authManagerMock.Setup(o => o.IsOwnerOrAdmin(It.IsAny <Organization>())).Returns(Task.FromResult(true)); var user = new User { UserName = userName, Email = "*****@*****.**", Id = Guid.NewGuid().ToString() }; _authManagerMock.Setup(o => o.GetCurrentUser()).Returns(Task.FromResult(user)); _authManagerMock.Setup(o => o.UserExists(user.Id)).Returns(Task.FromResult(true)); _authManagerMock.Setup(o => o.SafeGetCurrentUserName()).Returns(Task.FromResult(userName)); var attributes = new Dictionary <string, object> { { "public", true } }; var ddbMock = new Mock <IDDB>(); ddbMock.Setup(x => x.GetInfoAsync(default)).Returns(Task.FromResult(new Entry
public void IsBuildable_TextFile_False() { using var test = new TestFS(TestDelta2ArchiveUrl, BaseTestFolder); DDBWrapper.IsBuildable(test.TestFolder, "lol.txt").Should().BeFalse(); }
public void Search_ExistingEntry_Entry2() { using var fs = new TestFS(DbTest1ArchiveUrl, nameof(DdbFactoryTest)); _settings.StoragePath = fs.TestFolder; _appSettingsMock.Setup(o => o.Value).Returns(_settings); const string fileName = "DJI_0022.JPG"; const int expectedDepth = 0; const int expectedSize = 3872682; const EntryType expectedType = EntryType.GeoImage; const string expectedHash = "e6e57187a33951a27f51e3a86cc66c6ce43d555f0d51ba3c715fc7b707ce1477"; var expectedModifiedTime = new DateTime(2017, 04, 2, 20, 01, 27); var expectedMeta = JsonConvert.DeserializeObject <Dictionary <string, object> >( "{\"cameraPitch\":-90.0,\"cameraRoll\":0.0,\"cameraYaw\":45.29999923706055,\"captureTime\":1466699547000.0,\"focalLength\":3.4222222222222225,\"focalLength35\":20.0,\"height\":2250,\"make\":\"DJI\",\"model\":\"FC300S\",\"orientation\":1,\"sensor\":\"dji fc300s\",\"sensorHeight\":3.4650000000000003,\"sensorWidth\":6.16,\"width\":4000}"); const double expectedLatitude = 46.842952; const double expectedLongitude = -91.994052; const double expectedAltitude = 198.51; List <List <double> > expectedCoordinates = new List <List <double> >(); expectedCoordinates.Add(new List <double> { -91.99418833907131, 46.843311240786406, 158.51 }); expectedCoordinates.Add(new List <double> { -91.99457061482893, 46.843058237783886, 158.51 }); expectedCoordinates.Add(new List <double> { -91.99391510716002, 46.842591925708966, 158.51 }); expectedCoordinates.Add(new List <double> { -91.99353283170487, 46.842844926544224, 158.51 }); expectedCoordinates.Add(new List <double> { -91.99418833907131, 46.843311240786406, 158.51 }); var factory = new DdbManager(_appSettingsMock.Object, _ddbFactoryLogger); var ddb = factory.Get(MagicStrings.PublicOrganizationSlug, _datasetGuid); var list = ddb.Search(fileName).ToArray(); list.Should().HaveCount(1); var res = list.First(); res.Path.Should().Be(fileName); // TODO: Handle different timezones res.ModifiedTime.Should().BeCloseTo(expectedModifiedTime, new TimeSpan(6, 0, 0)); res.Hash.Should().Be(expectedHash); res.Depth.Should().Be(expectedDepth); res.Size.Should().Be(expectedSize); res.Type.Should().Be(expectedType); res.Properties.Should().BeEquivalentTo(expectedMeta); res.PointGeometry["geometry"]["coordinates"][0].Value <double>().Should().BeApproximately(expectedLongitude, 0.00001); res.PointGeometry["geometry"]["coordinates"][1].Value <double>().Should().BeApproximately(expectedLatitude, 0.00001); res.PointGeometry["geometry"]["coordinates"][2].Value <double>().Should().BeApproximately(expectedAltitude, 0.1); var polygon = res.PolygonGeometry; var coords = polygon["geometry"]["coordinates"][0]; for (int i = 0; i < expectedCoordinates.Count; i++) { for (int j = 0; j < expectedCoordinates[i].Count; j++) { coords[i][j].Value <double>().Should().BeApproximately(expectedCoordinates[i][j], 0.001); } } }
public void Clean_Domain() { TempFile.CleanDomain(BaseTestFolder); TestFS.ClearCache(BaseTestFolder); }