mirror of
https://github.com/ICDSystems/ICD.Common.Utils.git
synced 2026-02-17 05:35:07 +00:00
Simplifying path recursion, adding PathUtils test stubs
This commit is contained in:
@@ -11,7 +11,49 @@ namespace ICD.Common.Utils.Tests
|
|||||||
[TestFixture]
|
[TestFixture]
|
||||||
public sealed class PathUtilsTest
|
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()
|
public void JoinTest()
|
||||||
{
|
{
|
||||||
string expected = Path.Combine("A", "B");
|
string expected = Path.Combine("A", "B");
|
||||||
@@ -19,5 +61,49 @@ namespace ICD.Common.Utils.Tests
|
|||||||
|
|
||||||
Assert.AreEqual(expected, PathUtils.Join("A", "B", "C"));
|
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using ICD.Common.Properties;
|
using ICD.Common.Properties;
|
||||||
using ICD.Common.Services;
|
|
||||||
using ICD.Common.Services.Logging;
|
|
||||||
using ICD.Common.Utils.IO;
|
using ICD.Common.Utils.IO;
|
||||||
|
|
||||||
namespace ICD.Common.Utils
|
namespace ICD.Common.Utils
|
||||||
@@ -125,41 +123,10 @@ namespace ICD.Common.Utils
|
|||||||
public static IEnumerable<string> RecurseFilePaths(string path)
|
public static IEnumerable<string> RecurseFilePaths(string path)
|
||||||
{
|
{
|
||||||
if (!IcdDirectory.Exists(path))
|
if (!IcdDirectory.Exists(path))
|
||||||
yield break;
|
return Enumerable.Empty<string>();
|
||||||
|
|
||||||
Queue<string> queue = new Queue<string>();
|
return RecursionUtils.BreadthFirstSearch(path, IcdDirectory.GetDirectories)
|
||||||
queue.Enqueue(path);
|
.SelectMany(p => IcdDirectory.GetFiles(p));
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -168,6 +135,7 @@ namespace ICD.Common.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="localPath"></param>
|
/// <param name="localPath"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[PublicAPI]
|
||||||
public static string GetDefaultConfigPath(params string[] localPath)
|
public static string GetDefaultConfigPath(params string[] localPath)
|
||||||
{
|
{
|
||||||
string local = Join(localPath);
|
string local = Join(localPath);
|
||||||
@@ -199,6 +167,7 @@ namespace ICD.Common.Utils
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="path"></param>
|
/// <param name="path"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
|
[PublicAPI]
|
||||||
public static bool PathExists(string path)
|
public static bool PathExists(string path)
|
||||||
{
|
{
|
||||||
return IcdFile.Exists(path) || IcdDirectory.Exists(path);
|
return IcdFile.Exists(path) || IcdDirectory.Exists(path);
|
||||||
|
|||||||
Reference in New Issue
Block a user