Exemplo n.º 1
0
        public void SaveRenamedMappedObjectOverridesExistingEntry()
        {
            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);
            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));
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        public void RemoveObjectDoesNotTouchParents()
        {
            string remoteId   = "remoteId";
            string childId    = "childId";
            string subChildId = "subchildId";
            var    storage    = new MetaDataStorage(this.engine, this.matcher);
            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);
        }
Exemplo n.º 4
0
        public void RemoveObjectRemovesChildrenAsWell([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(obj);

            Assert.That(storage.GetObjectByRemoteId(remoteId), Is.Null);
            Assert.That(storage.GetObjectByRemoteId(childId), Is.Null);
            Assert.That(storage.GetObjectByRemoteId(subChildId), Is.Null);
        }
Exemplo n.º 5
0
        public void RemoveObjectTest()
        {
            string remoteId = "remoteId";
            var    storage  = new MetaDataStorage(this.engine, this.matcher);
            var    obj      = new MappedObject("name", remoteId, MappedObjectType.Folder, null, null);

            storage.SaveMappedObject(obj);

            storage.RemoveObject(obj);

            Assert.That(storage.GetObjectByRemoteId(remoteId), Is.Null);
        }
Exemplo n.º 6
0
        public void FindRootFolder()
        {
            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);
            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");
        }
Exemplo n.º 7
0
        public void SaveFolderObjectAndGetObjectReturnEqualObject()
        {
            var    storage  = new MetaDataStorage(this.engine, this.matcher);
            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));
        }
Exemplo n.º 8
0
        public void SaveFileObjectAndGetObjectReturnsEqualObject()
        {
            var    storage  = new MetaDataStorage(this.engine, this.matcher);
            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));
        }
Exemplo n.º 9
0
        public void GetObjectByIdWithNotExistingIdMustReturnNull()
        {
            var storage = new MetaDataStorage(this.engine, this.matcher);

            Assert.That(storage.GetObjectByRemoteId("DOESNOTEXIST"), Is.Null);
        }
Exemplo n.º 10
0
        public void GetObjectByIdWithNotExistingIdMustReturnNull([Values(true, false)] bool withValidation)
        {
            var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);

            Assert.That(storage.GetObjectByRemoteId("DOESNOTEXIST"), Is.Null);
        }