2022-06-05 18:44:51 +00:00
|
|
|
using System.Linq;
|
|
|
|
|
2022-09-06 05:53:22 +00:00
|
|
|
using MfGames.Nitride.IO.Contents;
|
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
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Tests the functionality of the ReadFiles().
|
|
|
|
/// </summary>
|
|
|
|
public class ReadFilesTest : NitrideIOTestBase
|
|
|
|
{
|
|
|
|
public ReadFilesTest(ITestOutputHelper output)
|
|
|
|
: base(output)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReadAllFiles()
|
|
|
|
{
|
|
|
|
// Set up the test and file system.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
CreateFileSystem(context);
|
|
|
|
|
|
|
|
// Set up the operation.
|
|
|
|
ReadFiles op = context.Resolve<ReadFiles>();
|
|
|
|
|
|
|
|
// Verify the paths.
|
|
|
|
IOrderedEnumerable<string> paths = op.WithPattern("/**")
|
|
|
|
.Run()
|
|
|
|
.Select(x => x.Get<UPath>())
|
|
|
|
.Select(x => (string)x)
|
|
|
|
.OrderBy(x => x);
|
|
|
|
|
|
|
|
Assert.Equal(
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
"/a.txt",
|
|
|
|
"/b1/b.md",
|
|
|
|
"/c1/c.txt",
|
|
|
|
"/c1/c2/e.md",
|
|
|
|
},
|
|
|
|
paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReadGlob()
|
|
|
|
{
|
|
|
|
// Set up the test and file system.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
CreateFileSystem(context);
|
|
|
|
|
|
|
|
// Set up the operation.
|
2022-07-09 04:52:10 +00:00
|
|
|
ReadFiles op = context.Resolve<ReadFiles>()
|
|
|
|
.WithPattern("/*.txt");
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
// Verify the paths.
|
2022-07-09 04:52:10 +00:00
|
|
|
IOrderedEnumerable<string> paths = op.Run()
|
|
|
|
.Select(x => (string)x.Get<UPath>())
|
|
|
|
.OrderBy(x => x);
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
Assert.Equal(
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
"/a.txt",
|
|
|
|
},
|
|
|
|
paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ReadGlobWithSubdirectories()
|
|
|
|
{
|
|
|
|
// Set up the test and file system.
|
|
|
|
using NitrideIOTestContext context = this.CreateContext();
|
|
|
|
|
|
|
|
CreateFileSystem(context);
|
|
|
|
|
|
|
|
// Set up the operation.
|
2022-07-09 04:52:10 +00:00
|
|
|
ReadFiles op = context.Resolve<ReadFiles>()
|
|
|
|
.WithPattern("**/*.txt");
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
// Verify the paths.
|
2022-07-09 04:52:10 +00:00
|
|
|
IOrderedEnumerable<string> paths = op.Run()
|
|
|
|
.Select(x => (string)x.Get<UPath>())
|
|
|
|
.OrderBy(x => x);
|
2022-06-05 18:44:51 +00:00
|
|
|
|
|
|
|
Assert.Equal(
|
|
|
|
new[]
|
|
|
|
{
|
|
|
|
"/a.txt",
|
|
|
|
"/c1/c.txt",
|
|
|
|
},
|
|
|
|
paths);
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void CreateFileSystem(NitrideIOTestContext context)
|
|
|
|
{
|
|
|
|
IFileSystem fileSystem = context.FileSystem;
|
|
|
|
|
|
|
|
fileSystem.CreateDirectory("/b1");
|
|
|
|
fileSystem.CreateDirectory("/c1");
|
|
|
|
fileSystem.CreateDirectory("/c1/c2");
|
|
|
|
fileSystem.CreateDirectory("/d1");
|
|
|
|
fileSystem.WriteAllText("/a.txt", "File A");
|
|
|
|
fileSystem.WriteAllText("/b1/b.md", "File B");
|
|
|
|
fileSystem.WriteAllText("/c1/c.txt", "File C");
|
|
|
|
fileSystem.WriteAllText("/c1/c2/e.md", "File C");
|
|
|
|
}
|
|
|
|
}
|