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

@@ -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]