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/ReadFilesTests.cs

98 lines
2.8 KiB
C#
Raw Normal View History

2021-09-07 05:15:45 +00:00
using System.Linq;
using Autofac;
using Nitride.IO.Contents;
using Xunit;
using Xunit.Abstractions;
using Zio;
using Zio.FileSystems;
namespace Nitride.IO.Tests
{
/// <summary>
/// Tests the functionality of the ReadFiles().
/// </summary>
public class ReadFilesTests : NitrideIOTestsBase
{
private readonly MemoryFileSystem fileSystem;
public ReadFilesTests(ITestOutputHelper output)
: base(output)
{
this.fileSystem = new MemoryFileSystem();
this.fileSystem.CreateDirectory("/b1");
this.fileSystem.CreateDirectory("/c1");
this.fileSystem.CreateDirectory("/c1/c2");
this.fileSystem.CreateDirectory("/d1");
this.fileSystem.WriteAllText("/a.txt", "File A");
this.fileSystem.WriteAllText("/b1/b.md", "File B");
this.fileSystem.WriteAllText("/c1/c.txt", "File C");
this.fileSystem.WriteAllText("/c1/c2/e.md", "File C");
}
[Fact]
public void ReadAllFiles()
{
// Set up the operation.
var factory = this.Container.Resolve<ReadFiles.Factory>();
ReadFiles op = factory(this.fileSystem);
// Verify the paths.
IOrderedEnumerable<string> paths = op.Read()
.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 operation.
var factory = this.Container.Resolve<ReadFiles.Factory>();
ReadFiles op = factory(this.fileSystem);
// Verify the paths.
IOrderedEnumerable<string> paths = op.Read("/*.txt")
.Select(x => (string)x.Get<UPath>())
.OrderBy(x => x);
Assert.Equal(
new[]
{
"/a.txt",
},
paths);
}
[Fact]
public void ReadGlobWithSubdirectories()
{
// Set up the operation.
var factory = this.Container.Resolve<ReadFiles.Factory>();
ReadFiles op = factory(this.fileSystem);
// Verify the paths.
IOrderedEnumerable<string> paths = op.Read("**/*.txt")
.Select(x => (string)x.Get<UPath>())
.OrderBy(x => x);
Assert.Equal(
new[]
{
"/a.txt",
"/c1/c.txt",
},
paths);
}
}
}