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