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/Nitride.IO.Tests/MoveToIndexPathsTests.cs

81 lines
2.3 KiB
C#
Raw Normal View History

2021-09-07 05:15:45 +00:00
using System.Linq;
using Autofac;
using Nitride.IO.Contents;
using Nitride.IO.Paths;
using Xunit;
using Xunit.Abstractions;
using Zio;
using Zio.FileSystems;
namespace Nitride.IO.Tests
{
public class MoveToIndexPathsTests : NitrideIOTestsBase
{
private readonly MemoryFileSystem fileSystem;
public MoveToIndexPathsTests(ITestOutputHelper output)
: base(output)
{
this.fileSystem = new MemoryFileSystem();
this.fileSystem.CreateDirectory("/c1");
this.fileSystem.CreateFile("/a1");
this.fileSystem.CreateFile("/b1.txt");
this.fileSystem.CreateFile("/c1/index.md");
this.fileSystem.CreateFile("/d1.html");
}
[Fact]
public void MoveAllFiles()
{
// Set up the operation.
var readFiles = this.Container.Resolve<ReadFiles.Factory>();
var op = new MoveToIndexPaths();
// Read and replace the paths.
IOrderedEnumerable<string> output = readFiles(this.fileSystem)
.Read()
.Run(op)
.Select(x => x.Get<UPath>().ToString())
.OrderBy(x => x);
// Verify the results.
Assert.Equal(
new[]
{
"/a1",
"/b1.txt",
"/c1/index.md",
"/d1/index.html",
},
output);
}
[Fact]
public void OverrideCanMoveCallback()
{
// Set up the operation.
var readFiles = this.Container.Resolve<ReadFiles.Factory>();
MoveToIndexPaths? op = new MoveToIndexPaths()
.WithCanMoveCallback((path) => path.ToString().Contains("a1"));
// Read and replace the paths.
IOrderedEnumerable<string> output = readFiles(this.fileSystem)
.Read()
.Run(op)
.Select(x => x.Get<UPath>().ToString())
.OrderBy(x => x);
// Verify the results.
Assert.Equal(
new[]
{
"/a1/index",
"/b1.txt",
"/c1/index.md",
"/d1.html",
},
output);
}
}
}