public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToDelete, Guid workSpaceId) { if (itemToDelete == null) { return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemToDeleteWasNull)); } if (itemToDelete.ResourceType == "Folder") { var deleteResult = DeleteFolder(itemToDelete.ResourcePath, true, workSpaceId); if (deleteResult.Status == ExecStatus.Success) { var folderDeleted = Find(_root, item => item.ResourcePath == itemToDelete.ResourcePath); if (folderDeleted != null) { var parent = Find(_root, item => item.ResourcePath == GetSavePath(folderDeleted)); if (parent != null) { parent.Children.Remove(folderDeleted); } else { _root.Children.Remove(folderDeleted); } } } return(deleteResult); } ResourceCatalogResult result = ResourceCatalogue.DeleteResource(workSpaceId, itemToDelete.ResourceId, itemToDelete.ResourceType); TestCatalog.DeleteAllTests(itemToDelete.ResourceId); if (result.Status == ExecStatus.Success) { var itemDeleted = Find(_root, itemToDelete.ResourceId); if (itemDeleted != null) { var parent = Find(_root, item => item.ResourcePath == GetSavePath(itemDeleted)); if (parent != null) { parent.Children.Remove(itemDeleted); } else { _root.Children.Remove(itemDeleted); } } } return(new ExplorerRepositoryResult(result.Status, result.Message)); }
private ResourceCatalogResult RenameChildrenPaths(string oldPath, string newName) { var resourcesToRename = ResourceCatalogue.GetResourceList(GlobalConstants.ServerWorkspaceID) .Where(a => a.GetResourcePath(GlobalConstants.ServerWorkspaceID).StartsWith(oldPath)).ToList(); if (resourcesToRename.Count == 0) { var resourceCatalogResult = new ResourceCatalogResult { Status = ExecStatus.Success }; return(resourceCatalogResult); } ResourceCatalogResult result = ResourceCatalogue.RenameCategory(GlobalConstants.ServerWorkspaceID, oldPath, newName, resourcesToRename); return(result); }
IExplorerRepositoryResult RenameExplorerItem(IExplorerItem itemToRename, Guid workSpaceId) { IEnumerable <IResource> item = ResourceCatalogue.GetResourceList(workSpaceId) .Where( a => (a.ResourceName == itemToRename.DisplayName.Trim()) && (a.ResourceID == itemToRename.ResourceId)); if (item.Any()) { return(new ExplorerRepositoryResult(ExecStatus.Fail, ErrorResource.ItemAlreadyExistInPath)); } ResourceCatalogResult result = ResourceCatalogue.RenameResource(workSpaceId, itemToRename.ResourceId, itemToRename.DisplayName, itemToRename.ResourcePath); return(new ExplorerRepositoryResult(result.Status, result.Message)); }
IExplorerRepositoryResult RenameExplorerItem(IExplorerItem itemToRename, Guid workSpaceId) { IEnumerable <IResource> item = ResourceCatalogue.GetResourceList(workSpaceId) .Where( a => (a.ResourceName == itemToRename.DisplayName.Trim()) && (a.ResourcePath == itemToRename.ResourcePath.Trim())); if (item.Any()) { return(new ExplorerRepositoryResult(ExecStatus.Fail, "There is an item that exists with the same name and path")); } ResourceCatalogResult result = ResourceCatalogue.RenameResource(workSpaceId, itemToRename.ResourceId, itemToRename.DisplayName); return(new ExplorerRepositoryResult(result.Status, result.Message)); }
public IExplorerRepositoryResult DeleteItem(IExplorerItem itemToDelete, Guid workSpaceId) { if (itemToDelete == null) { return(new ExplorerRepositoryResult(ExecStatus.Fail, "Item to delete was null")); } switch (itemToDelete.ResourceType) { case ResourceType.Folder: { return(DeleteFolder(itemToDelete.ResourcePath, true, workSpaceId)); } default: ResourceCatalogResult result = ResourceCatalogue.DeleteResource(workSpaceId, itemToDelete.DisplayName, itemToDelete.ResourceType.ToString()); return(new ExplorerRepositoryResult(result.Status, result.Message)); } }
public IExplorerRepositoryResult MoveItem(IExplorerItem itemToMove, string newPath, Guid workSpaceId) { IEnumerable <IResource> item = ResourceCatalogue.GetResourceList(workSpaceId) .Where( a => (a.ResourcePath == newPath)); if (item.Any()) { return(new ExplorerRepositoryResult(ExecStatus.Fail, "There is an item that exists with the same name and path")); } MoveVersions(itemToMove, newPath); ResourceCatalogResult result = ResourceCatalogue.RenameCategory(workSpaceId, itemToMove.ResourcePath, newPath, new List <IResource> { ResourceCatalogue.GetResource(workSpaceId, itemToMove.ResourceId) }); _file.Delete(string.Format("{0}.xml", DirectoryStructureFromPath(itemToMove.ResourcePath))); return(new ExplorerRepositoryResult(result.Status, result.Message)); }
IExplorerRepositoryResult MoveSingeItem(IExplorerItem itemToMove, string newPath, Guid workSpaceId) { var newResourcePath = newPath; if (!string.IsNullOrEmpty(itemToMove.ResourcePath)) { newResourcePath = itemToMove.ResourcePath.Replace(itemToMove.ResourcePath, newPath); } var resource = ResourceCatalogue.GetResource(workSpaceId, itemToMove.ResourceId); var source = $"{DirectoryStructureFromPath(resource.GetResourcePath(GlobalConstants.ServerWorkspaceID))}.xml"; var destination = $"{DirectoryStructureFromPath(newResourcePath)+"\\"+resource.ResourceName+".xml"}"; if (_file.Exists(source)) { _file.Move(source, destination); } ResourceCatalogResult result = ResourceCatalogue.RenameCategory(workSpaceId, resource.GetSavePath(), newResourcePath, new List <IResource> { resource }); itemToMove.ResourcePath = newResourcePath; return(new ExplorerRepositoryResult(result.Status, result.Message)); }
public void ServerExplorerRepository_RenameFolder_FilesystemError_ExpectFailureMessage() { //------------Setup for test-------------------------- var catalogue = new Mock<IResourceCatalog>(); ResourceCatalogResult resourceCatalogResult = new ResourceCatalogResult { Status = ExecStatus.Success, Message = "" }; catalogue.Setup(catalog => catalog.RenameCategory(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<string>())).Returns(resourceCatalogResult); var factory = new Mock<IExplorerItemFactory>(); var dir = new Mock<IDirectory>(); var guid = Guid.NewGuid(); var explorerItem = new ServerExplorerItem( "dave", guid, ResourceType.DbSource, new List<IExplorerItem>() , Permissions.Administrator, "bob" ); factory.Setup(a => a.CreateRootExplorerItem(It.IsAny<string>(), It.IsAny<Guid>())).Returns(explorerItem); dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(true); dir.Setup(a => a.Delete(It.IsAny<string>(), It.IsAny<bool>())).Throws(new FieldAccessException("bob has an error")).Verifiable(); var sync = new Mock<IExplorerRepositorySync>(); var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper()); //------------Execute Test--------------------------- var result = serverExplorerRepository.RenameFolder("monkey", "moocowimpi", Guid.NewGuid()); //------------Assert Results------------------------- Assert.AreEqual(result.Message, "bob has an error"); Assert.AreEqual(result.Status, ExecStatus.AccessViolation); }
public void ServerExplorerRepository_RenameFolder_ResourceCatalogFailure_ErrorReturnedNoDelete() { //------------Setup for test-------------------------- var catalogue = new Mock<IResourceCatalog>(); ResourceCatalogResult resourceCatalogResult = new ResourceCatalogResult { Status = ExecStatus.Fail, Message = "Error Renaming" }; catalogue.Setup(catalog => catalog.RenameCategory(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<string>())).Returns(resourceCatalogResult); var factory = new Mock<IExplorerItemFactory>(); var dir = new Mock<IDirectory>(); var guid = Guid.NewGuid(); var res = new Mock<IResource>(); var explorerItem = new ServerExplorerItem( "dave", guid, ResourceType.DbSource, new List<IExplorerItem>() , Permissions.Administrator, "bob" ); factory.Setup(a => a.CreateRootExplorerItem(It.IsAny<string>(), It.IsAny<Guid>())).Returns(explorerItem); dir.Setup(a => a.Exists(It.IsAny<string>())).Returns(true); dir.Setup(a => a.Move(It.IsAny<string>(), It.IsAny<string>())).Verifiable(); var sync = new Mock<IExplorerRepositorySync>(); var serverExplorerRepository = new ServerExplorerRepository(catalogue.Object, factory.Object, dir.Object, sync.Object, new Mock<IServerVersionRepository>().Object, new FileWrapper()); catalogue.Setup(a => a.GetResourceList(It.IsAny<Guid>())).Returns(new List<IResource> { res.Object }); catalogue.Setup(a => a.SaveResource(It.IsAny<Guid>(), res.Object, null, It.IsAny<string>(), It.IsAny<string>())).Verifiable(); res.Setup(a => a.ResourcePath).Returns("monkey2"); //------------Execute Test--------------------------- var result = serverExplorerRepository.RenameFolder("monkey", "moocowimpi", Guid.NewGuid()); //------------Assert Results------------------------- Assert.AreEqual(result.Message, "Error Renaming"); Assert.AreEqual(result.Status, ExecStatus.Fail); dir.Verify(a => a.Delete(It.IsAny<string>(), It.IsAny<bool>()), Times.Never()); catalogue.Verify(a => a.RenameCategory(It.IsAny<Guid>(), It.IsAny<string>(), It.IsAny<string>()), Times.Once()); }