Simplifying path recursion, adding PathUtils test stubs

This commit is contained in:
Chris Cameron
2017-10-09 14:51:40 -04:00
parent 18649cc761
commit 8331763fe2
2 changed files with 92 additions and 37 deletions

View File

@@ -11,7 +11,49 @@ namespace ICD.Common.Utils.Tests
[TestFixture]
public sealed class PathUtilsTest
{
[Test, UsedImplicitly]
#region Properties
[Test]
public static void RootPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void NvramPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void ProgramConfigPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void CommonConfigPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void CommonLibPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void ProgramLibPathTest()
{
Assert.Inconclusive();
}
#endregion
#region Methods
[Test]
public void JoinTest()
{
string expected = Path.Combine("A", "B");
@@ -19,5 +61,49 @@ namespace ICD.Common.Utils.Tests
Assert.AreEqual(expected, PathUtils.Join("A", "B", "C"));
}
[Test]
public static void GetFullPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void ChangeFilenameWithoutExtTest()
{
Assert.Inconclusive();
}
[Test]
public static void GetPathWithoutExtensionTest()
{
Assert.Inconclusive();
}
[Test]
public static void RecurseFilePathsTest()
{
Assert.Inconclusive();
}
[Test]
public static void GetDefaultConfigPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void GetProgramConfigPathTest()
{
Assert.Inconclusive();
}
[Test]
public static void PathExistsTest()
{
Assert.Inconclusive();
}
#endregion
}
}

View File

@@ -2,8 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using ICD.Common.Properties;
using ICD.Common.Services;
using ICD.Common.Services.Logging;
using ICD.Common.Utils.IO;
namespace ICD.Common.Utils
@@ -125,41 +123,10 @@ namespace ICD.Common.Utils
public static IEnumerable<string> RecurseFilePaths(string path)
{
if (!IcdDirectory.Exists(path))
yield break;
return Enumerable.Empty<string>();
Queue<string> queue = new Queue<string>();
queue.Enqueue(path);
while (queue.Count > 0)
{
path = queue.Dequeue();
// Get the subdirectories
try
{
foreach (string subDir in IcdDirectory.GetDirectories(path))
queue.Enqueue(subDir);
}
catch (Exception e)
{
ServiceProvider.TryGetService<ILoggerService>().AddEntry(eSeverity.Error, e, e.Message);
}
// Get the files
string[] files;
try
{
files = IcdDirectory.GetFiles(path);
}
catch (Exception e)
{
ServiceProvider.TryGetService<ILoggerService>().AddEntry(eSeverity.Error, e, e.Message);
continue;
}
foreach (string filePath in files)
yield return filePath;
}
return RecursionUtils.BreadthFirstSearch(path, IcdDirectory.GetDirectories)
.SelectMany(p => IcdDirectory.GetFiles(p));
}
/// <summary>
@@ -168,6 +135,7 @@ namespace ICD.Common.Utils
/// </summary>
/// <param name="localPath"></param>
/// <returns></returns>
[PublicAPI]
public static string GetDefaultConfigPath(params string[] localPath)
{
string local = Join(localPath);
@@ -199,6 +167,7 @@ namespace ICD.Common.Utils
/// </summary>
/// <param name="path"></param>
/// <returns></returns>
[PublicAPI]
public static bool PathExists(string path)
{
return IcdFile.Exists(path) || IcdDirectory.Exists(path);