From 273a5cef2876acf54697df792bd2463f12c9de5b Mon Sep 17 00:00:00 2001 From: Claus Date: Thu, 9 Feb 2017 12:59:13 +0100 Subject: [PATCH] fixed bug in GetFiles with filter param. test for shadow filesystem GetFiles. --- src/Umbraco.Core/IO/ShadowFileSystem.cs | 12 +++---- src/Umbraco.Tests/IO/ShadowFileSystemTests.cs | 31 +++++++++++++++++-- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/IO/ShadowFileSystem.cs b/src/Umbraco.Core/IO/ShadowFileSystem.cs index 1e5da10bdc..ca1de0413c 100644 --- a/src/Umbraco.Core/IO/ShadowFileSystem.cs +++ b/src/Umbraco.Core/IO/ShadowFileSystem.cs @@ -200,10 +200,15 @@ namespace Umbraco.Core.IO } public IEnumerable GetFiles(string path) + { + return GetFiles(path, null); + } + + public IEnumerable GetFiles(string path, string filter) { var normPath = NormPath(path); var shadows = Nodes.Where(kvp => IsChild(normPath, kvp.Key)).ToArray(); - var files = _fs.GetFiles(path); + var files = filter != null ? _fs.GetFiles(path, filter) : _fs.GetFiles(path); return files .Except(shadows.Where(kvp => (kvp.Value.IsFile && kvp.Value.IsDelete) || kvp.Value.IsDir) .Select(kvp => kvp.Key)) @@ -211,11 +216,6 @@ namespace Umbraco.Core.IO .Distinct(); } - public IEnumerable GetFiles(string path, string filter) - { - return _fs.GetFiles(path, filter); - } - public Stream OpenFile(string path) { ShadowNode sf; diff --git a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs index 8e79544052..01ecdd8f04 100644 --- a/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs +++ b/src/Umbraco.Tests/IO/ShadowFileSystemTests.cs @@ -381,7 +381,7 @@ namespace Umbraco.Tests.IO var fs = new PhysicalFileSystem(path, "ignore"); var sw = new ShadowWrapper(fs, "shadow", scopeProvider); - var swa = new[] { sw }; + var swa = new[] {sw}; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f1.txt", ms); @@ -462,7 +462,7 @@ namespace Umbraco.Tests.IO var fs = new PhysicalFileSystem(path, "ignore"); var sw = new ShadowWrapper(fs, "shadow", scopeProvider); - var swa = new[] { sw }; + var swa = new[] {sw}; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f1.txt", ms); @@ -511,7 +511,7 @@ namespace Umbraco.Tests.IO var fs = new PhysicalFileSystem(path, "ignore"); var sw = new ShadowWrapper(fs, "shadow", scopeProvider); - var swa = new[] { sw }; + var swa = new[] {sw}; using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) sw.AddFile("sub/f1.txt", ms); @@ -622,5 +622,30 @@ namespace Umbraco.Tests.IO providerMock.Setup(x => x.AmbientScope).Returns(scopeMock.Object); return providerMock.Object; } + + [Test] + public void ShadowGetFiles() + { + // Arrange + var path = IOHelper.MapPath("FileSysTests"); + Directory.CreateDirectory(path); + Directory.CreateDirectory(path + "/ShadowTests"); + Directory.CreateDirectory(path + "/ShadowSystem"); + + var fs = new PhysicalFileSystem(path + "/ShadowTests/", "ignore"); + var sfs = new PhysicalFileSystem(path + "/ShadowSystem/", "ignore"); + var ss = new ShadowFileSystem(fs, sfs); + + // Act + File.WriteAllText(path + "/ShadowTests/f2.txt", "foo"); + using (var ms = new MemoryStream(Encoding.UTF8.GetBytes("foo"))) + ss.AddFile("f1.txt", ms); + + // Assert + var getFiles = ss.GetFiles(string.Empty); + Assert.AreEqual(2, getFiles.Count()); + var getFilesWithFilter = ss.GetFiles(string.Empty, "*"); + Assert.AreEqual(2, getFilesWithFilter.Count()); + } } }