This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/tests/MfGames.Nitride.IO.Tests/Paths/LinkDirectChildrenTests.cs

92 lines
2.9 KiB
C#
Raw Normal View History

using System;
using System.Linq;
2022-09-06 05:53:22 +00:00
using MfGames.Nitride.Entities;
using MfGames.Nitride.IO.Contents;
using MfGames.Nitride.IO.Paths;
using MfGames.Nitride.Tests;
using Xunit;
using Xunit.Abstractions;
using Zio;
namespace MfGames.Nitride.IO.Tests.Paths;
public class LinkDirectChildrenTests : NitrideIOTestBase
{
public LinkDirectChildrenTests(ITestOutputHelper output)
: base(output)
{
}
[Fact]
public void NestedLinkTest()
{
// 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 scanner =
context.Resolve<DirectChildPathScanner>();
2022-07-09 04:52:10 +00:00
CreateOrUpdateIndex op = context.Resolve<LinkDirectChildren>()
.WithScanner(scanner);
// Read and replace the paths.
Tuple<string, string[]?>[]? actual = NitrideOperationExtensions.Run(
readFiles.WithPattern("/**")
.Run(),
scanner)
.ToList()
.Run(op)
.Select(
x => new Tuple<string, string[]?>(
2022-07-09 04:52:10 +00:00
x.Get<UPath>()
.ToString(),
x.GetOptional<DirectChildEntityList>()
2022-07-09 04:52:10 +00:00
?.Select(
y => y.Get<UPath>()
.ToString())
.OrderBy(y => y)
.ToArray()))
.OrderBy(x => x.Item1)
.ToArray();
// Verify the results.
Tuple<string, string[]?>[] expected = new[]
{
new Tuple<string, string[]?>("/a/c/index.md", new string[] { }),
new Tuple<string, string[]?>("/a/d/e/index.md", new string[] { }),
new Tuple<string, string[]?>(
"/a/d/index.md",
new[] { "/a/d/e/index.md" }),
new Tuple<string, string[]?>(
"/a/index.md",
new[] { "/a/c/index.md", "/a/d/index.md" }),
new Tuple<string, string[]?>("/b/index.md", new string[] { }),
new Tuple<string, string[]?>(
"/index.md",
new[] { "/a/index.md", "/b/index.md" }),
};
TestHelper.CompareObjects(expected, actual);
}
}