Files
ThreadPilot/Tests/ThreadPilot.Core.Tests/PersistentRuleResolutionTests.cs
T
PrimeBuild-pc 2102724b8f feat: back up persistent rules and resolve rule precedence deterministically
- Configuration export now includes persistent process rules (schema 3.0),
  stays compatible with 2.0 bundles, validates before writing, previews
  what an import replaces and rolls back on failure.
- Matching rules apply broad-to-specific (name, wildcard path, exact path,
  then most recently edited), shared by the engine and the process summary,
  which now lists the apply order and flags conflicting values.
- Localized the new strings in all seven languages.
2026-10-14 17:05:41 +02:00

39 lines
1.7 KiB
C#

namespace ThreadPilot.Core.Tests
{
using System.Diagnostics;
using ThreadPilot.Models;
using ThreadPilot.Services;
public sealed class PersistentRuleResolutionTests
{
private static readonly ProcessModel Process = new() { Name = "game.exe", ExecutablePath = @"C:\Games\Foo\game.exe" };
[Fact]
public void MatchInApplyOrder_PutsMoreSpecificRulesLast()
{
var byName = Rule("name", processName: "game.exe");
var exact = Rule("exact", path: @"C:\Games\Foo\game.exe");
var wildcard = Rule("wildcard", path: @"C:\Games\*\game.exe");
var other = Rule("other", processName: "other.exe");
var order = PersistentRuleResolution.MatchInApplyOrder([exact, other, wildcard, byName], Process, new PersistentProcessRuleMatcher());
Assert.Equal(["name", "wildcard", "exact"], order.Select(rule => rule.Id));
}
[Fact]
public void HasConflicts_OnlyWhenAppliedValuesDiffer()
{
var high = Rule("a", processName: "game.exe") with { Priority = ProcessPriorityClass.High, ApplyPriorityOnStart = true };
var low = Rule("b", processName: "game.exe") with { Priority = ProcessPriorityClass.BelowNormal, ApplyPriorityOnStart = true };
var unapplied = low with { Id = "c", ApplyPriorityOnStart = false };
Assert.True(PersistentRuleResolution.HasConflicts([high, low]));
Assert.False(PersistentRuleResolution.HasConflicts([high, unapplied]));
}
private static PersistentProcessRule Rule(string id, string? processName = null, string? path = null) =>
new() { Id = id, IsEnabled = true, ProcessName = processName, ExecutablePath = path };
}
}