Adds unlit color to hidden file system browser dialog elements.

This commit is contained in:
BinaryAlley committed 2026-11-15 13:53:23 +02:00
1 parent 3f7cc2c60f
commit b46dce745b
58 files changed
+855 -360

No files matched your search

+1 -1
View File
@@ -153,7 +153,7 @@ Both book and music pages double as editors for the items that were scanned in.
## The file system browser
Wherever Lumina needs a folder or a file from the server, it opens the file system browser: a modal that lists the drives, a tree of folders, a pane of the items in the current folder, and an address bar you can walk with. It offers icon view modes, generates thumbnails for images, and can show or hide hidden files. You will meet it when you pick the content locations of a library, and anywhere else the interface asks you to point at a path on the server.
Wherever Lumina needs a folder or a file from the server, it opens the file system browser: a modal that lists the drives, a tree of folders, a pane of the items in the current folder, and an address bar you can walk with. It offers icon view modes, generates thumbnails for images, and can show or hide hidden files. Hidden entries are dimmed by the bundled themes. You will meet it when you pick the content locations of a library, and anywhere else the interface asks you to point at a path on the server.
## Settings and language
@@ -32,14 +32,16 @@ GET api/v1/directories/get-directories?path=C%3A%5CUsers%5C&shouldIncludeHiddenE
"path": "/media/movies/The Matrix (1999)/",
"name": "The Matrix",
"dateCreated": "2025-01-01T13:50:38.3183787Z",
"dateModified": "2025-01-01T13:40:38.3183791Z"
"dateModified": "2025-01-01T13:40:38.3183791Z",
"isHidden": false
},
{
"items": [],
"path": "/media/movies/The Lord of the Rings - The Fellowship of the Ring (2001)/",
"name": "The Lord of the Rings - The Fellowship of the Ring (2001)",
"dateCreated": "2025-01-01T13:50:38.3184681Z",
"dateModified": "2025-01-01T13:40:38.3184683Z"
"dateModified": "2025-01-01T13:40:38.3184683Z",
"isHidden": false
}
]
```
@@ -31,6 +31,7 @@ GET api/v1/drives/get-drives
"path": "C:\\",
"name": "C:\\",
"itemType": "Root",
"isHidden": false,
"isExpanded": false,
"childrenLoaded": false,
"children": []
@@ -39,6 +40,7 @@ GET api/v1/drives/get-drives
"path": "D:\\",
"name": "D:\\",
"itemType": "Root",
"isHidden": false,
"isExpanded": false,
"childrenLoaded": false,
"children": []
@@ -35,14 +35,16 @@ GET api/v1/files/get-files?path=C%3A%5CUsers%5C&shouldIncludeHiddenElements=true
"path": "/media/movies/The Matrix (1999)/The Matrix.mkv",
"name": "The Matrix.mkv",
"dateCreated": "2025-01-01T13:50:38.3143711Z",
"dateModified": "2025-01-01T13:40:38.3143719Z"
"dateModified": "2025-01-01T13:40:38.3143719Z",
"isHidden": false
},
{
"size": 6897,
"path": "/media/movies/The Matrix (1999)/The Matrix.en.srt",
"name": "The Matrix.en.srt",
"dateCreated": "2025-01-01T13:50:38.3145606Z",
"dateModified": "2025-01-01T13:40:38.3145609Z"
"dateModified": "2025-01-01T13:40:38.3145609Z",
"isHidden": false
}
]
```
@@ -67,6 +69,7 @@ GET api/v1/files/get-tree-files?path=C%3A%5CUsers%5C&shouldIncludeHiddenElements
"path": "/media/movies/The Matrix (1999)/The Matrix.mkv",
"name": "The Matrix.mkv",
"itemType": "File",
"isHidden": false,
"isExpanded": false,
"childrenLoaded": false,
"children": []
@@ -75,6 +78,7 @@ GET api/v1/files/get-tree-files?path=C%3A%5CUsers%5C&shouldIncludeHiddenElements
"path": "/media/movies/The Matrix (1999)/The Matrix.en.srt",
"name": "The Matrix.en.srt",
"itemType": "File",
"isHidden": false,
"isExpanded": false,
"childrenLoaded": false,
"children": []
@@ -83,6 +87,7 @@ GET api/v1/files/get-tree-files?path=C%3A%5CUsers%5C&shouldIncludeHiddenElements
"path": "/media/movies/The Matrix (1999)/poster.jpg",
"name": "poster.jpg",
"itemType": "File",
"isHidden": false,
"isExpanded": false,
"childrenLoaded": false,
"children": []
+3 -3
View File
@@ -86,7 +86,7 @@ The manifest is a JSON object describing the theme. The example below is the man
"name": "Editorial Paper",
"description": "A clean, readable proof of concept theme.",
"author": "Lumina",
"version": "1.4.0",
"version": "1.5.61",
"preview": "assets/preview.svg",
"templates": {
"default": "templates/index.html"
@@ -511,8 +511,8 @@ The sub templates are rendered client side by the application script for each dy
| Template | Fields |
| --- | --- |
| `tree-node` | `path`, `name`, `itemType` (`Root`, `Directory` or `File`), `isRoot`, `isDirectory`, `isFile`, `isExpanded` and `icon`. The node must keep the `.tree-node` root with its `data-path`, the `.node-content`, `.expand-button` (or `.spacer` for files), `.node-icon` and `.node-name` elements, and the `.child-nodes` container. |
| `explorer-item` | `path`, `name`, `itemType` (`Directory` or `File`), `isDirectory`, `isFile`, `cssClass` (the active view mode, such as `large-icons`) and `iconUrl`. The item must keep the `.e` root with its `data-path` and `data-type`, and an `<img>` element, which the script replaces with thumbnails for image files. |
| `tree-node` | `path`, `name`, `itemType` (`Root`, `Directory` or `File`), `isRoot`, `isDirectory`, `isFile`, `isHidden`, `isExpanded` and `icon`. The node must keep the `.tree-node` root with its `data-path`, the `.node-content`, `.expand-button` (or `.spacer` for files), `.node-icon` and `.node-name` elements, and the `.child-nodes` container. When `isHidden` is true the application also adds the `is-hidden` class to the root, so a theme can dim hidden nodes. |
| `explorer-item` | `path`, `name`, `itemType` (`Directory` or `File`), `isDirectory`, `isFile`, `isHidden`, `cssClass` (the active view mode, such as `large-icons`) and `iconUrl`. The item must keep the `.e` root with its `data-path` and `data-type`, and an `<img>` element, which the script replaces with thumbnails for image files. When `isHidden` is true the application also adds the `is-hidden` class to the root, so a theme can dim hidden items. |
| `path-segment` | `id`, `path` (the segment name), `dataPath` (the full path up to and including the segment), `toggleId` and `dropdownId`. The segment must keep the combobox structure with its `.navigator-combobox` (`data-path`), `.navigator-toggle-checkbox`, `.navigator-selected-text`, `.navigator-arrow` and `.navigator-dropdown` elements. |
#### The file icons mapping (assets/file-icons.json)
@@ -26,10 +26,10 @@ public static class DirectoryMapping
Name = domainEntity.Name,
Path = domainEntity.Id.Path,
ItemType = domainEntity.Type,
IsHidden = domainEntity.IsHidden,
IsExpanded = false,
ChildrenLoaded = false,
Children = domainEntity.Items.Select(item => item.ToTreeNodeResponse())
.ToList()
Children = [.. domainEntity.Items.Select(item => item.ToTreeNodeResponse())]
};
}
@@ -55,8 +55,8 @@ public static class DirectoryMapping
domainEntity.Name,
domainEntity.DateCreated.Value,
domainEntity.DateModified.Value,
domainEntity.Items.Select(fileSystemItem => fileSystemItem.ToFileSystemItemDto())
.ToList()
[.. domainEntity.Items.Select(fileSystemItem => fileSystemItem.ToFileSystemItemDto())],
domainEntity.IsHidden
);
}
@@ -28,7 +28,8 @@ public static class FileSystemItemMapping
domainEntity.Id.Path,
domainEntity.Name,
DateTime.Now,
DateTime.Now
DateTime.Now,
domainEntity.IsHidden
);
}
@@ -25,6 +25,7 @@ public static class FileMapping
Name = domainEntity.Name,
Path = domainEntity.Id.Path,
ItemType = domainEntity.Type,
IsHidden = domainEntity.IsHidden,
IsExpanded = false,
ChildrenLoaded = false
};
@@ -52,7 +53,8 @@ public static class FileMapping
domainEntity.Name,
domainEntity.DateCreated.HasValue ? domainEntity.DateCreated.Value : default,
domainEntity.DateModified.HasValue ? domainEntity.DateModified.Value : default,
domainEntity.Size
domainEntity.Size,
domainEntity.IsHidden
);
}
@@ -12,10 +12,12 @@ namespace Lumina.Contracts.DTO.FileSystemManagement;
/// <param name="Name">The name of the file system item.</param>
/// <param name="DateCreated">The creation date of the file system item.</param>
/// <param name="DateModified">The modification date of the file system item.</param>
/// <param name="IsHidden">Whether the file system item is hidden.</param>
[DebuggerDisplay("Name: {Name}")]
public record FileSystemItemDto(
string Path,
string Name,
DateTime DateCreated,
DateTime DateModified
DateTime DateModified,
bool IsHidden
);
@@ -27,6 +27,11 @@ public class FileSystemTreeNodeResponse
/// </summary>
public FileSystemItemType ItemType { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the file or directory is hidden.
/// </summary>
public bool IsHidden { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the node is expanded.
/// </summary>
@@ -15,11 +15,13 @@ namespace Lumina.Contracts.Responses.FileSystemManagement.Directories;
/// <param name="DateCreated">The creation date of the directory.</param>
/// <param name="DateModified">The modification date of the directory.</param>
/// <param name="Items">The children items of the directory.</param>
/// <param name="IsHidden">Whether the directory is hidden.</param>
[DebuggerDisplay("Name: {Name} (Directory)")]
public record DirectoryResponse(
string Path,
string Name,
DateTime DateCreated,
DateTime DateModified,
List<FileSystemItemDto> Items
) : FileSystemItemDto(Path, Name, DateCreated, DateModified);
List<FileSystemItemDto> Items,
bool IsHidden
) : FileSystemItemDto(Path, Name, DateCreated, DateModified, IsHidden);
@@ -14,11 +14,13 @@ namespace Lumina.Contracts.Responses.FileSystemManagement.Files;
/// <param name="DateCreated">The creation date of the file.</param>
/// <param name="DateModified">The modification date of the file.</param>
/// <param name="Size">The size of the file, in bytes.</param>
/// <param name="IsHidden">Whether the file is hidden.</param>
[DebuggerDisplay("Name: {Name} (File, Size: {Size} bytes)")]
public record FileResponse(
string Path,
string Name,
DateTime DateCreated,
DateTime DateModified,
long Size
) : FileSystemItemDto(Path, Name, DateCreated, DateModified);
long Size,
bool IsHidden
) : FileSystemItemDto(Path, Name, DateCreated, DateModified, IsHidden);
@@ -53,6 +53,7 @@ public sealed class Directory : FileSystemItem
/// <param name="dateCreated">The date and time the directory was created. Can be optional if unknown.</param>
/// <param name="dateModified">The date and time the directory was last modified. Can be optional if unknown.</param>
/// <param name="status">The status of the file system item.</param>
/// <param name="isHidden">Whether the directory is hidden.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Directory"/>, or an error message.
/// </returns>
@@ -61,9 +62,10 @@ public sealed class Directory : FileSystemItem
string name,
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
FileSystemItemStatus status = FileSystemItemStatus.Accessible,
bool isHidden = false)
{
// TODO: enforce invariants
// TODO: enforce invariants.
Result<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
if (createPathResult.IsFailure)
return createPathResult.Errors;
@@ -75,6 +77,9 @@ public sealed class Directory : FileSystemItem
Result<Updated> setStatusResult = newDirectory.SetStatus(status);
if (setStatusResult.IsFailure)
return setStatusResult.Errors;
Result<Updated> setHiddenStateResult = newDirectory.SetHiddenState(isHidden);
if (setHiddenStateResult.IsFailure)
return setHiddenStateResult.Errors;
return newDirectory;
}
@@ -85,6 +90,7 @@ public sealed class Directory : FileSystemItem
/// <param name="dateCreated">The date and time the directory was created. Can be optional if unknown.</param>
/// <param name="dateModified">The date and time the directory was last modified. Can be optional if unknown.</param>
/// <param name="status">The status of the file system item.</param>
/// <param name="isHidden">Whether the directory is hidden.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="Directory"/>, or an error message.
/// </returns>
@@ -93,9 +99,10 @@ public sealed class Directory : FileSystemItem
string name,
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
FileSystemItemStatus status = FileSystemItemStatus.Accessible,
bool isHidden = false)
{
// TODO: enforce invariants
// TODO: enforce invariants.
Directory newDirectory = new(
id,
name,
@@ -104,6 +111,9 @@ public sealed class Directory : FileSystemItem
Result<Updated> setStatusResult = newDirectory.SetStatus(status);
if (setStatusResult.IsFailure)
return setStatusResult.Errors;
Result<Updated> setHiddenStateResult = newDirectory.SetHiddenState(isHidden);
if (setHiddenStateResult.IsFailure)
return setHiddenStateResult.Errors;
return newDirectory;
}
@@ -54,6 +54,7 @@ public sealed class File : FileSystemItem
/// <param name="dateModified">The date and time the file was last modified. Can be optional if unknown.</param>
/// <param name="size">The size of the file in bytes.</param>
/// <param name="status">The status of the file system item.</param>
/// <param name="isHidden">Whether the file is hidden.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="File"/>, or an error message.
/// </returns>
@@ -63,7 +64,8 @@ public sealed class File : FileSystemItem
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
long size,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
FileSystemItemStatus status = FileSystemItemStatus.Accessible,
bool isHidden = false)
{
// TODO: enforce invariants
Result<FileSystemPathId> createPathResult = FileSystemPathId.Create(path);
@@ -78,6 +80,9 @@ public sealed class File : FileSystemItem
Result<Updated> setStatusResult = newFile.SetStatus(status);
if (setStatusResult.IsFailure)
return setStatusResult.Errors;
Result<Updated> setHiddenStateResult = newFile.SetHiddenState(isHidden);
if (setHiddenStateResult.IsFailure)
return setHiddenStateResult.Errors;
return newFile;
}
@@ -90,6 +95,7 @@ public sealed class File : FileSystemItem
/// <param name="dateModified">The date and time the file was last modified. Can be optional if unknown.</param>
/// <param name="size">The size of the file in bytes.</param>
/// <param name="status">The status of the file system item.</param>
/// <param name="isHidden">Whether the file is hidden.</param>
/// <returns>
/// An <see cref="Result{TValue}"/> containing either a successfully created <see cref="File"/>, or an error message.
/// </returns>
@@ -99,7 +105,8 @@ public sealed class File : FileSystemItem
Optional<DateTime> dateCreated,
Optional<DateTime> dateModified,
long size,
FileSystemItemStatus status = FileSystemItemStatus.Accessible)
FileSystemItemStatus status = FileSystemItemStatus.Accessible,
bool isHidden = false)
{
// TODO: enforce invariants
File newFile = new(
@@ -111,6 +118,9 @@ public sealed class File : FileSystemItem
Result<Updated> setStatusResult = newFile.SetStatus(status);
if (setStatusResult.IsFailure)
return setStatusResult.Errors;
Result<Updated> setHiddenStateResult = newFile.SetHiddenState(isHidden);
if (setHiddenStateResult.IsFailure)
return setHiddenStateResult.Errors;
return newFile;
}
@@ -1,10 +1,9 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Models.Core;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System.Diagnostics;
#endregion
@@ -36,6 +35,11 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
/// </summary>
public FileSystemItemType Type { get; protected set; }
/// <summary>
/// Gets a value indicating whether the file system item is hidden.
/// </summary>
public bool IsHidden { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="FileSystemItem"/> class.
/// </summary>
@@ -49,7 +53,7 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
}
/// <summary>
/// Sets the status of the filesystem item.
/// Sets the status of the file system item.
/// </summary>
/// <param name="status">The status to be set.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
@@ -60,7 +64,18 @@ public abstract class FileSystemItem : AggregateRoot<FileSystemPathId>
}
/// <summary>
/// Sets the parent of the filesystem item.
/// Sets the hidden state of the file system item.
/// </summary>
/// <param name="isHidden">Whether the file system item is hidden.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
public Result<Updated> SetHiddenState(bool isHidden)
{
IsHidden = isHidden;
return Result.Updated;
}
/// <summary>
/// Sets the parent of the file system item.
/// </summary>
/// <param name="parent">The file system item to be set as parent.</param>
/// <returns>An <see cref="Result{TValue}"/> representing either a successful operation, or an error.</returns>
@@ -1,10 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Services;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.IO;
@@ -54,6 +52,19 @@ internal class DirectoryProviderService : IDirectoryProviderService
.AsEnumerable());
}
/// <summary>
/// Checks if the directory at the specified path is hidden.
/// </summary>
/// <param name="path">The path of the directory to check.</param>
/// <returns><see langword="true"/> when the directory is hidden, otherwise <see langword="false"/>, including when its attributes cannot be read.</returns>
public bool IsHidden(FileSystemPathId path)
{
// The hidden flag is metadata, so it follows the same read properties permission as the other metadata accessors.
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false))
return false;
return (GetAttributes(path.Path) & FileAttributes.Hidden) == FileAttributes.Hidden;
}
/// <summary>
/// Gets the attributes of a file system item identified by <paramref name="path"/>.
/// </summary>
@@ -1,12 +1,11 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Environment;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Strategies.Platform;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
#endregion
@@ -76,13 +75,15 @@ public class DirectoryService : IDirectoryService
Result<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(subPath);
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(subPath);
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(subPath);
// When hidden elements are excluded, the provider already filtered them out, so only an inclusive listing needs the attribute.
bool isHidden = shouldIncludeHiddenElements && _environmentContext.DirectoryProviderService.IsHidden(subPath);
// If any error occurred, mark the directory as inaccessible.
if (dirNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
{
Result<Directory> errorDirResult = Directory.Create(subPath, !dirNameResult.IsFailure ? dirNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None());
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), isHidden: isHidden);
if (errorDirResult.IsFailure)
return errorDirResult.Errors;
Result<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -92,7 +93,7 @@ public class DirectoryService : IDirectoryService
}
else
{
Result<Directory> subDirectoryResult = Directory.Create(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
Result<Directory> subDirectoryResult = Directory.Create(subPath, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, isHidden: isHidden);
if (subDirectoryResult.IsFailure)
return subDirectoryResult.Errors;
result.Add(subDirectoryResult.Value);
@@ -141,12 +142,13 @@ public class DirectoryService : IDirectoryService
Result<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
bool isHidden = _environmentContext.DirectoryProviderService.IsHidden(newDirectoryPathResult.Value);
// If any error occurred, mark the directory as inaccessible.
if (dirNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
{
Result<Directory> errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsFailure ? dirNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None());
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), isHidden: isHidden);
if (errorDirResult.IsFailure)
return errorDirResult.Errors;
Result<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -155,7 +157,7 @@ public class DirectoryService : IDirectoryService
return errorDirResult;
}
else
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, isHidden: isHidden);
}
}
@@ -291,12 +293,13 @@ public class DirectoryService : IDirectoryService
Result<string> dirNameResult = _environmentContext.DirectoryProviderService.GetFileName(newDirectoryPathResult.Value);
Result<Optional<DateTime>> dateModifiedResult = _environmentContext.DirectoryProviderService.GetLastWriteTime(newDirectoryPathResult.Value);
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.DirectoryProviderService.GetCreationTime(newDirectoryPathResult.Value);
bool isHidden = _environmentContext.DirectoryProviderService.IsHidden(newDirectoryPathResult.Value);
// If any error occurred, mark the directory as inaccessible.
if (dirNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure)
{
Result<Directory> errorDirResult = Directory.Create(newDirectoryPathResult.Value, !dirNameResult.IsFailure ? dirNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None());
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), isHidden: isHidden);
if (errorDirResult.IsFailure)
return errorDirResult.Errors;
Result<Updated> setStatusResult = errorDirResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -305,7 +308,7 @@ public class DirectoryService : IDirectoryService
return errorDirResult;
}
else
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value);
return Directory.Create(newDirectoryPathResult.Value, dirNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, isHidden: isHidden);
}
}
@@ -1,9 +1,8 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.SharedKernel.Common.Enums.FileSystem;
using System;
using System.Collections.Generic;
using System.IO;
@@ -52,6 +51,19 @@ internal class FileProviderService : IFileProviderService
.AsEnumerable());
}
/// <summary>
/// Checks if the file at the specified path is hidden.
/// </summary>
/// <param name="path">The path of the file to check.</param>
/// <returns><see langword="true"/> when the file is hidden, otherwise <see langword="false"/>, including when its attributes cannot be read.</returns>
public bool IsHidden(FileSystemPathId path)
{
// The hidden flag is metadata, so it follows the same read properties permission as the other metadata accessors.
if (!_fileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties))
return false;
return (GetAttributes(path.Path) & FileAttributes.Hidden) == FileAttributes.Hidden;
}
/// <summary>
/// Gets the attributes of a file system item identified by <paramref name="path"/>.
/// </summary>
@@ -78,12 +78,14 @@ public class FileService : IFileService
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(filePath);
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(filePath);
long size = !sizeResult.IsFailure ? sizeResult.Value ?? 0 : 0;
// When hidden elements are excluded, the provider already filtered them out, so only an inclusive listing needs the attribute.
bool isHidden = shouldIncludeHiddenElements && _environmentContext.FileProviderService.IsHidden(filePath);
// If any of the details returned an error, set the inaccessible status.
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure || sizeResult.IsFailure)
{
Result<File> errorFileResult = File.Create(filePath, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size, isHidden: isHidden);
if (errorFileResult.IsFailure)
return errorFileResult.Errors;
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -93,7 +95,7 @@ public class FileService : IFileService
}
else
{
Result<File> fileResult = File.Create(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
Result<File> fileResult = File.Create(filePath, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size, isHidden: isHidden);
if (fileResult.IsFailure)
return fileResult.Errors;
result.Add(fileResult.Value);
@@ -150,12 +152,13 @@ public class FileService : IFileService
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(copyFileResult.Value);
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(copyFileResult.Value);
long size = !sizeResult.IsFailure ? sizeResult.Value ?? 0 : 0;
bool isHidden = _environmentContext.FileProviderService.IsHidden(copyFileResult.Value);
// If any of the details returned an error, set the inaccessible status.
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure || sizeResult.IsFailure)
{
Result<File> errorFileResult = File.Create(copyFileResult.Value, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size, isHidden: isHidden);
if (errorFileResult.IsFailure)
return errorFileResult.Errors;
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -164,7 +167,7 @@ public class FileService : IFileService
return errorFileResult;
}
else
return File.Create(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
return File.Create(copyFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size, isHidden: isHidden);
}
}
@@ -216,12 +219,13 @@ public class FileService : IFileService
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(moveFileResult.Value);
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(moveFileResult.Value);
long size = !sizeResult.IsFailure ? sizeResult.Value ?? 0 : 0;
bool isHidden = _environmentContext.FileProviderService.IsHidden(moveFileResult.Value);
// If any of the details returned an error, set the inaccessible status.
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure || sizeResult.IsFailure)
{
Result<File> errorFileResult = File.Create(moveFileResult.Value, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size, isHidden: isHidden);
if (errorFileResult.IsFailure)
return errorFileResult.Errors;
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -230,7 +234,7 @@ public class FileService : IFileService
return errorFileResult;
}
else
return File.Create(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
return File.Create(moveFileResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size, isHidden: isHidden);
}
}
@@ -276,12 +280,13 @@ public class FileService : IFileService
Result<Optional<DateTime>> dateCreatedResult = _environmentContext.FileProviderService.GetCreationTime(newFilePathResult.Value);
Result<long?> sizeResult = _environmentContext.FileProviderService.GetSize(newFilePathResult.Value);
long size = !sizeResult.IsFailure ? sizeResult.Value ?? 0 : 0;
bool isHidden = _environmentContext.FileProviderService.IsHidden(newFilePathResult.Value);
// If any of the details returned an error, set the inaccessible status.
if (fileNameResult.IsFailure || dateModifiedResult.IsFailure || dateCreatedResult.IsFailure || sizeResult.IsFailure)
{
Result<File> errorFileResult = File.Create(newFilePathResult.Value, !fileNameResult.IsFailure ? fileNameResult.Value : null!,
!dateCreatedResult.IsFailure ? dateCreatedResult.Value : Optional<DateTime>.None(),
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size);
!dateModifiedResult.IsFailure ? dateModifiedResult.Value : Optional<DateTime>.None(), size, isHidden: isHidden);
if (errorFileResult.IsFailure)
return errorFileResult.Errors;
Result<Updated> setStatusResult = errorFileResult.Value.SetStatus(FileSystemItemStatus.Inaccessible);
@@ -290,7 +295,7 @@ public class FileService : IFileService
return errorFileResult;
}
else
return File.Create(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size);
return File.Create(newFilePathResult.Value, fileNameResult.Value, dateCreatedResult.Value, dateModifiedResult.Value, size, isHidden: isHidden);
}
}
@@ -21,6 +21,13 @@ public interface IDirectoryProviderService
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of directory paths or an error.</returns>
Result<IEnumerable<FileSystemPathId>> GetSubdirectoryPaths(FileSystemPathId path, bool shouldIncludeHiddenElements);
/// <summary>
/// Checks if the directory at the specified path is hidden.
/// </summary>
/// <param name="path">The path of the directory to check.</param>
/// <returns><see langword="true"/> when the directory is hidden, otherwise <see langword="false"/>, including when its attributes cannot be read.</returns>
bool IsHidden(FileSystemPathId path);
/// <summary>
/// Checks if a directory with the specified path exists.
/// </summary>
@@ -21,6 +21,13 @@ public interface IFileProviderService
/// <returns>An <see cref="Result{TValue}"/> containing either a collection of file paths, or an error.</returns>
Result<IEnumerable<FileSystemPathId>> GetFilePaths(FileSystemPathId path, bool shouldIncludeHiddenElements);
/// <summary>
/// Checks if the file at the specified path is hidden.
/// </summary>
/// <param name="path">The path of the file to check.</param>
/// <returns><see langword="true"/> when the file is hidden, otherwise <see langword="false"/>, including when its attributes cannot be read.</returns>
bool IsHidden(FileSystemPathId path);
/// <summary>
/// Retrieves the contents of a file at the specified path.
/// </summary>
@@ -37,8 +37,8 @@ public class GetDirectoriesEndpointSummary : Summary<GetDirectoriesEndpoint, Get
Response(200, "The list of directories for the specified path is returned.",
example: new DirectoryResponse[] {
new(Path: "/media/movies/The Matrix (1999)/", Name: "The Matrix", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Items: []),
new(Path: "/media/movies/The Lord of the Rings - The Fellowship of the Ring (2001)/", Name: "The Lord of the Rings - The Fellowship of the Ring (2001)", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Items: [])
new(Path: "/media/movies/The Matrix (1999)/", Name: "The Matrix", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Items: [], IsHidden: false),
new(Path: "/media/movies/The Lord of the Rings - The Fellowship of the Ring (2001)/", Name: "The Lord of the Rings - The Fellowship of the Ring (2001)", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Items: [], IsHidden: false)
});
Response(401, "Authentication required.", "application/problem+json",
@@ -24,8 +24,8 @@ public class GetDrivesEndpointSummary : Summary<GetDrivesEndpoint, EmptyRequest>
Response(200, "The list of file system drives is returned.",
example: new FileSystemTreeNodeResponse[] {
new() { Path = "C:\\", Name = "C:\\", ItemType = FileSystemItemType.Root, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "D:\\", Name = "D:\\", ItemType = FileSystemItemType.Root, IsExpanded = false, ChildrenLoaded = false, Children = [] }
new() { Path = "C:\\", Name = "C:\\", ItemType = FileSystemItemType.Root, IsHidden = false, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "D:\\", Name = "D:\\", ItemType = FileSystemItemType.Root, IsHidden = false, IsExpanded = false, ChildrenLoaded = false, Children = [] }
});
Response(401, "Authentication required.", "application/problem+json",
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using FastEndpoints;
using Lumina.Contracts.Requests.FileSystemManagement.Files;
using Lumina.Contracts.Responses.FileSystemManagement.Common;
using Lumina.Contracts.Responses.FileSystemManagement.Files;
using System;
using System.Collections.Generic;
@@ -38,8 +37,8 @@ public class GetFilesEndpointSummary : Summary<GetFilesEndpoint, GetFilesRequest
Response(200, "The list of files is returned.",
example: new FileResponse[] {
new(Path: "/media/movies/The Matrix (1999)/The Matrix.mkv", Name: "The Matrix.mkv", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Size: 754045401),
new(Path: "/media/movies/The Matrix (1999)/The Matrix.en.srt", Name: "The Matrix.en.srt", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Size: 6897)
new(Path: "/media/movies/The Matrix (1999)/The Matrix.mkv", Name: "The Matrix.mkv", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Size: 754045401, IsHidden: false),
new(Path: "/media/movies/The Matrix (1999)/The Matrix.en.srt", Name: "The Matrix.en.srt", DateCreated: DateTime.UtcNow, DateModified: DateTime.UtcNow.AddMinutes(-10), Size: 6897, IsHidden: false)
});
Response(401, "Authentication required.", "application/problem+json",
@@ -37,9 +37,9 @@ public class GetTreeFilesEndpointSummary : Summary<GetTreeFilesEndpoint, GetTree
Response(200, "The tree structure of files is returned.",
example: new FileSystemTreeNodeResponse[] {
new() { Path = "/media/movies/The Matrix (1999)/The Matrix.mkv", Name = "The Matrix.mkv", ItemType = FileSystemItemType.File, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "/media/movies/The Matrix (1999)/The Matrix.en.srt", Name = "The Matrix.en.srt", ItemType = FileSystemItemType.File, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "/media/movies/The Matrix (1999)/poster.jpg", Name = "poster.jpg", ItemType = FileSystemItemType.File, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "/media/movies/The Matrix (1999)/The Matrix.mkv", Name = "The Matrix.mkv", ItemType = FileSystemItemType.File, IsHidden = false, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "/media/movies/The Matrix (1999)/The Matrix.en.srt", Name = "The Matrix.en.srt", ItemType = FileSystemItemType.File, IsHidden = false, IsExpanded = false, ChildrenLoaded = false, Children = [] },
new() { Path = "/media/movies/The Matrix (1999)/poster.jpg", Name = "poster.jpg", ItemType = FileSystemItemType.File, IsHidden = false, IsExpanded = false, ChildrenLoaded = false, Children = [] },
});
Response(401, "Authentication required.", "application/problem+json",
@@ -30,4 +30,9 @@ public abstract class FileSystemItemDto
/// Gets or sets the modification date of the file system item.
/// </summary>
public DateTime DateModified { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the file system item is hidden.
/// </summary>
public bool IsHidden { get; set; }
}
@@ -27,6 +27,11 @@ public class FileSystemTreeNodeDto
/// </summary>
public FileSystemItemType ItemType { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the file or directory is hidden.
/// </summary>
public bool IsHidden { get; set; }
/// <summary>
/// Gets or sets a value indicating whether the node is expanded.
/// </summary>
File diff suppressed because it is too large. Load diff
@@ -19,14 +19,16 @@ public class FileSystemItemDtoFixture
/// <summary>
/// Creates a random valid <see cref="FileSystemItemDto"/>.
/// </summary>
/// <param name="isHidden">Optional. Whether the file system item is hidden. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="FileSystemItemDto"/>.</returns>
public FileSystemItemDto Create()
public FileSystemItemDto Create(bool? isHidden = null)
{
return new FileSystemItemDto(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.Date.Past(),
_faker.Date.Recent()
_faker.Date.Recent(),
isHidden ?? _faker.Random.Bool()
);
}
@@ -23,14 +23,16 @@ public class FileSystemTreeNodeResponseFixture
/// <param name="currentDepth">The current depth in the tree structure. Default is 0 (root level).</param>
/// <param name="maxDepth">The maximum depth of the tree structure. Default is 2.</param>
/// <param name="maxChildren">The maximum number of children for each node. Default is 3.</param>
/// <param name="isHidden">Optional. Whether the node is hidden. If not provided, a random value is generated.</param>
/// <returns>A <see cref="FileSystemTreeNodeResponse"/> with a nested structure.</returns>
public FileSystemTreeNodeResponse Create(int currentDepth = 0, int maxDepth = 2, int maxChildren = 3)
public FileSystemTreeNodeResponse Create(int currentDepth = 0, int maxDepth = 2, int maxChildren = 3, bool? isHidden = null)
{
FileSystemTreeNodeResponse response = new()
{
Path = _faker.System.FilePath(),
Name = _faker.System.FileName(),
ItemType = FileSystemItemType.Directory,
IsHidden = isHidden ?? _faker.Random.Bool(),
IsExpanded = _faker.Random.Bool(),
ChildrenLoaded = true,
Children = []
@@ -22,15 +22,17 @@ public class DirectoryResponseFixture
/// Creates a random valid <see cref="DirectoryResponse"/>.
/// </summary>
/// <param name="itemCount">Optional. The number of children elements to create.</param>
/// <param name="isHidden">Optional. Whether the directory is hidden. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="DirectoryResponse"/>.</returns>
public DirectoryResponse Create(int itemCount = 3)
public DirectoryResponse Create(int itemCount = 3, bool? isHidden = null)
{
return new DirectoryResponse(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.Date.Past(),
_faker.Date.Recent(),
_fileSystemItemDtoFixture.CreateMany(itemCount)
_fileSystemItemDtoFixture.CreateMany(itemCount),
isHidden ?? _faker.Random.Bool()
);
}
@@ -19,15 +19,17 @@ public class FileResponseFixture
/// <summary>
/// Creates a random valid <see cref="FileResponse"/>.
/// </summary>
/// <param name="isHidden">Optional. Whether the file is hidden. If not provided, a random value is generated.</param>
/// <returns>The created <see cref="FileResponse"/>.</returns>
public FileResponse Create()
public FileResponse Create(bool? isHidden = null)
{
return new FileResponse(
_faker.System.FilePath(),
_faker.System.FileName(),
_faker.Date.Past(),
_faker.Date.Recent(),
_faker.Random.Long()
_faker.Random.Long(),
isHidden ?? _faker.Random.Bool()
);
}
@@ -28,6 +28,7 @@ public class DirectoryFixture
/// <param name="dateCreated">Optional. The directory's creation date. If not provided, a random past date is generated.</param>
/// <param name="dateModified">Optional. The directory's modification date. If not provided, a recent date is generated.</param>
/// <param name="status">Optional. The directory's status. If not provided, a random status is assigned.</param>
/// <param name="isHidden">Optional. Whether the directory is hidden. If not provided, a random value is generated.</param>
/// <param name="childItems">Optional. A list of child items to be added to the directory.</param>
/// <returns>A newly created <see cref="Directory"/> instance.</returns>
/// <exception cref="InvalidOperationException">Thrown if the <see cref="Directory"/> creation fails.</exception>
@@ -37,6 +38,7 @@ public class DirectoryFixture
Optional<DateTime>? dateCreated = null,
Optional<DateTime>? dateModified = null,
FileSystemItemStatus? status = null,
bool? isHidden = null,
List<FileSystemItem>? childItems = null)
{
path ??= _faker.System.FilePath();
@@ -44,8 +46,9 @@ public class DirectoryFixture
dateCreated ??= Optional<DateTime>.Some(_faker.Date.Past());
dateModified ??= Optional<DateTime>.Some(_faker.Date.Recent());
status ??= _faker.PickRandom<FileSystemItemStatus>();
isHidden ??= _faker.Random.Bool();
Result<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value);
Result<Directory> directoryResult = Directory.Create(path, name, dateCreated.Value, dateModified.Value, status.Value, isHidden.Value);
if (directoryResult.IsFailure)
throw new InvalidOperationException("Failed to create Directory: " + string.Join(", ", directoryResult.Errors));
@@ -28,6 +28,7 @@ public class FileFixture
/// <param name="dateModified">Optional. The file's modification date. If not provided, a recent date is generated.</param>
/// <param name="size">Optional. The file size. If not provided, a random size is generated.</param>
/// <param name="status">Optional. The file's status. If not provided, a random status is assigned.</param>
/// <param name="isHidden">Optional. Whether the file is hidden. If not provided, a random value is generated.</param>
/// <param name="includeDates">Whether the creation and modification dates should be included, or left unset.</param>
/// <returns>The created <see cref="File"/>.</returns>
public File Create(
@@ -37,6 +38,7 @@ public class FileFixture
Optional<DateTime>? dateModified = null,
long? size = null,
FileSystemItemStatus? status = null,
bool? isHidden = null,
bool includeDates = true)
{
path ??= _faker.System.FilePath();
@@ -45,8 +47,9 @@ public class FileFixture
dateModified ??= includeDates ? Optional<DateTime>.Some(_faker.Date.Recent()) : Optional<DateTime>.None();
size ??= _faker.Random.Long();
status ??= _faker.PickRandom<FileSystemItemStatus>();
isHidden ??= _faker.Random.Bool();
Result<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value);
Result<File> fileResult = File.Create(path, name, dateCreated.Value, dateModified.Value, size.Value, status.Value, isHidden.Value);
if (fileResult.IsFailure)
throw new InvalidOperationException("Failed to create File: " + string.Join(", ", fileResult.Errors));
@@ -22,12 +22,14 @@ public class DirectoryDtoFixture
/// </summary>
/// <param name="path">Optional. The full path to the directory.</param>
/// <param name="name">Optional. The name of the directory.</param>
/// <param name="isHidden">Optional. Whether the directory is hidden. If not provided, a random value is generated.</param>
/// <param name="items">Optional. The children items of the directory.</param>
/// <param name="includeItems">Whether the children items should be included, or forced to an empty collection.</param>
/// <returns>The created <see cref="DirectoryDto"/>.</returns>
public DirectoryDto Create(
string? path = null,
string? name = null,
bool? isHidden = null,
List<FileSystemItemDto>? items = null,
bool includeItems = false)
{
@@ -38,6 +40,7 @@ public class DirectoryDtoFixture
Name = name ?? Path.GetFileName(generatedPath),
DateCreated = _faker.Date.Past(),
DateModified = _faker.Date.Recent(),
IsHidden = isHidden ?? _faker.Random.Bool(),
Items = includeItems ? (items ?? []) : []
};
}
@@ -23,11 +23,13 @@ public class FileDtoFixture
/// <param name="path">Optional. The full path to the file.</param>
/// <param name="name">Optional. The name of the file.</param>
/// <param name="size">Optional. The size of the file, in bytes.</param>
/// <param name="isHidden">Optional. Whether the file is hidden. If not provided, a random value is generated.</param>
/// <returns>A configured <see cref="FileDto"/> instance.</returns>
public FileDto Create(
string? path = null,
string? name = null,
long? size = null)
long? size = null,
bool? isHidden = null)
{
string generatedPath = _faker.System.FilePath();
return new FileDto
@@ -36,6 +38,7 @@ public class FileDtoFixture
Name = name ?? Path.GetFileName(generatedPath),
DateCreated = _faker.Date.Past(),
DateModified = _faker.Date.Recent(),
IsHidden = isHidden ?? _faker.Random.Bool(),
Size = size ?? _faker.Random.Long(0, 10_000_000)
};
}
@@ -24,11 +24,13 @@ public class FileSystemTreeNodeDtoFixture
/// <param name="path">Optional. The full path of the file or directory.</param>
/// <param name="name">Optional. The name of the file or directory.</param>
/// <param name="itemType">Optional. The type of the item, indicating whether it is a file, directory, or drive.</param>
/// <param name="isHidden">Optional. Whether the node is hidden. If not provided, a random value is generated.</param>
/// <returns>A configured <see cref="FileSystemTreeNodeDto"/> instance.</returns>
public FileSystemTreeNodeDto Create(
string? path = null,
string? name = null,
FileSystemItemType? itemType = null)
FileSystemItemType? itemType = null,
bool? isHidden = null)
{
string generatedPath = _faker.System.FilePath();
return new FileSystemTreeNodeDto
@@ -36,6 +38,7 @@ public class FileSystemTreeNodeDtoFixture
Path = path ?? generatedPath,
Name = name ?? Path.GetFileName(generatedPath),
ItemType = itemType ?? _faker.PickRandom<FileSystemItemType>(),
IsHidden = isHidden ?? _faker.Random.Bool(),
IsExpanded = _faker.Random.Bool(),
ChildrenLoaded = _faker.Random.Bool(),
Children = []
@@ -58,7 +58,7 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
// Arrange
string testPath = _fileSystemStructureFixture.CreateFileSystemStructure();
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath;
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // two levels to get to the element that has a hidden element as child
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // Two levels to get to the element that has a hidden element as child.
string encodedPath = Uri.EscapeDataString(testPath);
bool shouldIncludeHiddenElements = false;
try
@@ -82,13 +82,13 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
}
}
[Fact]
[SkipWhenHiddenAttributeNotSupportedFact]
public async Task GetDirectories_WhenCalledWithValidPathAndWithShouldIncludeHiddenElements_ShouldReturnDirectoriesWithHiddenElements()
{
// Arrange
string testPath = _fileSystemStructureFixture.CreateFileSystemStructure();
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath;
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // two levels to get to the element that has a hidden element as child
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // Two levels to get to the element that has a hidden element as child.
string encodedPath = Uri.EscapeDataString(testPath);
bool shouldIncludeHiddenElements = true;
try
@@ -112,7 +112,8 @@ public class GetDirectoriesEndpointTests : IClassFixture<AuthenticatedLuminaApiF
DirectoryResponse firstDirectory = directories!.First();
Assert.Equal((s_isUnix ? "." : string.Empty) + "NestedDirectory_2", directories!.First().Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "NestedDirectory_2" + System.IO.Path.DirectorySeparatorChar), directories.First().Path);
Assert.Single(directories); // only directories
Assert.True(firstDirectory.IsHidden);
Assert.Single(directories); // Only directories.
}
finally
{
@@ -80,7 +80,8 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
FileResponse firstDirectory = files!.First();
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.Single(files); // only files
Assert.False(firstDirectory.IsHidden);
Assert.Single(files); // Only files.
}
finally
{
@@ -94,7 +95,7 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
// Arrange
string testPath = _fileSystemStructureFixture.CreateFileSystemStructure();
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath;
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // two levels to get to the element that has a hidden element as child
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // Two levels to get to the element that has a hidden element as child.
bool shouldIncludeHiddenElements = false;
try
{
@@ -112,6 +113,7 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
FileResponse firstDirectory = files!.First();
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.False(firstDirectory.IsHidden);
}
finally
{
@@ -119,13 +121,13 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
}
}
[Fact]
[SkipWhenHiddenAttributeNotSupportedFact]
public async Task GetFiles_WhenCalledWithValidPathAndWithShouldIncludeHiddenElements_ShouldReturnFilesWithHiddenElements()
{
// Arrange
string testPath = _fileSystemStructureFixture.CreateFileSystemStructure();
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath;
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // two levels to get to the element that has a hidden element as child
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // Two levels to get to the element that has a hidden element as child.
bool shouldIncludeHiddenElements = true;
try
{
@@ -147,10 +149,12 @@ public class GetFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFactory
FileResponse firstDirectory = files!.First();
Assert.Equal((s_isUnix ? "." : string.Empty) + "TestFile_1.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"), firstDirectory.Path);
Assert.True(firstDirectory.IsHidden);
FileResponse secondDirectory = files!.Last();
Assert.Equal("TestFile_2.txt", secondDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), secondDirectory.Path);
Assert.False(secondDirectory.IsHidden);
Assert.Equal(2, files.Count);
}
finally
@@ -80,7 +80,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
FileSystemTreeNodeResponse firstDirectory = files!.First();
Assert.Equal("TestFile_2.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), firstDirectory.Path);
Assert.Single(files); // only files
Assert.Single(files); // Only files.
}
finally
{
@@ -94,7 +94,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
// Arrange
string testPath = _fileSystemStructureFixture.CreateFileSystemStructure();
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath;
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // two levels to get to the element that has a hidden element as child
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // Two levels to get to the element that has a hidden element as child.
bool shouldIncludeHiddenElements = false;
try
{
@@ -120,13 +120,13 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
}
}
[Fact]
[SkipWhenHiddenAttributeNotSupportedFact]
public async Task GetTreeFiles_WhenCalledWithValidPathAndWithShouldIncludeHiddenElements_ShouldReturnTreeFilesWithHiddenElements()
{
// Arrange
string testPath = _fileSystemStructureFixture.CreateFileSystemStructure();
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath;
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // two levels to get to the element that has a hidden element as child
testPath = System.IO.Path.GetDirectoryName(testPath) ?? testPath; // Two levels to get to the element that has a hidden element as child.
bool shouldIncludeHiddenElements = true;
try
{
@@ -148,10 +148,12 @@ public class GetTreeFilesEndpointTests : IClassFixture<AuthenticatedLuminaApiFac
FileSystemTreeNodeResponse firstDirectory = files!.First();
Assert.Equal((s_isUnix ? "." : string.Empty) + "TestFile_1.txt", firstDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, (s_isUnix ? "." : string.Empty) + "TestFile_1.txt"), firstDirectory.Path);
Assert.True(firstDirectory.IsHidden);
FileSystemTreeNodeResponse secondDirectory = files!.Last();
Assert.Equal("TestFile_2.txt", secondDirectory.Name);
Assert.Equal(System.IO.Path.Combine(testPath, "TestFile_2.txt"), secondDirectory.Path);
Assert.False(secondDirectory.IsHidden);
Assert.Equal(2, files.Count);
}
finally
@@ -39,7 +39,7 @@ public class GetDirectoriesEndpointTests : IClassFixture<LuminaWebFactory>
// Arrange
_apiFactory.ApiClientStub.Reset();
string path = @"C:\Users\test";
DirectoryDto[] expectedDirectories = [_directoryDtoFixture.Create(path: path, name: "test")];
DirectoryDto[] expectedDirectories = [_directoryDtoFixture.Create(path: path, name: "test", isHidden: true)];
string expectedEndpoint = $"directories/get-directories?path={Uri.EscapeDataString(path)}&shouldIncludeHiddenElements=True";
_apiFactory.ApiClientStub.RegisterGetResponse(expectedEndpoint, expectedDirectories);
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
@@ -56,6 +56,7 @@ public class GetDirectoriesEndpointTests : IClassFixture<LuminaWebFactory>
using JsonDocument json = JsonDocument.Parse(content);
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
Assert.Equal(expectedDirectories.Length, json.RootElement.GetProperty("data").GetArrayLength());
Assert.True(json.RootElement.GetProperty("data")[0].GetProperty("isHidden").GetBoolean());
Assert.Contains(expectedEndpoint, _apiFactory.ApiClientStub.GetEndpointsCalled);
}
}
@@ -39,7 +39,7 @@ public class GetFilesEndpointTests : IClassFixture<LuminaWebFactory>
// Arrange
_apiFactory.ApiClientStub.Reset();
string path = @"C:\Users\test";
FileDto[] expectedFiles = [_fileDtoFixture.Create(path: path, name: "book.pdf")];
FileDto[] expectedFiles = [_fileDtoFixture.Create(path: path, name: "book.pdf", isHidden: true)];
string expectedEndpoint = $"files/get-files?path={Uri.EscapeDataString(path)}&shouldIncludeHiddenElements=True";
_apiFactory.ApiClientStub.RegisterGetResponse(expectedEndpoint, expectedFiles);
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
@@ -56,6 +56,7 @@ public class GetFilesEndpointTests : IClassFixture<LuminaWebFactory>
using JsonDocument json = JsonDocument.Parse(content);
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
Assert.Equal(expectedFiles.Length, json.RootElement.GetProperty("data").GetArrayLength());
Assert.True(json.RootElement.GetProperty("data")[0].GetProperty("isHidden").GetBoolean());
Assert.Contains(expectedEndpoint, _apiFactory.ApiClientStub.GetEndpointsCalled);
}
}
@@ -39,7 +39,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<LuminaWebFactory>
// Arrange
_apiFactory.ApiClientStub.Reset();
string path = @"C:\Users\test";
FileSystemTreeNodeDto[] expectedNodes = [_fileSystemTreeNodeDtoFixture.Create(path: path, name: "test")];
FileSystemTreeNodeDto[] expectedNodes = [_fileSystemTreeNodeDtoFixture.Create(path: path, name: "test", isHidden: true)];
string expectedEndpoint = $"files/get-tree-files?path={Uri.EscapeDataString(path)}&shouldIncludeHiddenElements=True";
_apiFactory.ApiClientStub.RegisterGetResponse(expectedEndpoint, expectedNodes);
AuthenticatedWebClient webClient = await WebTestHelpers.CreateAuthenticatedClientAsync(_apiFactory);
@@ -56,6 +56,7 @@ public class GetTreeFilesEndpointTests : IClassFixture<LuminaWebFactory>
using JsonDocument json = JsonDocument.Parse(content);
Assert.True(json.RootElement.GetProperty("success").GetBoolean());
Assert.Equal(expectedNodes.Length, json.RootElement.GetProperty("data").GetArrayLength());
Assert.True(json.RootElement.GetProperty("data")[0].GetProperty("isHidden").GetBoolean());
Assert.Contains(expectedEndpoint, _apiFactory.ApiClientStub.GetEndpointsCalled);
}
}
@@ -20,15 +20,17 @@ public class DirectoryMappingTests
{
private readonly DirectoryFixture _directoryFixture = new();
[Fact]
public void ToFileSystemTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden directory
[InlineData(false)] // visible directory
public void ToFileSystemTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly(bool isHidden)
{
// Arrange
Directory directory = _directoryFixture.Create();
Directory directory = _directoryFixture.Create(isHidden: isHidden);
List<FileSystemItem> childItems =
[
_directoryFixture.Create(),
_directoryFixture.Create()
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
foreach (FileSystemItem item in childItems)
directory.AddItem(item);
@@ -41,6 +43,7 @@ public class DirectoryMappingTests
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Type, result.ItemType);
Assert.Equal(directory.IsHidden, result.IsHidden);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.NotNull(result.Children);
@@ -51,6 +54,7 @@ public class DirectoryMappingTests
Assert.Equal(childItems[i].Name, result.Children[i].Name);
Assert.Equal(childItems[i].Id.Path, result.Children[i].Path);
Assert.Equal(childItems[i].Type, result.Children[i].ItemType);
Assert.Equal(childItems[i].IsHidden, result.Children[i].IsHidden);
}
}
@@ -58,7 +62,11 @@ public class DirectoryMappingTests
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleDirectories_ShouldMapCorrectly()
{
// Arrange
List<Directory> directories = _directoryFixture.CreateMany(2);
List<Directory> directories =
[
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
// Act
IEnumerable<FileSystemTreeNodeResponse> result = directories.ToFileSystemTreeNodeResponses();
@@ -73,18 +81,21 @@ public class DirectoryMappingTests
Assert.Equal(directories[i].Name, resultList[i].Name);
Assert.Equal(directories[i].Id.Path, resultList[i].Path);
Assert.Equal(directories[i].Type, resultList[i].ItemType);
Assert.Equal(directories[i].IsHidden, resultList[i].IsHidden);
}
}
[Fact]
public void ToResponse_WhenMappingDirectory_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden directory
[InlineData(false)] // visible directory
public void ToResponse_WhenMappingDirectory_ShouldMapCorrectly(bool isHidden)
{
// Arrange
Directory directory = _directoryFixture.Create();
Directory directory = _directoryFixture.Create(isHidden: isHidden);
List<FileSystemItem> childItems =
[
_directoryFixture.Create(),
_directoryFixture.Create()
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
foreach (FileSystemItem item in childItems)
directory.AddItem(item);
@@ -98,6 +109,7 @@ public class DirectoryMappingTests
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.DateCreated.Value, result.DateCreated);
Assert.Equal(directory.DateModified.Value, result.DateModified);
Assert.Equal(directory.IsHidden, result.IsHidden);
Assert.NotNull(result.Items);
Assert.Equal(childItems.Count, result.Items.Count);
@@ -105,6 +117,7 @@ public class DirectoryMappingTests
{
Assert.Equal(childItems[i].Name, result.Items[i].Name);
Assert.Equal(childItems[i].Id.Path, result.Items[i].Path);
Assert.Equal(childItems[i].IsHidden, result.Items[i].IsHidden);
}
}
@@ -112,7 +125,11 @@ public class DirectoryMappingTests
public void ToResponses_WhenMappingMultipleDirectories_ShouldMapCorrectly()
{
// Arrange
List<Directory> directories = _directoryFixture.CreateMany(2);
List<Directory> directories =
[
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
// Act
IEnumerable<DirectoryResponse> result = directories.ToResponses();
@@ -128,6 +145,7 @@ public class DirectoryMappingTests
Assert.Equal(directories[i].Name, resultList[i].Name);
Assert.Equal(directories[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directories[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(directories[i].IsHidden, resultList[i].IsHidden);
}
}
}
@@ -29,17 +29,18 @@ public class FileSystemItemMappingTests
private readonly WindowsRootItemFixture _windowsRootItemFixture = new();
private readonly UnixRootItemFixture _unixRootItemFixture = new();
[Fact]
public void ToFileSystemItemModel_WhenMappingFileSystemItem_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden file system item
[InlineData(false)] // visible file system item
public void ToFileSystemItemModel_WhenMappingFileSystemItem_ShouldMapCorrectly(bool isHidden)
{
// Arrange
FileSystemPathId id = _fileSystemPathIdFixture.Create();
string name = "TestItem";
FileSystemItemType type = FileSystemItemType.File;
FileSystemItemFixture domainModel = new(id, name, type);
domainModel.SetHiddenState(isHidden);
// Arrange
// Act
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
@@ -47,15 +48,18 @@ public class FileSystemItemMappingTests
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.IsHidden, result.IsHidden);
Assert.True((DateTime.Now - result.DateCreated) < TimeSpan.FromSeconds(1));
Assert.True((DateTime.Now - result.DateModified) < TimeSpan.FromSeconds(1));
}
[Fact]
public void ToTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden directory
[InlineData(false)] // visible directory
public void ToTreeNodeResponse_WhenMappingDirectory_ShouldMapCorrectly(bool isHidden)
{
// Arrange
Directory directory = _directoryFixture.Create();
Directory directory = _directoryFixture.Create(isHidden: isHidden);
// Act
FileSystemTreeNodeResponse result = directory.ToTreeNodeResponse();
@@ -65,13 +69,16 @@ public class FileSystemItemMappingTests
Assert.Equal(directory.Name, result.Name);
Assert.Equal(directory.Id.Path, result.Path);
Assert.Equal(directory.Type, result.ItemType);
Assert.Equal(directory.IsHidden, result.IsHidden);
}
[Fact]
public void ToTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden file
[InlineData(false)] // visible file
public void ToTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly(bool isHidden)
{
// Arrange
File file = _fileFixture.Create();
File file = _fileFixture.Create(isHidden: isHidden);
// Act
FileSystemTreeNodeResponse result = file.ToTreeNodeResponse();
@@ -81,6 +88,7 @@ public class FileSystemItemMappingTests
Assert.Equal(file.Name, result.Name);
Assert.Equal(file.Id.Path, result.Path);
Assert.Equal(file.Type, result.ItemType);
Assert.Equal(file.IsHidden, result.IsHidden);
}
[Fact]
@@ -97,6 +105,7 @@ public class FileSystemItemMappingTests
Assert.Equal(windowsRootItem.Name, result.Name);
Assert.Equal(windowsRootItem.Id.Path, result.Path);
Assert.Equal(windowsRootItem.Type, result.ItemType);
Assert.False(result.IsHidden);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
@@ -116,19 +125,21 @@ public class FileSystemItemMappingTests
Assert.Equal(unixRootItem.Name, result.Name);
Assert.Equal(unixRootItem.Id.Path, result.Path);
Assert.Equal(unixRootItem.Type, result.ItemType);
Assert.False(result.IsHidden);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
Assert.Empty(result.Children);
}
[Theory]
[InlineData("TestFile.txt", FileSystemItemType.File)]
[InlineData("TestFolder", FileSystemItemType.Directory)]
public void ToFileSystemItemModel_WhenMappingDifferentFileSystemItems_ShouldMapCorrectly(string name, FileSystemItemType type)
[InlineData("TestFile.txt", FileSystemItemType.File, true)] // hidden file
[InlineData("TestFolder", FileSystemItemType.Directory, false)] // visible directory
public void ToFileSystemItemModel_WhenMappingDifferentFileSystemItems_ShouldMapCorrectly(string name, FileSystemItemType type, bool isHidden)
{
// Arrange
FileSystemPathId id = _fileSystemPathIdFixture.Create();
FileSystemItemFixture domainModel = new(id, name, type);
domainModel.SetHiddenState(isHidden);
// Act
FileSystemItemDto result = domainModel.ToFileSystemItemDto();
@@ -137,6 +148,7 @@ public class FileSystemItemMappingTests
Assert.NotNull(result);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.IsHidden, result.IsHidden);
Assert.True((DateTime.Now - result.DateCreated) < TimeSpan.FromSeconds(1));
Assert.True((DateTime.Now - result.DateModified) < TimeSpan.FromSeconds(1));
}
@@ -147,8 +159,8 @@ public class FileSystemItemMappingTests
// Arrange
List<FileSystemItem> domainModels =
[
_directoryFixture.Create(),
_fileFixture.Create(),
_directoryFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false),
_windowsRootItemFixture.Create(),
_unixRootItemFixture.Create()
];
@@ -166,6 +178,7 @@ public class FileSystemItemMappingTests
Assert.Equal(domainModels[i].Name, resultList[i].Name);
Assert.Equal(domainModels[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModels[i].Type, resultList[i].ItemType);
Assert.Equal(domainModels[i].IsHidden, resultList[i].IsHidden);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
}
@@ -189,7 +202,11 @@ public class FileSystemItemMappingTests
public void ToTreeNodeResponses_WhenMappingMultipleFileSystemItems_ShouldMapCorrectly()
{
// Arrange
IEnumerable<FileSystemItem> domainModels = _directoryFixture.CreateMany();
IEnumerable<FileSystemItem> domainModels =
[
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
// Act
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToTreeNodeResponses();
@@ -205,6 +222,7 @@ public class FileSystemItemMappingTests
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
Assert.Equal(domainModelsList[i].IsHidden, resultList[i].IsHidden);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
@@ -20,11 +20,13 @@ public class FileMappingTests
{
private readonly FileFixture _fileFixture = new();
[Fact]
public void ToFileSystemTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden file
[InlineData(false)] // visible file
public void ToFileSystemTreeNodeResponse_WhenMappingFile_ShouldMapCorrectly(bool isHidden)
{
// Arrange
File domainModel = _fileFixture.Create();
File domainModel = _fileFixture.Create(isHidden: isHidden);
// Act
FileSystemTreeNodeResponse result = domainModel.ToFileSystemTreeNodeResponse();
@@ -34,6 +36,7 @@ public class FileMappingTests
Assert.Equal(domainModel.Name, result.Name);
Assert.Equal(domainModel.Id.Path, result.Path);
Assert.Equal(domainModel.Type, result.ItemType);
Assert.Equal(domainModel.IsHidden, result.IsHidden);
Assert.False(result.IsExpanded);
Assert.False(result.ChildrenLoaded);
}
@@ -42,7 +45,11 @@ public class FileMappingTests
public void ToFileSystemTreeNodeResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
{
// Arrange
IEnumerable<File> domainModels = _fileFixture.CreateMany();
IEnumerable<File> domainModels =
[
_fileFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false)
];
// Act
IEnumerable<FileSystemTreeNodeResponse> result = domainModels.ToFileSystemTreeNodeResponses();
@@ -58,17 +65,20 @@ public class FileMappingTests
Assert.Equal(domainModelsList[i].Name, resultList[i].Name);
Assert.Equal(domainModelsList[i].Id.Path, resultList[i].Path);
Assert.Equal(domainModelsList[i].Type, resultList[i].ItemType);
Assert.Equal(domainModelsList[i].IsHidden, resultList[i].IsHidden);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
}
}
[Fact]
public void ToResponse_WhenMappingFile_ShouldMapCorrectly()
[Theory]
[InlineData(true)] // hidden file
[InlineData(false)] // visible file
public void ToResponse_WhenMappingFile_ShouldMapCorrectly(bool isHidden)
{
// Arrange
File domainModel = _fileFixture.Create();
File domainModel = _fileFixture.Create(isHidden: isHidden);
// Act
FileResponse result = domainModel.ToResponse();
@@ -80,13 +90,18 @@ public class FileMappingTests
Assert.Equal(domainModel.DateCreated.Value, result.DateCreated);
Assert.Equal(domainModel.DateModified.Value, result.DateModified);
Assert.Equal(domainModel.Size, result.Size);
Assert.Equal(domainModel.IsHidden, result.IsHidden);
}
[Fact]
public void ToResponses_WhenMappingMultipleFiles_ShouldMapCorrectly()
{
// Arrange
IEnumerable<File> domainModels = _fileFixture.CreateMany();
IEnumerable<File> domainModels =
[
_fileFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false)
];
// Act
IEnumerable<FileResponse> result = domainModels.ToResponses();
@@ -104,6 +119,7 @@ public class FileMappingTests
Assert.Equal(domainModelsList[i].Size, resultList[i].Size);
Assert.Equal(domainModelsList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(domainModelsList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(domainModelsList[i].IsHidden, resultList[i].IsHidden);
}
}
}
@@ -51,7 +51,11 @@ public class GetDirectoriesQueryHandlerTests
// Arrange
GetDirectoriesQuery getDirectoriesQuery = _getDirectoriesQueryFixture.Create(shouldIncludeHiddenElements: false);
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
IEnumerable<Directory> directories =
[
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements)
.Returns(Result.From(directories));
@@ -73,7 +77,8 @@ public class GetDirectoriesQueryHandlerTests
Assert.Equal(directoriesList[i].Name, resultList[i].Name);
Assert.Equal(directoriesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directoriesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Empty(resultList[i].Items); // since files are not included
Assert.Equal(directoriesList[i].IsHidden, resultList[i].IsHidden);
Assert.Empty(resultList[i].Items); // Since files are not included.
}
_mockDirectoryService.Received(1).GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements);
@@ -85,7 +90,11 @@ public class GetDirectoriesQueryHandlerTests
// Arrange
GetDirectoriesQuery getDirectoriesQuery = _getDirectoriesQueryFixture.Create(shouldIncludeHiddenElements: true);
IEnumerable<Directory> directories = _directoryFixture.CreateMany();
IEnumerable<Directory> directories =
[
_directoryFixture.Create(isHidden: true),
_directoryFixture.Create(isHidden: false)
];
_mockDirectoryService.GetSubdirectories(getDirectoriesQuery.Path!, getDirectoriesQuery.ShouldIncludeHiddenElements)
.Returns(Result.From(directories));
@@ -107,6 +116,7 @@ public class GetDirectoriesQueryHandlerTests
Assert.Equal(directoriesList[i].Name, resultList[i].Name);
Assert.Equal(directoriesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(directoriesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(directoriesList[i].IsHidden, resultList[i].IsHidden);
Assert.Equal(directoriesList[i].Items.Count, resultList[i].Items.Count);
}
@@ -51,7 +51,11 @@ public class GetFilesQueryHandlerTests
// Arrange
GetFilesQuery getFilesQuery = _getFilesQueryFixture.Create(shouldIncludeHiddenElements: false);
IEnumerable<File> files = _fileFixture.CreateMany();
IEnumerable<File> files =
[
_fileFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false)
];
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
.Returns(Result.From(files));
@@ -74,6 +78,7 @@ public class GetFilesQueryHandlerTests
Assert.Equal(filesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(filesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(filesList[i].Size, resultList[i].Size);
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
}
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements);
@@ -85,7 +90,11 @@ public class GetFilesQueryHandlerTests
// Arrange
GetFilesQuery getFilesQuery = _getFilesQueryFixture.Create(shouldIncludeHiddenElements: true);
IEnumerable<File> files = _fileFixture.CreateMany();
IEnumerable<File> files =
[
_fileFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false)
];
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
.Returns(Result.From(files));
@@ -108,6 +117,7 @@ public class GetFilesQueryHandlerTests
Assert.Equal(filesList[i].DateCreated.Value, resultList[i].DateCreated);
Assert.Equal(filesList[i].DateModified.Value, resultList[i].DateModified);
Assert.Equal(filesList[i].Size, resultList[i].Size);
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
}
_mockFileService.Received(1).GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements);
@@ -1,6 +1,4 @@
#region ========================================================================= USING =====================================================================================
using AutoFixture;
using AutoFixture.AutoNSubstitute;
using Lumina.Application.Common.Infrastructure.Validation;
using Lumina.Application.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
using Lumina.Application.Fixtures.Core.FileSystemManagement.Files.Queries.GetTreeFiles;
@@ -26,7 +24,6 @@ namespace Lumina.Application.UnitTests.Core.FileSystemManagement.Files.Queries.G
[ExcludeFromCodeCoverage]
public class GetTreeFilesQueryHandlerTests
{
private readonly IFixture _fixture;
private readonly IFileService _mockFileService;
private readonly GetTreeFilesQueryHandler _sut;
private readonly FileFixture _fileFixture = new();
@@ -37,7 +34,6 @@ public class GetTreeFilesQueryHandlerTests
/// </summary>
public GetTreeFilesQueryHandlerTests()
{
_fixture = new Fixture().Customize(new AutoNSubstituteCustomization());
_mockFileService = Substitute.For<IFileService>();
IValidator<GetTreeFilesQuery> mockValidator = Substitute.For<IValidator<GetTreeFilesQuery>>();
mockValidator.Validate(Arg.Any<GetTreeFilesQuery>())
@@ -51,7 +47,11 @@ public class GetTreeFilesQueryHandlerTests
// Arrange
GetTreeFilesQuery getFilesQuery = _getTreeFilesQueryFixture.Create(shouldIncludeHiddenElements: false);
IEnumerable<File> files = _fileFixture.CreateMany();
IEnumerable<File> files =
[
_fileFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false)
];
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
.Returns(Result.From(files));
@@ -72,6 +72,7 @@ public class GetTreeFilesQueryHandlerTests
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
Assert.Equal(filesList[i].Name, resultList[i].Name);
Assert.Equal(FileSystemItemType.File, resultList[i].ItemType);
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
@@ -86,7 +87,11 @@ public class GetTreeFilesQueryHandlerTests
// Arrange
GetTreeFilesQuery getFilesQuery = _getTreeFilesQueryFixture.Create(shouldIncludeHiddenElements: true);
IEnumerable<File> files = _fileFixture.CreateMany();
IEnumerable<File> files =
[
_fileFixture.Create(isHidden: true),
_fileFixture.Create(isHidden: false)
];
_mockFileService.GetFiles(getFilesQuery.Path!, getFilesQuery.ShouldIncludeHiddenElements)
.Returns(Result.From(files));
@@ -107,6 +112,7 @@ public class GetTreeFilesQueryHandlerTests
Assert.Equal(filesList[i].Id.Path, resultList[i].Path);
Assert.Equal(filesList[i].Name, resultList[i].Name);
Assert.Equal(FileSystemItemType.File, resultList[i].ItemType);
Assert.Equal(filesList[i].IsHidden, resultList[i].IsHidden);
Assert.False(resultList[i].IsExpanded);
Assert.False(resultList[i].ChildrenLoaded);
Assert.Empty(resultList[i].Children);
@@ -1,7 +1,6 @@
#region ========================================================================= USING =====================================================================================
using Lumina.Domain.Common.Errors;
using Lumina.Domain.Common.Primitives;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
using Lumina.Domain.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.ValueObjects;
using Lumina.Domain.Fixtures.Core.BoundedContexts.FileSystemManagementBoundedContext.FileSystemManagementAggregate.Entities;
@@ -42,6 +41,24 @@ public class DirectoryTests
Assert.Equal(dateCreated, result.Value.DateCreated);
Assert.Equal(dateModified, result.Value.DateModified);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
Assert.False(result.Value.IsHidden);
}
[Fact]
public void Create_WhenCalledWithHiddenDirectory_ShouldSetHiddenState()
{
// Arrange
string path = "/valid/path";
string name = "TestDirectory";
Optional<DateTime> dateCreated = DateTime.Now;
Optional<DateTime> dateModified = DateTime.Now;
// Act
Result<Directory> result = Directory.Create(path, name, dateCreated, dateModified, isHidden: true);
// Assert
Assert.False(result.IsFailure);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -42,6 +42,25 @@ public class FileTests
Assert.Equal(dateModified, result.Value.DateModified);
Assert.Equal(size, result.Value.Size);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
Assert.False(result.Value.IsHidden);
}
[Fact]
public void Create_WhenCalledWithHiddenFile_ShouldSetHiddenState()
{
// Arrange
string path = "/valid/path/file.txt";
string name = "file.txt";
Optional<DateTime> dateCreated = DateTime.Now;
Optional<DateTime> dateModified = DateTime.Now;
long size = 1024;
// Act
Result<File> result = File.Create(path, name, dateCreated, dateModified, size, isHidden: true);
// Assert
Assert.False(result.IsFailure);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -46,6 +46,7 @@ public class FileSystemItemTests
Assert.Equal(name, item.Name);
Assert.Equal(type, item.Type);
Assert.Equal(FileSystemItemStatus.Accessible, item.Status);
Assert.False(item.IsHidden);
Assert.Equal(Optional<FileSystemItem>.None(), item.Parent);
}
@@ -65,6 +66,21 @@ public class FileSystemItemTests
Assert.Equal(newStatus, item.Status);
}
[Fact]
public void SetHiddenState_WhenCalled_ShouldUpdateHiddenStateAndReturnUpdated()
{
// Arrange
FileSystemItemFixture item = CreateFileSystemItemFixture();
// Act
Result<Updated> result = item.SetHiddenState(true);
// Assert
Assert.False(result.IsFailure);
Assert.Equal(Result.Updated, result.Value);
Assert.True(item.IsHidden);
}
[Fact]
public void SetParent_WithValidParent_ShouldUpdateParentAndReturnUpdated()
{
@@ -211,6 +211,66 @@ public class DirectoryProviderServiceTests
Assert.Empty(result.Value);
}
[Fact]
public void IsHidden_WhenDirectoryHasHiddenAttribute_ShouldReturnTrue()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathHidden1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false).Returns(true);
_mockFileSystem.File.GetAttributes(path.Path).Returns(FileAttributes.Directory | FileAttributes.Hidden);
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.True(result);
}
[Fact]
public void IsHidden_WhenDirectoryDoesNotHaveHiddenAttribute_ShouldReturnFalse()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathVisible1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false).Returns(true);
_mockFileSystem.File.GetAttributes(path.Path).Returns(FileAttributes.Directory);
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.False(result);
}
[Fact]
public void IsHidden_WhenGetAttributesThrowsException_ShouldReturnFalse()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathInvalid1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false).Returns(true);
_mockFileSystem.File.GetAttributes(path.Path).Throws(new Exception("Access denied"));
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.False(result);
}
[Fact]
public void IsHidden_WhenUserHasNoAccess_ShouldReturnFalseWithoutReadingAttributes()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathHidden1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties, false).Returns(false);
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.False(result);
_mockFileSystem.File.DidNotReceive().GetAttributes(Arg.Any<string>());
}
[Fact]
public void DirectoryExists_WhenDirectoryExists_ShouldReturnTrue()
{
@@ -83,6 +83,37 @@ public class DirectoryServiceTests
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count());
Assert.Equal(["Sub1", "Sub2"], result.Value.Select(d => d.Name));
_mockEnvironmentContext.DirectoryProviderService.DidNotReceive().IsHidden(Arg.Any<FileSystemPathId>());
}
[Fact]
public void GetSubdirectories_WhenDirectoryIsHidden_ShouldReturnDirectoryWithHiddenState()
{
// Arrange
string path = _pathDirTest;
bool shouldIncludeHiddenElements = true;
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path);
FileSystemPathId subPath = _fileSystemPathIdFixture.Create(_pathDirTestSubDir1);
_mockEnvironmentContext.DirectoryProviderService.GetSubdirectoryPaths(pathId, shouldIncludeHiddenElements)
.Returns(Result.From(new[] { subPath }.AsEnumerable()));
_mockEnvironmentContext.DirectoryProviderService.GetFileName(subPath)
.Returns(Result.From(System.IO.Path.GetFileName(subPath.Path)));
_mockEnvironmentContext.DirectoryProviderService.GetLastWriteTime(subPath)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now)));
_mockEnvironmentContext.DirectoryProviderService.GetCreationTime(subPath)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now.AddDays(-1))));
_mockEnvironmentContext.DirectoryProviderService.IsHidden(subPath)
.Returns(true);
// Act
Result<IEnumerable<Directory>> result = _sut.GetSubdirectories(path, shouldIncludeHiddenElements);
// Assert
Assert.False(result.IsFailure);
Directory directory = Assert.Single(result.Value);
Assert.True(directory.IsHidden);
_mockEnvironmentContext.DirectoryProviderService.Received(1).IsHidden(subPath);
}
[Fact]
@@ -124,7 +155,7 @@ public class DirectoryServiceTests
{
// Arrange
string path = _pathDirTest;
bool shouldIncludeHiddenElements = false;
bool shouldIncludeHiddenElements = true;
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path);
FileSystemPathId subPath = _fileSystemPathIdFixture.Create(
s_isUnix ? "/TestDir/InaccessibleSub" : @"C:\TestDir\InaccessibleSub"
@@ -139,6 +170,7 @@ public class DirectoryServiceTests
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.DirectoryProviderService.GetCreationTime(subPath)
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.DirectoryProviderService.IsHidden(subPath).Returns(true);
// Act
Result<IEnumerable<Directory>> result = _sut.GetSubdirectories(path, shouldIncludeHiddenElements);
@@ -147,6 +179,7 @@ public class DirectoryServiceTests
Assert.False(result.IsFailure);
Assert.Single(result.Value);
Assert.Equal(FileSystemItemStatus.Inaccessible, result.Value.First().Status);
Assert.True(result.Value.First().IsHidden);
}
[Fact]
@@ -331,6 +364,7 @@ public class DirectoryServiceTests
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now)));
_mockEnvironmentContext.DirectoryProviderService.GetCreationTime(newDirPathId)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now)));
_mockEnvironmentContext.DirectoryProviderService.IsHidden(newDirPathId).Returns(true);
// Act
Result<Directory> result = _sut.CreateDirectory(parentPath, newDirName);
@@ -338,6 +372,7 @@ public class DirectoryServiceTests
// Assert
Assert.False(result.IsFailure);
Assert.Equal(newDirPathId, result.Value.Id);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -425,6 +460,7 @@ public class DirectoryServiceTests
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.DirectoryProviderService.GetCreationTime(newDirPathId)
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.DirectoryProviderService.IsHidden(newDirPathId).Returns(true);
// Act
Result<Directory> result = _sut.CreateDirectory(parentPathId, newDirName);
@@ -435,6 +471,7 @@ public class DirectoryServiceTests
Assert.Equal(newDirPathId, result.Value.Id);
Assert.False(result.Value.DateCreated.HasValue);
Assert.False(result.Value.DateModified.HasValue);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -493,7 +530,7 @@ public class DirectoryServiceTests
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
// Verify that DirectoryExists was not called
// Verify that DirectoryExists was not called.
_mockEnvironmentContext.DirectoryProviderService.DidNotReceive().DirectoryExists(Arg.Any<FileSystemPathId>());
_mockEnvironmentContext.DirectoryProviderService.DidNotReceive().CreateDirectory(Arg.Any<FileSystemPathId>(), Arg.Any<string>());
}
@@ -664,6 +701,7 @@ public class DirectoryServiceTests
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now)));
_mockEnvironmentContext.DirectoryProviderService.GetCreationTime(newPathId)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now)));
_mockEnvironmentContext.DirectoryProviderService.IsHidden(newPathId).Returns(true);
// Act
Result<Directory> result = _sut.RenameDirectory(oldPath, newName);
@@ -672,6 +710,7 @@ public class DirectoryServiceTests
Assert.False(result.IsFailure);
Assert.Equal(newPathId, result.Value.Id);
Assert.Equal(newName, result.Value.Name);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -772,6 +811,7 @@ public class DirectoryServiceTests
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.DirectoryProviderService.GetCreationTime(newPathId)
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.DirectoryProviderService.IsHidden(newPathId).Returns(true);
// Act
Result<Directory> result = _sut.RenameDirectory(oldPathId, newName);
@@ -780,6 +820,7 @@ public class DirectoryServiceTests
Assert.False(result.IsFailure);
Assert.Equal(FileSystemItemStatus.Inaccessible, result.Value.Status);
Assert.Equal(newPathId, result.Value.Id);
Assert.True(result.Value.IsHidden);
Assert.False(result.Value.DateCreated.HasValue);
Assert.False(result.Value.DateModified.HasValue);
}
@@ -828,7 +869,7 @@ public class DirectoryServiceTests
Assert.True(result.IsFailure);
Assert.Equal(Errors.FileSystemManagement.InvalidPath, result.FirstError);
// Verify that DirectoryExists and RenameDirectory were not called
// Verify that DirectoryExists and RenameDirectory were not called.
_mockEnvironmentContext.DirectoryProviderService.DidNotReceive().DirectoryExists(Arg.Any<FileSystemPathId>());
_mockEnvironmentContext.DirectoryProviderService.DidNotReceive().RenameDirectory(Arg.Any<FileSystemPathId>(), Arg.Any<string>());
}
@@ -857,7 +898,7 @@ public class DirectoryServiceTests
Assert.True(result.IsFailure);
Assert.Equal(Errors.Permission.UnauthorizedAccess, result.FirstError);
// Verify that RenameDirectory was not called
// Verify that RenameDirectory was not called.
_mockEnvironmentContext.DirectoryProviderService.DidNotReceive().RenameDirectory(Arg.Any<FileSystemPathId>(), Arg.Any<string>());
}
@@ -190,6 +190,66 @@ public class FileProviderServiceTests
Assert.Empty(result.Value);
}
[Fact]
public void IsHidden_WhenFileHasHiddenAttribute_ShouldReturnTrue()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathHidden1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
_mockFileSystem.File.GetAttributes(path.Path).Returns(FileAttributes.Hidden);
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.True(result);
}
[Fact]
public void IsHidden_WhenFileDoesNotHaveHiddenAttribute_ShouldReturnFalse()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathVisible1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
_mockFileSystem.File.GetAttributes(path.Path).Returns(FileAttributes.Normal);
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.False(result);
}
[Fact]
public void IsHidden_WhenGetAttributesThrowsException_ShouldReturnFalse()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathInvalid1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(true);
_mockFileSystem.File.GetAttributes(path.Path).Throws(new Exception("Access denied"));
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.False(result);
}
[Fact]
public void IsHidden_WhenUserHasNoAccess_ShouldReturnFalseWithoutReadingAttributes()
{
// Arrange
FileSystemPathId path = _fileSystemPathIdFixture.Create(_pathHidden1);
_mockFileSystemPermissionsService.CanAccessPath(path, FileAccessMode.ReadProperties).Returns(false);
// Act
bool result = _sut.IsHidden(path);
// Assert
Assert.False(result);
_mockFileSystem.File.DidNotReceive().GetAttributes(Arg.Any<string>());
}
[Fact]
public void FileExists_WhenFileExists_ShouldReturnTrue()
{
@@ -94,6 +94,39 @@ public class FileServiceTests
Assert.False(result.IsFailure);
Assert.Equal(2, result.Value.Count());
Assert.Equal(["File1.txt", "File2.txt"], result.Value.Select(f => f.Name));
_mockEnvironmentContext.FileProviderService.DidNotReceive().IsHidden(Arg.Any<FileSystemPathId>());
}
[Fact]
public void GetFiles_WhenFileIsHidden_ShouldReturnFileWithHiddenState()
{
// Arrange
string path = _pathTestDir;
bool shouldIncludeHiddenElements = true;
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path);
FileSystemPathId filePath = _fileSystemPathIdFixture.Create(_pathTestDirFile1);
_mockEnvironmentContext.FileProviderService.GetFilePaths(pathId, shouldIncludeHiddenElements)
.Returns(Result.From(new[] { filePath }.AsEnumerable()));
_mockEnvironmentContext.FileProviderService.GetFileName(filePath)
.Returns(Result.From(System.IO.Path.GetFileName(filePath.Path)));
_mockEnvironmentContext.FileProviderService.GetLastWriteTime(filePath)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now)));
_mockEnvironmentContext.FileProviderService.GetCreationTime(filePath)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now.AddDays(-1))));
_mockEnvironmentContext.FileProviderService.GetSize(filePath)
.Returns(Result.From((long?)1024));
_mockEnvironmentContext.FileProviderService.IsHidden(filePath)
.Returns(true);
// Act
Result<IEnumerable<File>> result = _sut.GetFiles(path, shouldIncludeHiddenElements);
// Assert
Assert.False(result.IsFailure);
File file = Assert.Single(result.Value);
Assert.True(file.IsHidden);
_mockEnvironmentContext.FileProviderService.Received(1).IsHidden(filePath);
}
[Fact]
@@ -135,7 +168,7 @@ public class FileServiceTests
{
// Arrange
string path = _pathTestDir;
bool shouldIncludeHiddenElements = false;
bool shouldIncludeHiddenElements = true;
FileSystemPathId pathId = _fileSystemPathIdFixture.Create(path);
FileSystemPathId filePath = _fileSystemPathIdFixture.Create(_pathTestDirInaccessible);
@@ -150,6 +183,7 @@ public class FileServiceTests
.Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetSize(filePath)
.Returns(Result.From((long?)null));
_mockEnvironmentContext.FileProviderService.IsHidden(filePath).Returns(true);
// Act
Result<IEnumerable<File>> result = _sut.GetFiles(path, shouldIncludeHiddenElements);
@@ -158,6 +192,7 @@ public class FileServiceTests
Assert.False(result.IsFailure);
Assert.Single(result.Value);
Assert.Equal(FileSystemItemStatus.Inaccessible, result.Value.First().Status);
Assert.True(result.Value.First().IsHidden);
}
[Fact]
@@ -378,6 +413,7 @@ public class FileServiceTests
_mockEnvironmentContext.FileProviderService.GetCreationTime(copiedFilePathId)
.Returns(Optional<DateTime>.FromNullable(DateTime.Now.AddDays(-1)));
_mockEnvironmentContext.FileProviderService.GetSize(copiedFilePathId).Returns((long?)1024);
_mockEnvironmentContext.FileProviderService.IsHidden(copiedFilePathId).Returns(true);
// Act
Result<File> result = _sut.CopyFile(sourcePath, destinationPath, overrideExisting);
@@ -387,6 +423,7 @@ public class FileServiceTests
Assert.NotNull(result.Value);
Assert.Equal("file.txt", result.Value.Name);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -451,6 +488,7 @@ public class FileServiceTests
_mockEnvironmentContext.FileProviderService.GetLastWriteTime(copiedFilePathId).Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetCreationTime(copiedFilePathId).Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetSize(copiedFilePathId).Returns(Result.From((long?)null));
_mockEnvironmentContext.FileProviderService.IsHidden(copiedFilePathId).Returns(true);
// Act
Result<File> result = _sut.CopyFile(sourcePath, destinationPath, overrideExisting);
@@ -459,6 +497,7 @@ public class FileServiceTests
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(FileSystemItemStatus.Inaccessible, result.Value.Status);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -681,6 +720,7 @@ public class FileServiceTests
_mockEnvironmentContext.FileProviderService.GetCreationTime(movedFilePathId)
.Returns(Optional<DateTime>.FromNullable(DateTime.Now.AddDays(-1)));
_mockEnvironmentContext.FileProviderService.GetSize(movedFilePathId).Returns((long?)1024);
_mockEnvironmentContext.FileProviderService.IsHidden(movedFilePathId).Returns(true);
// Act
Result<File> result = _sut.MoveFile(sourcePath, destinationPath, overrideExisting);
@@ -690,6 +730,7 @@ public class FileServiceTests
Assert.NotNull(result.Value);
Assert.Equal("file.txt", result.Value.Name);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -757,6 +798,7 @@ public class FileServiceTests
_mockEnvironmentContext.FileProviderService.GetLastWriteTime(movedFilePathId).Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetCreationTime(movedFilePathId).Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetSize(movedFilePathId).Returns(Result.From((long?)null));
_mockEnvironmentContext.FileProviderService.IsHidden(movedFilePathId).Returns(true);
// Act
Result<File> result = _sut.MoveFile(sourcePath, destinationPath, overrideExisting);
@@ -765,6 +807,7 @@ public class FileServiceTests
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(FileSystemItemStatus.Inaccessible, result.Value.Status);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -971,6 +1014,7 @@ public class FileServiceTests
_mockEnvironmentContext.FileProviderService.GetCreationTime(newPathId)
.Returns(Result.From(Optional<DateTime>.FromNullable(DateTime.Now.AddDays(-1))));
_mockEnvironmentContext.FileProviderService.GetSize(newPathId).Returns(Result.From((long?)1024));
_mockEnvironmentContext.FileProviderService.IsHidden(newPathId).Returns(true);
// Act
Result<File> result = _sut.RenameFile(path, newName);
@@ -980,6 +1024,7 @@ public class FileServiceTests
Assert.NotNull(result.Value);
Assert.Equal(newName, result.Value.Name);
Assert.Equal(FileSystemItemStatus.Accessible, result.Value.Status);
Assert.True(result.Value.IsHidden);
}
[Fact]
@@ -1047,6 +1092,7 @@ public class FileServiceTests
_mockEnvironmentContext.FileProviderService.GetLastWriteTime(newPathId).Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetCreationTime(newPathId).Returns(Errors.Permission.UnauthorizedAccess);
_mockEnvironmentContext.FileProviderService.GetSize(newPathId).Returns(Result.From((long?)null));
_mockEnvironmentContext.FileProviderService.IsHidden(newPathId).Returns(true);
// Act
Result<File> result = _sut.RenameFile(path, newName);
@@ -1055,6 +1101,7 @@ public class FileServiceTests
Assert.False(result.IsFailure);
Assert.NotNull(result.Value);
Assert.Equal(FileSystemItemStatus.Inaccessible, result.Value.Status);
Assert.True(result.Value.IsHidden);
}
[Fact]