using System; using System.IO; using GeoVLog.Core.Hdf5; using Xunit; namespace GeoVLog.Tests.Helpers; public class UniquePathTests { [Fact] [Trait("Category", "Core")] public void ReturnsSameBaseWhenUnused() { var dir = CreateTempDir(); try { var basePath = Path.Combine(dir, "20250521_0915"); var unique = H5LogQueueWorker.GetUniquePath(basePath); Assert.Equal(basePath, unique); } finally { Directory.Delete(dir, true); } } [Fact] [Trait("Category", "Core")] public void AddsSuffixWhenFilesExist() { var dir = CreateTempDir(); try { var basePath = Path.Combine(dir, "20250521_0915"); File.WriteAllText(basePath + ".h5", string.Empty); var unique = H5LogQueueWorker.GetUniquePath(basePath); Assert.Equal(basePath + "(1)", unique); } finally { Directory.Delete(dir, true); } } [Fact] [Trait("Category", "Core")] public void IncrementsSuffixUntilFree() { var dir = CreateTempDir(); try { var basePath = Path.Combine(dir, "20250521_0915"); File.WriteAllText(basePath + ".h5", string.Empty); File.WriteAllText(basePath + "(1).h5.enc", string.Empty); var unique = H5LogQueueWorker.GetUniquePath(basePath); Assert.Equal(basePath + "(2)", unique); } finally { Directory.Delete(dir, true); } } private static string CreateTempDir() { var path = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")); Directory.CreateDirectory(path); return path; } }