示例#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));
        }
示例#2
0
        public void GetObjectByPathThrowsExceptionIfLocalPathDoesNotMatchToSyncPath()
        {
            var    matcher   = new Mock <IPathMatcher>();
            string localpath = Path.GetTempPath();
            var    folder    = Mock.Of <IDirectoryInfo>(f =>
                                                        f.FullName == localpath);

            matcher.Setup(m => m.CanCreateRemotePath(It.Is <string>(f => f == localpath))).Returns(false);
            var storage = new MetaDataStorage(this.engine, matcher.Object);

            storage.GetObjectByLocalPath(folder);
        }
示例#3
0
        public void GetObjectByPathWithHierarchie()
        {
            var matcher = new PathMatcher(Path.GetTempPath(), "/");
            var storage = new MetaDataStorage(this.engine, matcher);
            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));
        }
示例#4
0
        public void GetObjectByPathThrowsExceptionIfLocalPathDoesNotMatchToSyncPath([Values(true, false)] bool withValidation)
        {
            var    matcher   = new Mock <IPathMatcher>();
            string localpath = Path.GetTempPath();
            var    folder    = Mock.Of <IDirectoryInfo>(
                f =>
                f.FullName == localpath);

            matcher.Setup(m => m.CanCreateRemotePath(It.Is <string>(f => f == localpath))).Returns(false);
            var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation);

            Assert.Throws <ArgumentException>(() => storage.GetObjectByLocalPath(folder));
        }
示例#5
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");
        }
示例#6
0
        public void GetObjectByPathWithNotExistingEntryMustReturnNull([Values(true, false)] bool withValidation)
        {
            var    matcher      = new Mock <IPathMatcher>();
            string testfilename = "test";
            string testpath     = Path.Combine(Path.GetTempPath(), testfilename);

            matcher.Setup(m => m.CanCreateRemotePath(It.Is <string>(f => f == testpath))).Returns(true);
            matcher.Setup(m => m.GetRelativeLocalPath(It.Is <string>(f => f == testpath))).Returns(testfilename);
            var storage = new MetaDataStorage(this.engine, matcher.Object, withValidation);

            var path = Mock.Of <IFileSystemInfo>(p => p.FullName == testpath);

            Assert.That(storage.GetObjectByLocalPath(path), Is.Null);
        }
示例#7
0
        public void GetObjectByPath()
        {
            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);
            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));
        }
示例#8
0
        public void GetObjectByPathThrowsExceptionOnNullArgument()
        {
            var storage = new MetaDataStorage(this.engine, this.matcher);

            storage.GetObjectByLocalPath(null);
        }
示例#9
0
        public void GetObjectByPathThrowsExceptionOnNullArgument([Values(true, false)] bool withValidation)
        {
            var storage = new MetaDataStorage(this.engine, this.matcher, withValidation);

            Assert.Throws <ArgumentNullException>(() => storage.GetObjectByLocalPath(null));
        }