mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 12:11:10 +00:00
Adds Application layer unit tests for file system browser dialog
This commit is contained in:
1 parent
1f5322fa1d
commit
0e3e688eb7
79 files changed
+5484
-91
No files matched your search
+8
-5
@@ -94,16 +94,19 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
// get the path segments
|
||||
List<string> splitSegments = [.. path.Path.Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries)];
|
||||
IEnumerable<PathSegment> segments = splitSegments.Select((segment, index) =>
|
||||
IEnumerable<ErrorOr<PathSegment>> segmentsResults = splitSegments.Select((segment, index) =>
|
||||
{
|
||||
bool isDirectory;
|
||||
if (segment.Contains('.'))
|
||||
isDirectory = index != splitSegments.Count - 1 || path.Path.EndsWith(PathSeparator); // check if it's the last segment or if the path ends with a '/'
|
||||
else
|
||||
isDirectory = true;
|
||||
return new PathSegment(segment, isDirectory, isDrive: false);
|
||||
}).Prepend(new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true)); // UNIX paths have '/' as "root drive"
|
||||
return ErrorOrFactory.From(segments);
|
||||
return PathSegment.Create(segment, isDirectory, isDrive: false);
|
||||
}).Prepend(PathSegment.Create(PathSeparator.ToString(), isDirectory: false, isDrive: true)); // UNIX paths have '/' as "root drive"
|
||||
foreach (ErrorOr<PathSegment> segment in segmentsResults)
|
||||
if (segment.IsError)
|
||||
return segment.Errors;
|
||||
return ErrorOrFactory.From(segmentsResults.Select(segmentResult => segmentResult.Value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,7 +156,7 @@ public class UnixPathStrategy : IUnixPathStrategy
|
||||
|
||||
// On Unix-like systems, the root is always "/"
|
||||
if (path.Path.StartsWith(PathSeparator))
|
||||
return new PathSegment(PathSeparator.ToString(), isDirectory: false, isDrive: true);
|
||||
return PathSegment.Create(PathSeparator.ToString(), isDirectory: false, isDrive: true);
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
}
|
||||
#endregion
|
||||
|
||||
+11
-6
@@ -4,6 +4,7 @@ using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Core.Aggregates.FileManagement.FileManagementAggregate.ValueObjects;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO.Abstractions;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
@@ -91,11 +92,15 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
// Windows paths usually start with a drive letter and colon, e.g., "C:"
|
||||
if (!path.Path.Contains(':') || !path.Path.Contains(PathSeparator) || !char.IsLetter(path.Path[0]) || path.Path[1] != ':' || path.Path[2] != PathSeparator)
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
return ErrorOrFactory.From(GetPathSegments());
|
||||
IEnumerable<PathSegment> GetPathSegments()
|
||||
IEnumerable<ErrorOr<PathSegment>> getPathSegmentsResults = GetPathSegments();
|
||||
foreach (ErrorOr<PathSegment> getPathSegmentsResult in getPathSegmentsResults)
|
||||
if (getPathSegmentsResult.IsError)
|
||||
return getPathSegmentsResult.Errors;
|
||||
return ErrorOrFactory.From(getPathSegmentsResults.Select(getPathSegmentsResult => getPathSegmentsResult.Value));
|
||||
IEnumerable<ErrorOr<PathSegment>> GetPathSegments()
|
||||
{
|
||||
// the drive segment
|
||||
yield return new PathSegment(path.Path[..2], isDirectory: false, isDrive: true);
|
||||
yield return PathSegment.Create(path.Path[..2], isDirectory: false, isDrive: true);
|
||||
// extract the other segments
|
||||
string[] segments = path.Path[3..].Split(new[] { PathSeparator }, StringSplitOptions.RemoveEmptyEntries);
|
||||
for (int i = 0; i < segments.Length; i++)
|
||||
@@ -106,7 +111,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
isDirectory = i != segments.Length - 1 || path.Path.EndsWith(PathSeparator); // check if it's the last segment or if the next segment also contains a path delimiter
|
||||
else
|
||||
isDirectory = true;
|
||||
yield return new PathSegment(segment, isDirectory, isDrive: false);
|
||||
yield return PathSegment.Create(segment, isDirectory, isDrive: false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -164,7 +169,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
string root = path.Path[..2];
|
||||
if (path.Path.Length > 2 && path.Path[2] == PathSeparator)
|
||||
root += PathSeparator;
|
||||
return new PathSegment(root, isDirectory: true, isDrive: true);
|
||||
return PathSegment.Create(root, isDirectory: true, isDrive: true);
|
||||
}
|
||||
// check for UNC paths (e.g., "\\server\share")
|
||||
if (path.Path.StartsWith('\\'))
|
||||
@@ -177,7 +182,7 @@ public class WindowsPathStrategy : IWindowsPathStrategy
|
||||
if (segments.Count >= 2)
|
||||
{
|
||||
string root = $@"\\{segments[0].Name}\{segments[1].Name}\";
|
||||
return new PathSegment(root, isDirectory: true, isDrive: false);
|
||||
return PathSegment.Create(root, isDirectory: true, isDrive: false);
|
||||
}
|
||||
}
|
||||
return Errors.FileManagement.InvalidPath;
|
||||
|
||||
+21
-3
@@ -1,4 +1,6 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Lumina.Domain.Common.Models.Core;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
@@ -36,7 +38,7 @@ public class PathSegment : ValueObject
|
||||
/// <param name="name">The name of the path segment.</param>
|
||||
/// <param name="isDirectory">Value indicating if the current path segment is a file system directory or not.</param>
|
||||
/// <param name="isDrive">Value indicating if the current path segment is a file system drive or not.</param>
|
||||
public PathSegment(string name, bool isDirectory, bool isDrive)
|
||||
private PathSegment(string name, bool isDirectory, bool isDrive)
|
||||
{
|
||||
Name = name;
|
||||
IsDirectory = isDirectory;
|
||||
@@ -45,6 +47,22 @@ public class PathSegment : ValueObject
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="PathSegment"/> class.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the path segment.</param>
|
||||
/// <param name="isDirectory">Value indicating if the current path segment is a file system directory or not.</param>
|
||||
/// <param name="isDrive">Value indicating if the current path segment is a file system drive or not.</param>
|
||||
/// <returns>
|
||||
/// An <see cref="ErrorOr{TValue}"/> containing either a successfully created <see cref="PathSegment"/> or an error message.
|
||||
/// </returns>
|
||||
public static ErrorOr<PathSegment> Create(string name, bool isDirectory, bool isDrive)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
return Errors.FileManagement.NameCannotBeEmpty;
|
||||
return new PathSegment(name, isDirectory, isDrive);
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override IEnumerable<object> GetEqualityComponents()
|
||||
{
|
||||
@@ -53,4 +71,4 @@ public class PathSegment : ValueObject
|
||||
yield return IsDrive;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user