2022-06-26 18:50:51 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
using MfGames.Nitride.IO.Contents;
|
|
|
|
using MfGames.Nitride.IO.Paths;
|
|
|
|
using MfGames.Nitride.Tests;
|
2022-06-26 18:50:51 +00:00
|
|
|
|
|
|
|
using Xunit;
|
|
|
|
using Xunit.Abstractions;
|
|
|
|
|
|
|
|
using Zio;
|
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
namespace MfGames.Nitride.IO.Tests;
|
2022-06-26 18:50:51 +00:00
|
|
|
|
|
|
|
public class DirectChildPathScannerTests : NitrideIOTestBase
|
|
|
|
{
|
|
|
|
public DirectChildPathScannerTests(ITestOutputHelper output)
|
|
|
|
: base(output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void NestedFoldersTests()
|
|
|
|
{
|
|
|
|
// Set up the test.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
// Set up the file.
|
|
|
|
IFileSystem fileSystem = context.FileSystem;
|
|
|
|
|
|
|
|
fileSystem.CreateDirectory("/a");
|
|
|
|
fileSystem.CreateDirectory("/b");
|
|
|
|
fileSystem.CreateDirectory("/a/c");
|
|
|
|
fileSystem.CreateDirectory("/a/d");
|
|
|
|
fileSystem.CreateDirectory("/a/d/e");
|
|
|
|
fileSystem.CreateFile("/index.md");
|
|
|
|
fileSystem.CreateFile("/a/index.md");
|
|
|
|
fileSystem.CreateFile("/b/index.md");
|
|
|
|
fileSystem.CreateFile("/a/c/index.md");
|
|
|
|
fileSystem.CreateFile("/a/d/index.md");
|
|
|
|
fileSystem.CreateFile("/a/d/e/index.md");
|
|
|
|
|
|
|
|
// Set up the operation.
|
|
|
|
ReadFiles readFiles = context.Resolve<ReadFiles>();
|
|
|
|
DirectChildPathScanner op = context.Resolve<DirectChildPathScanner>();
|
|
|
|
|
|
|
|
// Read and replace the paths.
|
2022-07-09 04:52:10 +00:00
|
|
|
var _ = readFiles.WithPattern("/**")
|
|
|
|
.Run()
|
|
|
|
.Run(op)
|
|
|
|
.ToList();
|
|
|
|
|
2022-06-26 18:50:51 +00:00
|
|
|
KeyValuePair<string, string[]>[] actual = op.GetScannedResults()
|
2022-07-09 04:52:10 +00:00
|
|
|
.ToDictionary(
|
|
|
|
x => x.Key,
|
|
|
|
x => x.Value.Select(
|
|
|
|
y => y.Get<UPath>()
|
|
|
|
.ToString())
|
|
|
|
.ToArray())
|
2022-06-26 18:50:51 +00:00
|
|
|
.ToList()
|
|
|
|
.OrderBy(x => x.Key)
|
|
|
|
.ToArray();
|
|
|
|
|
|
|
|
// Verify the results.
|
|
|
|
KeyValuePair<string, string[]>[] expected = new[]
|
|
|
|
{
|
|
|
|
new KeyValuePair<string, string[]>("/", new[] { "/a/index.md", "/b/index.md" }),
|
|
|
|
new KeyValuePair<string, string[]>("/a/", new[] { "/a/c/index.md", "/a/d/index.md" }),
|
|
|
|
new KeyValuePair<string, string[]>("/a/d/", new[] { "/a/d/e/index.md" }),
|
|
|
|
};
|
|
|
|
|
2022-06-28 04:38:50 +00:00
|
|
|
TestHelper.CompareObjects(expected, actual);
|
2022-06-26 18:50:51 +00:00
|
|
|
}
|
|
|
|
}
|