fixed bug in GetFiles with filter param.

test for shadow filesystem GetFiles.
This commit is contained in:
Claus
2017-02-09 12:59:13 +01:00
parent 57945fcec6
commit 273a5cef28
2 changed files with 34 additions and 9 deletions
+6 -6
View File
@@ -200,10 +200,15 @@ namespace Umbraco.Core.IO
}
public IEnumerable<string> GetFiles(string path)
{
return GetFiles(path, null);
}
public IEnumerable<string> 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<string> GetFiles(string path, string filter)
{
return _fs.GetFiles(path, filter);
}
public Stream OpenFile(string path)
{
ShadowNode sf;
+28 -3
View File
@@ -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());
}
}
}