public void constructor_should_create_empty_files_and_childfolders() { // Arrange + Act DirectoryViewModel model = new DirectoryViewModel("", ""); // Assert Assert.That(model.Files.Count, Is.EqualTo(0)); Assert.That(model.ChildFolders.Count, Is.EqualTo(0)); }
public void Constructor_Should_Create_Empty_Files_And_ChildFolders() { // Arrange + Act DirectoryViewModel model = new DirectoryViewModel("", ""); // Assert Assert.That(model.Files.Count, Is.EqualTo(0)); Assert.That(model.ChildFolders.Count, Is.EqualTo(0)); }
public DirectoryViewModel FolderInfo(string dir) { if (CustomException != null) throw CustomException; DirectoryViewModel model = new DirectoryViewModel(dir, dir+ "urlpath"); model.Files.Add(new FileViewModel("file1.txt", "txt", 12345, DateTime.UtcNow, "")); model.ChildFolders.Add(new DirectoryViewModel("child", "childurlpath")); return model; }
public void constructor_should_fill_properties() { // Arrange string name = "MyDirectory"; string urlPath = "/Home/MyDirectory"; // Act DirectoryViewModel model = new DirectoryViewModel(name, urlPath); // Assert Assert.That(model.Name, Is.EqualTo(name)); Assert.That(model.UrlPath, Is.EqualTo(urlPath)); }
public DirectoryViewModel FolderInfo(string dir) { try { string currentFolderName = dir; if (!string.IsNullOrEmpty(currentFolderName) && currentFolderName != "/") currentFolderName = Path.GetFileName(dir); DirectoryViewModel directoryModel = new DirectoryViewModel(currentFolderName, dir); CloudBlobContainer container = GetCloudBlobContainer(); CloudBlobDirectory azureDirectory = container.GetDirectoryReference(dir); List<CloudBlobDirectory> directories = azureDirectory.ListBlobs() .Select(b => b as CloudBlobDirectory) .Where(b => b != null) .ToList(); List<CloudBlockBlob> files = azureDirectory.ListBlobs() .OfType<CloudBlockBlob>() .Where(b => !FilesToExclude.Contains(Path.GetFileName(b.Name))) .ToList(); foreach (CloudBlobDirectory directory in directories) { string dirName = directory.Prefix.TrimEnd('/'); dirName = dirName.Replace(directory.Parent.Prefix, String.Empty); DirectoryViewModel childModel = new DirectoryViewModel(dirName, directory.Prefix.TrimEnd('/')); directoryModel.ChildFolders.Add(childModel); } foreach (CloudBlockBlob file in files) { file.FetchAttributes(); string filename = file.Name; FileViewModel fileModel = new FileViewModel(Path.GetFileName(file.Name), Path.GetExtension(file.Name).Replace(".", ""), file.Properties.Length, ((DateTimeOffset)file.Properties.LastModified).DateTime, dir); directoryModel.Files.Add(fileModel); } return directoryModel; } catch (StorageException e) { throw new FileException(e.Message, e); } }
public ActionResult FolderInfo(string dir) { if (!Directory.Exists(ApplicationSettings.AttachmentsDirectoryPath)) return Json(new { status = "error", message = "The attachments directory does not exist - please create it." }); string folder = dir; folder = Server.UrlDecode(folder); string physicalPath = _attachmentPathUtil.ConvertUrlPathToPhysicalPath(folder); if (!_attachmentPathUtil.IsAttachmentPathValid(physicalPath)) { throw new SecurityException(null, "Attachment path was invalid when getting the folder {0}", dir); } try { string currentFolderName = dir; if (!string.IsNullOrEmpty(currentFolderName) && currentFolderName != "/") currentFolderName = Path.GetFileName(dir); DirectoryViewModel directoryModel = new DirectoryViewModel(currentFolderName, dir); if (Directory.Exists(physicalPath)) { foreach (string directory in Directory.GetDirectories(physicalPath)) { DirectoryInfo info = new DirectoryInfo(directory); string fullPath = info.FullName; fullPath = fullPath.Replace(ApplicationSettings.AttachmentsDirectoryPath, ""); fullPath = fullPath.Replace(Path.DirectorySeparatorChar.ToString(), "/"); fullPath = "/" + fullPath; // removed in the 1st replace DirectoryViewModel childModel = new DirectoryViewModel(info.Name, fullPath); directoryModel.ChildFolders.Add(childModel); } foreach (string file in Directory.GetFiles(physicalPath)) { FileInfo info = new FileInfo(file); string filename = info.Name; if (!_filesToExclude.Contains(info.Name)) { string urlPath = Path.Combine(dir, filename); FileViewModel fileModel = new FileViewModel(info.Name, info.Extension.Replace(".", ""), info.Length, info.CreationTime, dir); directoryModel.Files.Add(fileModel); } } } return Json(directoryModel); } catch (IOException e) { return Json(new { status = "error", message = "An unhandled error occurred: "+e.Message }); } }