using System.Linq; using Autofac; using Nitride.IO.Contents; using Xunit; using Xunit.Abstractions; using Zio; using Zio.FileSystems; namespace Nitride.IO.Tests { /// /// Tests the functionality of the ReadFiles(). /// 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 op = factory(this.fileSystem); // Verify the paths. IOrderedEnumerable paths = op.Read() .Select(x => x.Get()) .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 op = factory(this.fileSystem); // Verify the paths. IOrderedEnumerable paths = op.Read("/*.txt") .Select(x => (string)x.Get()) .OrderBy(x => x); Assert.Equal( new[] { "/a.txt", }, paths); } [Fact] public void ReadGlobWithSubdirectories() { // Set up the operation. var factory = this.Container.Resolve(); ReadFiles op = factory(this.fileSystem); // Verify the paths. IOrderedEnumerable paths = op.Read("**/*.txt") .Select(x => (string)x.Get()) .OrderBy(x => x); Assert.Equal( new[] { "/a.txt", "/c1/c.txt", }, paths); } } }