using System; using System.Linq; using Nitride.Entities; using Nitride.IO.Contents; using Nitride.IO.Paths; using Nitride.Tests; using Xunit; using Xunit.Abstractions; using Zio; namespace Nitride.IO.Tests; 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(); DirectChildPathScanner scanner = context.Resolve(); CreateOrUpdateIndex op = context.Resolve().WithScanner(scanner); // Read and replace the paths. Tuple[]? actual = readFiles.WithPattern("/**") .Run() .Run(scanner) .ToList() .Run(op) .Select( x => new Tuple( x.Get().ToString(), x.GetOptional() ?.Select(y => y.Get().ToString()) .OrderBy(y => y) .ToArray())) .OrderBy(x => x.Item1) .ToArray(); // Verify the results. Tuple[] expected = new[] { new Tuple("/a/c/index.md", new string[] { }), new Tuple("/a/d/e/index.md", new string[] { }), new Tuple("/a/d/index.md", new[] { "/a/d/e/index.md" }), new Tuple("/a/index.md", new[] { "/a/c/index.md", "/a/d/index.md" }), new Tuple("/b/index.md", new string[] { }), new Tuple("/index.md", new[] { "/a/index.md", "/b/index.md" }), }; TestHelper.CompareObjects(expected, actual); } }