public void MatchesTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.IsTrue(matcher.Matches(this.localpath, this.remotepath)); string sameSubfolder = "bla"; Assert.IsTrue(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + sameSubfolder)); sameSubfolder = Path.Combine("sub", "folder"); Assert.IsTrue(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + sameSubfolder)); string anotherFolder = "another"; Assert.IsFalse(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + anotherFolder)); string subfolderOfSame = Path.Combine(sameSubfolder, "sub"); Assert.IsFalse(matcher.Matches(Path.Combine(this.localpath, sameSubfolder), this.remotepath + "/" + subfolderOfSame)); Assert.IsFalse(matcher.Matches(Path.Combine(this.localpath, subfolderOfSame), this.remotepath + "/" + sameSubfolder)); string wrongStartingFolder = "wrong"; try { matcher.Matches(Path.Combine(this.localpath, wrongStartingFolder), wrongStartingFolder); Assert.Fail("Should throw exception on wrong path start"); } catch (ArgumentOutOfRangeException) { } try { matcher.Matches(wrongStartingFolder, wrongStartingFolder); Assert.Fail("Should throw exception on wrong path start"); } catch (ArgumentOutOfRangeException) { } try { matcher.Matches(wrongStartingFolder, this.remotepath + "/" + wrongStartingFolder); Assert.Fail("Should throw exception on wrong path start"); } catch (ArgumentOutOfRangeException) { } }
public void GetRootFolderRelativePathWithoutTrailingDenominator() { var matcher = new PathMatcher(Path.GetTempPath(), "/tmp"); Assert.That(matcher.GetRelativeLocalPath(Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar)), Is.EqualTo(".")); }
public void ConstructorTakesLocalAndRemotePath() { var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.AreEqual(this.localpath, matcher.LocalTargetRootPath); this.AssertPathEqual(this.remotepath, matcher.RemoteTargetRootPath); }
public void GetRelativePathDoesNotStartWithSlash() { this.localpath = this.localpath.EndsWith(Path.DirectorySeparatorChar.ToString()) ? this.localpath.Substring(0, this.localpath.Length - 1) : this.localpath; var matcher = new PathMatcher(this.localpath, "/"); string folderName = "new"; Assert.That(matcher.GetRelativeLocalPath(Path.Combine(this.localpath, folderName)).StartsWith(Path.DirectorySeparatorChar.ToString()), Is.False); }
public void RootFolderMatchesItselfWithoutTrailingDenominator() { var matcher = new PathMatcher(Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar.ToString(), "/"); Assert.That(matcher.CanCreateRemotePath(Path.GetTempPath().TrimEnd(Path.DirectorySeparatorChar)), Is.True); }
public void CrossPathCreatingTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); string result = matcher.CreateRemotePath(this.localpath); this.AssertPathEqual(this.remotepath, result); result = matcher.CreateLocalPath(result); this.AssertPathEqual(this.localpath, result); result = matcher.CreateRemotePath(Path.Combine(this.localpath, "sub")); result = matcher.CreateLocalPath(result); this.AssertPathEqual(Path.Combine(this.localpath, "sub"), result); result = matcher.CreateLocalPath(this.remotepath + "/sub"); result = matcher.CreateRemotePath(result); this.AssertPathEqual(this.remotepath + "/sub", result); }
public void GetRelativePath() { var matcher = new PathMatcher(this.localpath, this.remotepath); string folderName = "new"; string newLocalPath = Path.Combine(this.localpath, folderName); Assert.That(matcher.GetRelativeLocalPath(newLocalPath), Is.EqualTo(folderName)); }
public void CanCreateRemotePathTest() { string local = Path.Combine(this.localpath, "test"); string wrong = Path.Combine("wrong", "path", "on", "client", "test"); var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.IsTrue(matcher.CanCreateRemotePath(this.localpath)); Assert.IsTrue(matcher.CanCreateRemotePath(local)); Assert.IsFalse(matcher.CanCreateRemotePath(wrong)); var localFolder = new DirectoryInfo(Path.Combine(this.localpath, "test2")); Assert.IsTrue(matcher.CanCreateRemotePath(localFolder)); var wrongFolder = new DirectoryInfo(wrong); Assert.IsFalse(matcher.CanCreateRemotePath(wrongFolder)); }
public void CreateRemotePathTest() { var matcher = new PathMatcher(this.localpath, this.remotepath); string result = matcher.CreateRemotePath(this.localpath); this.AssertPathEqual(this.remotepath, result); string subfolder = "sub"; result = matcher.CreateRemotePath(Path.Combine(this.localpath, subfolder)); Assert.AreEqual(this.remotepath + "/" + subfolder, result); subfolder = "sub/sub"; result = matcher.CreateRemotePath(Path.Combine(this.localpath, "sub", "sub")); Assert.AreEqual(this.remotepath + "/" + subfolder, result); try { matcher.CreateRemotePath(Path.Combine("wrong", "folder")); Assert.Fail(); } catch (ArgumentOutOfRangeException) { } }
public void CanCreateLocalPathTest() { string remote = this.remotepath + "/test"; string wrong = "/wrong/path/on/server/test"; var matcher = new PathMatcher(this.localpath, this.remotepath); Assert.IsTrue(matcher.CanCreateLocalPath(this.remotepath)); Assert.IsTrue(matcher.CanCreateLocalPath(remote)); Assert.IsFalse(matcher.CanCreateLocalPath(wrong)); var remoteFolder = new Mock<IFolder>(); remoteFolder.Setup(f => f.Path).Returns(this.remotepath + "/test2"); Assert.IsTrue(matcher.CanCreateLocalPath(remoteFolder.Object)); var wrongFolder = new Mock<IFolder>(); wrongFolder.Setup(f => f.Path).Returns(wrong + "/test2"); Assert.IsFalse(matcher.CanCreateLocalPath(wrongFolder.Object)); }
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 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 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)); }
private IMetaDataStorage GetInitializedStorage() { IPathMatcher matcher = new PathMatcher(this.localRoot, this.remoteRoot); return new MetaDataStorage(this.engine, matcher, true); }