public SaveMappedObject ( IMappedObject obj ) : void | ||
obj | IMappedObject | /// The MappedObject instance. /// |
Результат | void |
public void FindRootFolder([Values(true, false)]bool withValidation) { string id = "id"; string path = Path.GetTempPath(); var fsInfo = new DirectoryInfoWrapper(new DirectoryInfo(path)); var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher, withValidation); var rootFolder = new MappedObject("/", id, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); Assert.That(storage.GetObjectByRemoteId(id), Is.Not.Null, "Not findable by ID"); Assert.That(storage.GetObjectByLocalPath(fsInfo), Is.Not.Null, "Not findable by path"); }
public void SaveRenamedMappedObjectOverridesExistingEntry([Values(true, false)]bool withValidation) { string id = "id"; string oldName = "my"; string newName = "newMy"; string path = Path.GetTempPath(); string parentId = "ParentId"; string oldToken = "oldToken"; string newToken = "newToken"; var matcher = new PathMatcher(path, "/"); var storage = new MetaDataStorage(this.engine, matcher, withValidation); var rootFolder = new MappedObject("/", parentId, MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); var folder = new MappedObject(oldName, id, MappedObjectType.Folder, parentId, oldToken); storage.SaveMappedObject(folder); var savedObject = storage.GetObjectByRemoteId(id); savedObject.Name = newName; savedObject.LastChangeToken = newToken; storage.SaveMappedObject(savedObject); Assert.That(storage.GetObjectByLocalPath(Mock.Of<IDirectoryInfo>(d => d.FullName == Path.Combine(path, oldName))), Is.Null); Assert.That(storage.GetObjectByLocalPath(Mock.Of<IDirectoryInfo>(d => d.FullName == Path.Combine(path, newName))), Is.EqualTo(savedObject)); }
public void GetObjectTreeReturnsTreeEqualToFolderStructure([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); var child2File = new MappedObject("sub2", "subId2", MappedObjectType.File, "subId1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); storage.SaveMappedObject(child2File); var tree = storage.GetObjectTree(); Assert.That(tree.Item, Is.EqualTo(rootFolder)); Assert.That(tree.Children.Count, Is.EqualTo(1)); Assert.That(tree.Children[0].Item, Is.EqualTo(child1Folder)); Assert.That(tree.Children[0].Children.Count, Is.EqualTo(1)); Assert.That(tree.Children[0].Children[0].Item, Is.EqualTo(child2File)); }
public void GetObjectByPathWithHierarchie([Values(true, false)]bool withValidation) { var matcher = new PathMatcher(Path.GetTempPath(), "/"); var storage = new MetaDataStorage(this.engine, matcher, withValidation); var root = Mock.Of<IDirectoryInfo>(f => f.FullName == Path.GetTempPath()); var folder = Mock.Of<IDirectoryInfo>( f => f.FullName == Path.Combine(Path.GetTempPath(), "a")); var mappedRoot = new MappedObject("/", "rootId", MappedObjectType.Folder, null, null); var mappedFolder = new MappedObject("a", "remoteId", MappedObjectType.Folder, "rootId", null) { Guid = Guid.NewGuid(), }; storage.SaveMappedObject(mappedRoot); storage.SaveMappedObject(mappedFolder); var obj = storage.GetObjectByLocalPath(folder); Assert.That(storage.GetObjectByLocalPath(root), Is.EqualTo(mappedRoot)); Assert.That(obj, Is.EqualTo(mappedFolder)); }
public void ValidateFolderStructureThrowsExceptionIfFileParentIdIsFileObject() { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), false); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1File = new MappedObject("sub1", "subId1", MappedObjectType.File, "rootId", "token"); var child2File = new MappedObject("sub2", "subId2", MappedObjectType.File, "sub1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1File); storage.SaveMappedObject(child2File); Assert.Throws<InvalidDataException>(() => storage.ValidateObjectStructure()); }
public void GetObjectByGuidReturnsSavedObject([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var uuid = Guid.NewGuid(); var file = new MappedObject("name" , "rootId", MappedObjectType.File, null, "token") { Guid = uuid }; storage.SaveMappedObject(file); Assert.That(storage.GetObjectByGuid(uuid), Is.EqualTo(file)); }
public void SaveFileObjectAndGetObjectReturnsEqualObject([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); string remoteId = "remoteId"; var file = new MappedObject("file", remoteId, MappedObjectType.File, null, null) { Description = "desc", Guid = Guid.NewGuid(), LastChecksum = new byte[20] }; storage.SaveMappedObject(file); var obj = storage.GetObjectByRemoteId(remoteId); Assert.That(obj.LastChecksum, Is.Not.Null); Assert.That(obj.Equals(file)); }
public void ToLinePrintReturnsOneLinePerNotFittingEntry() { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), false); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "WRONGID", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); string src = storage.ToFindString(); int count = src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(Environment.NewLine)); Assert.That(count, Is.EqualTo(2), string.Format("Newlines Counting {0}:{2} {1}", count, src, Environment.NewLine)); }
public void SaveFolderObjectAndGetObjectReturnEqualObject([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); string remoteId = "remoteId"; var folder = new MappedObject("folder", remoteId, MappedObjectType.Folder, null, null) { Description = "desc", Guid = Guid.NewGuid(), }; storage.SaveMappedObject(folder); var obj = storage.GetObjectByRemoteId(remoteId); Assert.That(obj.Equals(folder)); }
public void StoreDateOnStoringMappedObject([Values(true, false)]bool withValidation) { var underTest = new MetaDataStorage(this.engine, this.matcher, withValidation); IMappedObject obj = new MappedObject("obj", "remoteId", MappedObjectType.File, null, null); Assert.That(obj.LastTimeStoredInStorage, Is.Null); underTest.SaveMappedObject(obj); obj = underTest.GetObjectByRemoteId("remoteId"); Assert.That(obj.LastTimeStoredInStorage, Is.EqualTo(DateTime.UtcNow).Within(1).Seconds); }
public void SaveMappedObjectThrowsExceptionOnNonExistingIdInObject([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); Assert.Throws<ArgumentException>(() => storage.SaveMappedObject(Mock.Of<IMappedObject>())); }
public void SaveMappedObjectThrowsExceptionOnNullArgument([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); Assert.Throws<ArgumentNullException>(() => storage.SaveMappedObject(null)); }
public void GetChildrenReturnsEmptyListIfNoChildrenAreAvailable([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); var folder = new MappedObject("name", "id", MappedObjectType.Folder, null, null); storage.SaveMappedObject(folder); Assert.That(storage.GetChildren(folder).Count == 0); }
public void ToLinePrintReturnsOneLineIfOnlyRootFolderIsInDB([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); Assert.That(storage.ToFindString(), Is.EqualTo("name" + Environment.NewLine)); }
public void RemoveObjectTest([Values(true, false)]bool withValidation) { string remoteId = "remoteId"; var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); var obj = new MappedObject("name", remoteId, MappedObjectType.Folder, null, null); storage.SaveMappedObject(obj); storage.RemoveObject(obj); Assert.That(storage.GetObjectByRemoteId(remoteId), Is.Null); }
public void ToLinePrintReturnsOneLinePerEntry([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); var child2Folder = new MappedObject("sub2", "subId2", MappedObjectType.Folder, "rootId", "token"); var child3Folder = new MappedObject("sub3", "subId3", MappedObjectType.Folder, "rootId", "token"); var subChildFile = new MappedObject("file", "subId4", MappedObjectType.File, "subId1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); storage.SaveMappedObject(child2Folder); storage.SaveMappedObject(child3Folder); storage.SaveMappedObject(subChildFile); string src = storage.ToFindString(); int count = src.Select((c, i) => src.Substring(i)).Count(sub => sub.StartsWith(Environment.NewLine)); Assert.That(count, Is.EqualTo(5), string.Format("Newlines Counting {0}:{2} {1}", count, src, Environment.NewLine)); }
public void RemoveObjectDoesNotTouchParents([Values(true, false)]bool withValidation) { string remoteId = "remoteId"; string childId = "childId"; string subChildId = "subchildId"; var storage = new MetaDataStorage(this.engine, this.matcher, withValidation); var obj = new MappedObject("name", remoteId, MappedObjectType.Folder, null, null); var child = new MappedObject("child", childId, MappedObjectType.Folder, remoteId, null); var subchild = new MappedObject("subchild", subChildId, MappedObjectType.File, childId, null); storage.SaveMappedObject(obj); storage.SaveMappedObject(child); storage.SaveMappedObject(subchild); storage.RemoveObject(child); Assert.That(storage.GetObjectByRemoteId(remoteId), Is.EqualTo(obj)); Assert.That(storage.GetObjectByRemoteId(childId), Is.Null); Assert.That(storage.GetObjectByRemoteId(subChildId), Is.Null); }
public void ValidateFolderStructureThrowsExceptionIfRootObjectIsMissingButOtherObjectsAreStored() { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), false); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); storage.SaveMappedObject(child1Folder); Assert.Throws<InvalidDataException>(() => storage.ValidateObjectStructure()); }
public void GetLocalPath([Values(true, false)]bool withValidation) { var matcher = new Mock<IPathMatcher>(); matcher.Setup(m => m.LocalTargetRootPath).Returns(Path.GetTempPath()); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); string id = "remoteId"; var rootFolder = new MappedObject("name", id, MappedObjectType.Folder, null, null); storage.SaveMappedObject(rootFolder); string path = storage.GetLocalPath(rootFolder); Assert.That(path, Is.EqualTo(Path.Combine(Path.GetTempPath(), "name"))); }
public void ValidateFolderStructureIsFineOnCleanFolderStructure([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1Folder = new MappedObject("sub1", "subId1", MappedObjectType.Folder, "rootId", "token"); var child2File = new MappedObject("sub2", "subId2", MappedObjectType.File, "subId1", "token"); storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1Folder); storage.SaveMappedObject(child2File); storage.ValidateObjectStructure(); }
public void GetLocalPathOfNonExistingEntryReturnsNull([Values(true, false)]bool withValidation) { var matcher = new Mock<IPathMatcher>(); matcher.Setup(m => m.LocalTargetRootPath).Returns(Path.GetTempPath()); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); string id = "nonExistingId"; var rootFolder = new MappedObject("name", "otherId", MappedObjectType.Folder, null, null); var otherFolder = new MappedObject("name", id, MappedObjectType.Folder, "otherId", null); storage.SaveMappedObject(rootFolder); Assert.That(storage.GetLocalPath(otherFolder), Is.Null); }
public void GetObjectTreeReturnsOneItemWithEmptyChildrenList([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); storage.SaveMappedObject(rootFolder); var tree = storage.GetObjectTree(); Assert.That(tree.Item, Is.EqualTo(rootFolder)); Assert.That(tree.Children, Is.Empty); }
public void GetRemotePathWithCorrectSlashes([Values(true, false)]bool withValidation) { var matcher = new Mock<IPathMatcher>(); matcher.Setup(m => m.RemoteTargetRootPath).Returns("/"); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); var remoteRootFolder = new MappedObject("/", "rootId", MappedObjectType.Folder, null, null); var remoteFolder = new MappedObject("remoteFolder", "remoteId", MappedObjectType.Folder, "rootId", null); storage.SaveMappedObject(remoteRootFolder); storage.SaveMappedObject(remoteFolder); string remotePath = storage.GetRemotePath(remoteFolder); Assert.That(remotePath, Is.EqualTo("/remoteFolder")); }
public void ThrowOnDublicateGuid([Values(true, false)]bool withValidation) { var storage = new MetaDataStorage(this.engine, Mock.Of<IPathMatcher>(), withValidation); var rootFolder = new MappedObject("name", "rootId", MappedObjectType.Folder, null, "token"); var child1 = new MappedObject("sub1", "subId1", MappedObjectType.File, "rootId", "token"); child1.Guid = Guid.NewGuid(); var child2 = new MappedObject("sub2", "subId2", MappedObjectType.File, "rootId", "token"); child2.Guid = child1.Guid; storage.SaveMappedObject(rootFolder); storage.SaveMappedObject(child1); Assert.Throws<DublicateGuidException>(() => storage.SaveMappedObject(child2)); }
public void GetObjectByPath([Values(true, false)]bool withValidation) { var matcher = new Mock<IPathMatcher>(); matcher.Setup(m => m.LocalTargetRootPath).Returns(Path.GetTempPath()); matcher.Setup(m => m.CanCreateRemotePath(It.Is<string>(f => f == Path.Combine(Path.GetTempPath(), "a")))).Returns(true); matcher.Setup(m => m.GetRelativeLocalPath(It.Is<string>(p => p == Path.Combine(Path.GetTempPath(), "a")))).Returns("a"); var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation); var folder = Mock.Of<IDirectoryInfo>( f => f.FullName == Path.Combine(Path.GetTempPath(), "a")); var mappedFolder = new MappedObject("a", "remoteId", MappedObjectType.Folder, null, null) { Guid = Guid.NewGuid(), }; storage.SaveMappedObject(mappedFolder); var obj = storage.GetObjectByLocalPath(folder); Assert.That(obj, Is.EqualTo(mappedFolder)); }