Increase coverage with identity and filter tests

This commit is contained in:
2026-02-05 18:28:44 +01:00
parent 875b12db3f
commit 9096e089ab
5 changed files with 258 additions and 1 deletions

View File

@@ -39,11 +39,26 @@ public class HelperTests
Assert.Contains("content=\"/pick\"", text);
}
[Fact]
public void UpdateIndexMetaBase_no_marker_no_change()
{
var webRoot = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
Directory.CreateDirectory(webRoot);
var index = Path.Combine(webRoot, "index.html");
File.WriteAllText(index, "<html></html>");
var env = new FakeEnv { WebRootPath = webRoot };
var method = typeof(Program).GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public)
.First(m => m.Name.Contains("UpdateIndexMetaBase"));
method.Invoke(null, new object?[] { env, "/pick" });
Assert.Equal("<html></html>", File.ReadAllText(index));
}
[Fact]
public async Task IsReachableImageAsync_rejects_redirect_and_accepts_image()
{
Assert.True(await EndpointHelpers.IsReachableImageAsync(null, new StubHttpClientFactory(new StubHttpMessageHandler())));
// Private host should be rejected before network call
Assert.False(await EndpointHelpers.IsReachableImageAsync("http://127.0.0.1/img.png", new StubHttpClientFactory(new StubHttpMessageHandler())));
}
@@ -69,6 +84,20 @@ public class HelperTests
Assert.False(EndpointHelpers.IsValidHttpUrl("file://x"));
}
[Fact]
public void Find_root_handles_cycles()
{
var parentMap = new Dictionary<int, int?>
{
{1, 2},
{2, 3},
{3, 1}
};
var root = EndpointHelpers.FindRootId(1, parentMap);
Assert.Equal(3, root); // cycle breaks on revisit
}
private class FakeEnv : IWebHostEnvironment
{
public string ApplicationName { get; set; } = "";