2022-06-05 18:44:51 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
using MfGames.Nitride.IO.Contents;
|
|
|
|
using MfGames.Nitride.IO.Paths;
|
2022-06-05 18:44: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-05 18:44:51 +00:00
|
|
|
|
|
|
|
public class MoveToIndexPathsTest : NitrideIOTestBase
|
|
|
|
{
|
|
|
|
public MoveToIndexPathsTest(ITestOutputHelper output)
|
|
|
|
: base(output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void MoveAllFiles()
|
|
|
|
{
|
|
|
|
// Set up the test and file system.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
CreateFileSystem(context);
|
|
|
|
|
|
|
|
// Set up the operation.
|
|
|
|
ReadFiles readFiles = context.Resolve<ReadFiles>();
|
|
|
|
MoveToIndexPath op = context.Resolve<MoveToIndexPath>();
|
|
|
|
|
|
|
|
// Read and replace the paths.
|
|
|
|
IOrderedEnumerable<string> output = readFiles.WithPattern("/**")
|
|
|
|
.Run()
|
|
|
|
.Run(op)
|
2022-07-09 04:52:10 +00:00
|
|
|
.Select(
|
|
|
|
x => x.Get<UPath>()
|
|
|
|
.ToString())
|
2022-06-05 18:44:51 +00:00
|
|
|
.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 test and file system.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
CreateFileSystem(context);
|
|
|
|
|
|
|
|
// Set up the operation.
|
|
|
|
ReadFiles readFiles = context.Resolve<ReadFiles>();
|
2022-07-09 04:52:10 +00:00
|
|
|
|
2022-06-05 18:44:51 +00:00
|
|
|
MoveToIndexPath op = context.Resolve<MoveToIndexPath>()
|
2022-07-09 04:52:10 +00:00
|
|
|
.WithCanMoveCallback(
|
|
|
|
path => path.ToString()
|
|
|
|
.Contains("a1"));
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
// Read and replace the paths.
|
|
|
|
IOrderedEnumerable<string> output = readFiles.WithPattern("/**")
|
|
|
|
.Run()
|
|
|
|
.Run(op)
|
2022-07-09 04:52:10 +00:00
|
|
|
.Select(
|
|
|
|
x => x.Get<UPath>()
|
|
|
|
.ToString())
|
2022-06-05 18:44:51 +00:00
|
|
|
.OrderBy(x => x);
|
|
|
|
|
|
|
|
// Verify the results.
|
|
|
|
Assert.Equal(
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
"/a1/index",
|
|
|
|
"/b1.txt",
|
|
|
|
"/c1/index.md",
|
|
|
|
"/d1.html",
|
|
|
|
},
|
|
|
|
output);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void CreateFileSystem(NitrideIOTestContext context)
|
|
|
|
{
|
|
|
|
// Set up the file system.
|
|
|
|
IFileSystem fileSystem = context.FileSystem;
|
|
|
|
|
|
|
|
fileSystem.CreateDirectory("/c1");
|
|
|
|
fileSystem.CreateFile("/a1");
|
|
|
|
fileSystem.CreateFile("/b1.txt");
|
|
|
|
fileSystem.CreateFile("/c1/index.md");
|
|
|
|
fileSystem.CreateFile("/d1.html");
|
|
|
|
}
|
|
|
|
}
|