Files
Explorer-Workbench/tests/Explorer.Application.Tests/IndexedPathPresenceTests.cs

86 lines
2.9 KiB
C#

using Explorer.Application;
using Explorer.Domain;
namespace Explorer.Application.Tests;
public class IndexedPathPresenceTests
{
[Fact]
public void Missing_tree_returns_the_highest_gone_folder()
{
var root = Path.Combine(Path.GetTempPath(), "ew-idx", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
try
{
Assert.Equal(
"gone",
IndexedPathPresence.HighestMissingPrefix(root, @"gone\deep\file.txt"));
Assert.Equal("nope.txt", IndexedPathPresence.HighestMissingPrefix(root, "nope.txt"));
File.WriteAllText(Path.Combine(root, "keep.txt"), "x");
Assert.Null(IndexedPathPresence.HighestMissingPrefix(root, "keep.txt"));
}
finally
{
Directory.Delete(root, true);
}
}
[Fact]
public void Archive_inner_path_follows_the_archive_file()
{
var root = Path.Combine(Path.GetTempPath(), "ew-idx", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
var zip = Path.Combine(root, "pack.zip");
File.WriteAllBytes(zip, [1, 2, 3]);
try
{
Assert.True(IndexedPathPresence.FileExists(root, @"pack.zip\inner.txt"));
File.Delete(zip);
Assert.False(IndexedPathPresence.FileExists(root, @"pack.zip\inner.txt"));
Assert.Equal("pack.zip", IndexedPathPresence.HighestMissingPrefix(root, @"pack.zip\inner.txt"));
}
finally
{
if (Directory.Exists(root))
{
Directory.Delete(root, true);
}
}
}
[Fact]
public void Reconcile_path_uses_the_parent_for_a_missing_file()
{
Assert.Equal("gone", IndexedPathPresence.ReconcilePath(@"gone\deep\file.txt", "gone"));
Assert.Equal("", IndexedPathPresence.ReconcilePath("nope.txt", "nope.txt"));
Assert.Equal("keep", IndexedPathPresence.ReconcilePath(@"keep\a.txt", @"keep\a.txt"));
}
[Fact]
public void Long_paths_are_detected_with_the_extended_prefix()
{
var root = Path.Combine(Path.GetTempPath(), "ew-idx", Guid.NewGuid().ToString("N"));
var relative = Path.Combine(new string('a', 140), new string('b', 140), "file.txt");
var full = PathRules.Combine(root, relative);
Directory.CreateDirectory(PathRules.ToExtended(PathRules.Parent(full)));
File.WriteAllText(PathRules.ToExtended(full), "x");
try
{
Assert.True(IndexedPathPresence.FileExists(root, relative));
File.Delete(PathRules.ToExtended(full));
Assert.False(IndexedPathPresence.FileExists(root, relative));
}
finally
{
try
{
Directory.Delete(PathRules.ToExtended(root), true);
}
catch
{
// ignore
}
}
}
}