Adds hidden elements option to file system browser directories and paths

This commit is contained in:
BinaryAlley committed 2024-10-11 20:37:43 +03:00
1 parent 15a1881495
commit b3db46ed5f
18 files changed
+217 -59

No files matched your search

@@ -196,10 +196,10 @@ public class GetDirectoryTreeQueryHandlerTests
IEnumerable<PathSegment> pathSegments = new[] { firstPathSegment }.Concat(_pathSegmentFixture.CreateMany(2));
Error error = Error.Failure("PathService.Error", "An error occurred");
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From(pathSegments));
_mockPathService.CombinePath(Arg.Any<string>(), Arg.Any<string>()).Returns(error);
// Act
ErrorOr<IEnumerable<FileSystemTreeNodeResponse>> result = await _sut.Handle(query, CancellationToken.None);
@@ -313,6 +313,7 @@ public class GetDirectoryTreeQueryHandlerTests
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)pathSegments));
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(true);
_mockPathService.CombinePath(Arg.Any<string>(), Arg.Any<string>())
.Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
@@ -350,6 +351,7 @@ public class GetDirectoryTreeQueryHandlerTests
];
_mockDriveService.GetDrives().Returns(ErrorOrFactory.From(drives));
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(true);
_mockPathService.ParsePath(query.Path).Returns(ErrorOrFactory.From((IEnumerable<PathSegment>)pathSegments));
_mockPathService.CombinePath(Arg.Any<string>(), Arg.Any<string>())
.Returns(callInfo => $"{callInfo.ArgAt<string>(0)}\\{callInfo.ArgAt<string>(1)}");
@@ -36,7 +36,7 @@ public class CheckPathExistsQueryHandlerTests
#region ===================================================================== METHODS ===================================================================================
[Fact]
public async Task Handle_WhenPathExists_ShouldReturnTrueResponse()
public async Task Handle_WhenPathExistsAndIsNotHidden_ShouldReturnTrueResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery();
@@ -50,6 +50,36 @@ public class CheckPathExistsQueryHandlerTests
_mockPathService.Received(1).Exists(query.Path);
}
[Fact]
public async Task Handle_WhenPathExistsAndIsHiddenAndIncludeHiddenElementsIsTrue_ShouldReturnTrueResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery(true);
_mockPathService.Exists(query.Path).Returns(true);
// Act
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Exists.Should().BeTrue();
_mockPathService.Received(1).Exists(query.Path);
}
[Fact]
public async Task Handle_WhenPathExistsAndIsHiddenAndIncludeHiddenElementsIsFalse_ShouldReturnFalseResponse()
{
// Arrange
CheckPathExistsQuery query = CheckPathExistsQueryFixture.CreateCheckPathExistsQuery(false);
_mockPathService.Exists(query.Path, false).Returns(false);
// Act
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Exists.Should().BeFalse();
_mockPathService.Received(1).Exists(query.Path, false);
}
[Fact]
public async Task Handle_WhenPathDoesNotExist_ShouldReturnFalseResponse()
{
@@ -69,15 +99,15 @@ public class CheckPathExistsQueryHandlerTests
public async Task Handle_WhenCalledWithNullPath_ShouldStillCallPathService()
{
// Arrange
CheckPathExistsQuery query = new(null!);
_mockPathService.Exists(Arg.Any<string>()).Returns(false);
CheckPathExistsQuery query = new(null!, false);
_mockPathService.Exists(Arg.Any<string>(), Arg.Any<bool>()).Returns(false);
// Act
PathExistsResponse result = await _sut.Handle(query, CancellationToken.None);
// Assert
result.Exists.Should().BeFalse();
_mockPathService.Received(1).Exists(Arg.Any<string>());
_mockPathService.Received(1).Exists(Arg.Any<string>(), Arg.Any<bool>());
}
[Fact]
@@ -16,14 +16,17 @@ public class CheckPathExistsQueryFixture
/// <summary>
/// Creates a random valid query to check if paths exist.
/// </summary>
/// <param name="includeHiddenElements">Whether to include hidden file system elements or not.</param>
/// <returns>The created query.</returns>
public static CheckPathExistsQuery CreateCheckPathExistsQuery()
public static CheckPathExistsQuery CreateCheckPathExistsQuery(bool includeHiddenElements = true)
{
return new Faker<CheckPathExistsQuery>()
.CustomInstantiator(f => new CheckPathExistsQuery(
default!
default!,
default
))
.RuleFor(x => x.Path, f => f.System.FilePath());
.RuleFor(x => x.Path, f => f.System.FilePath())
.RuleFor(x => x.IncludeHiddenElements, includeHiddenElements);
}
#endregion
}