9a4baba19a
* 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.
* feat: clearer process and rule editors
- Process details: CPU, memory and I/O priority pickers with an explicit
Apply, undo of the last manual priority change (guarded against reused
PIDs), adaptive side/bottom details panel.
- Manual process control stays available while automation is paused, with
a persistent notice instead of an overlay.
- Saved-rule editor stages all edits (including the core mask) and saves
them together, showing pending changes.
- Localized the new strings in all seven languages.
* fix: one save path for a saved rule's cores
The rules editor's core mask went through a new update path that reported
success without saving when no affinity payload was built, and kept a
legacy mask next to a CPU selection. Merge it with the old single-purpose
method (now unused), keep its checks, and localize the undo message.
* feat: per-process efficiency mode (EcoQoS) for live processes and rules
Closes #66.
- Native: SetProcessInformation/GetProcessInformation with
ProcessPowerThrottling (EXECUTION_SPEED), three states: Windows decides,
On (EcoQoS), Off (never throttle / HighQoS).
- Process tab: context menu entries, a picker with Apply in the details
panel, current state in the summary, undo of the last change, included
when saving current settings as a rule (only if explicitly set).
- Rules: EfficiencyMode + ApplyEfficiencyModeOnStart, applied by the rules
engine, editable in the saved-rule editor, validated on import and part
of conflict detection.
- The summary flags when the global Power Throttling tweak voids it. CPU
priority is left alone, unlike Task Manager's efficiency mode.
- Localized in all seven languages.
* chore: keep CRLF line endings in SelectedProcessSummaryViewModel
* feat: clearer navigation, process page and rules editor
- Navigation pane open with short labels instead of seven bare icons.
- Processes: one toolbar row (search with placeholder, Filters and
Columns menus, sort, refresh); details split into Process, Priority,
CPU cores and Rule cards; pickers start from the process's current
values and stay empty when a value cannot be read; help paragraphs
moved into tooltips; core picker always visible.
- Rules: process rules first, clearer tab names, localized choices in the
saved-rule editor instead of internal enum names.
- Shorter page titles and subtitles in all seven languages; removed the
strings this made unused.
No data format changes.
* feat: settings and tweaks as Windows 11 rows, localized rule list
- Settings: one column of rows (what it is on the left, its switch on the
right), most used sections first, Save as the primary action.
- Tweaks: one tweak per row with its status dot and switch.
- Rule list: 'Applies' and 'Mode' columns use the same localized labels as
the editor and refresh on language change.
- Removed 76 strings no code referenced, from all seven languages.
* fix: issues found testing the beta in a clean Windows 11 VM
- Process counter could show more visible processes than the total
('157 / 151'): the batch total was a snapshot from the first load.
- Narrow windows (or 150% scaling): toolbar buttons move under the search
box instead of squeezing it to a few letters.
- Rules list keeps the 'Applies' column readable when narrow.
- Settings status message gets its own line instead of being cut.
Tested in a Hyper-V Windows 11 VM: clean install, upgrade, uninstall,
light and dark theme, 100% and 150% scaling.
* feat: remember layout choices; Windows 11 toggles in Tweaks
- The navigation pane, window size/position/maximized state, and the
process list filters, sort and columns now survive a restart. They live
in ui-state.json, apart from settings.json, so they never mark the
Settings page as unsaved or travel in exported configurations. A corrupt
file falls back to defaults; tests write to a temp file.
- Fixes the pane re-opening on every start (it was hard-coded open).
- Tweaks use a native-looking Windows 11 switch (40x20 track, sliding
thumb) with On/Off written beside it.
- New test: every on/off setting survives save and reload.
* docs: handoff for the 1.7.7 PR stack and beta test
* fix: P/E cores from the highest EfficiencyClass, AMD CCDs from real L3 groups
The legacy topology treated the lowest EfficiencyClass as the performance
core, swapping P- and E-cores on hybrid Intel CPUs. AMD CCDs were guessed
as 8 cores each, which split 6+6 parts (7900X3D, 9900X3D) into 8+4; they now
come from the L3 groups Windows reports, with the guess kept only as a
fallback. The topology snapshot also keeps each L3 group's size.
* feat: Game Boost, CPU Sets for the game and selected background apps
While a detected game runs, Game Boost sets process default CPU Sets from
the CPU topology: on AMD X3D with one larger L3 the game goes to the V-Cache
CCD, on Intel hybrid CPUs to the P-cores, and selected background apps
(browsers, sync clients, updaters, launchers) to the other cores. On dual-CCD
parts with equal L3 only the background moves, unless Isolation mode also
keeps the game on CCD0. Single-L3 and unreadable topologies are left to
Windows. Above Normal priority for the game is optional; never High.
Each change is written to a journal before it is made and undone when the
game exits, Game Boost is turned off or ThreadPilot closes, and on the next
start after a crash. Only values still exactly as Game Boost set them are
restored, never one a user rule or a manual change has taken over since.
Persistent rules and Game Boost share one apply gate, and a rule always
wins over Game Boost for the setting it covers.
The switch, mode and lists are on the Tweaks page, off by default, and take
effect without a restart.
* fix: Game Boost background entries with a full path never matched
The background list compared full-path entries against an empty path, so
only bare process names worked. Found by a new integration test that runs
the real services on two copies of PING.EXE: CPU Sets and priority are set
and read back through Windows, removed when Game Boost is turned off, and
undone from the journal after a simulated crash. The topology is simulated
from this machine's CPU Set IDs, so the test also runs on CPUs where Game
Boost would not act; it skips itself below 8 cores.
* feat: report Game Boost sessions and restore results in Activity
* test: diagnose EcoQoS read failures on Windows Server
* chore: prepare 1.7.7-beta.2 and keep prereleases out of stable channels
* test: use native full-query access mask in EcoQoS diagnostic
* docs: update beta handoff and prerelease publication policy
* ci: run native EcoQoS tests on a Windows 11-era kernel
Windows Server 2022 build 20348 rejects GetProcessInformation(ProcessPowerThrottling) with ERROR_INVALID_PARAMETER (87), with both limited and full query handles. Windows 11 local tests pass. Use Server 2025 for CI/release tests and smoke testing; keep the real round-trip assertions, remove temporary probes.
* test: lock beta publication and native runner contracts
* chore: separate stable 1.7.7 from experimental Game Boost
Stable retains the validated EcoQoS/rules/UI stack. Preserve the complete local Game Boost implementation at ef2ec24 for the separate 1.7.8-beta.1 prerelease; no experimental Game Boost/topology changes ship in stable. Keep channel-aware publication and Windows 11-era native CI tests.
901 lines
43 KiB
C#
901 lines
43 KiB
C#
namespace ThreadPilot.Core.Tests
|
|
{
|
|
using System.Collections.ObjectModel;
|
|
using System.Diagnostics;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Moq;
|
|
using ThreadPilot.Models;
|
|
using ThreadPilot.Services;
|
|
using ThreadPilot.ViewModels;
|
|
|
|
public sealed class ProcessViewModelContextMenuTests
|
|
{
|
|
[Fact]
|
|
public async Task ContextCpuPriorityCommand_CallsSafePriorityServicePath()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var enhancedLoggingService = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
enhancedLoggingService: enhancedLoggingService.Object,
|
|
activityAuditService: audit);
|
|
var process = CreateProcess(priority: ProcessPriorityClass.Normal);
|
|
|
|
await viewModel.SetContextHighPriorityCommand.ExecuteAsync(process);
|
|
|
|
processService.Verify(
|
|
service => service.SetProcessPriority(process, ProcessPriorityClass.High, ProcessPriorityWriteSource.ManualUiAction),
|
|
Times.Once);
|
|
enhancedLoggingService.Verify(
|
|
service => service.LogUserActionAsync(
|
|
"ProcessPriorityChanged",
|
|
It.Is<string>(details => details.Contains("Game.exe") && details.Contains("High")),
|
|
It.Is<string>(context => context.Contains("PID: 42"))),
|
|
Times.Once);
|
|
Assert.Equal(ProcessOperationUserMessages.HighPriorityWarning, viewModel.StatusMessage);
|
|
Assert.False(viewModel.HasError);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Priority", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Success, entry.Severity);
|
|
Assert.Contains("High", entry.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyContextAffinityCommand_UsesProvidedRowProcess()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var coordinator = CreateAffinityCoordinator();
|
|
var enhancedLoggingService = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
processAffinityApplyCoordinator: coordinator.Object,
|
|
enhancedLoggingService: enhancedLoggingService.Object,
|
|
activityAuditService: audit);
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
new CpuCoreModel { LogicalCoreId = 1, IsSelected = false },
|
|
];
|
|
var rowProcess = CreateProcess(processId: 100);
|
|
|
|
await viewModel.ApplyContextAffinityCommand.ExecuteAsync(rowProcess);
|
|
|
|
coordinator.Verify(
|
|
service => service.ApplyCoreSelectionAsync(
|
|
rowProcess,
|
|
It.Is<IReadOnlyList<bool>>(mask => mask.Count == 2 && mask[0] && !mask[1]),
|
|
"Manual Process tab context menu CPU selection",
|
|
CpuAssignmentMode.Automatic,
|
|
default),
|
|
Times.Once);
|
|
enhancedLoggingService.Verify(
|
|
service => service.LogUserActionAsync(
|
|
"ProcessCpuAssignmentApplied",
|
|
It.IsAny<string>(),
|
|
It.Is<string>(context => context.Contains("Process: Game.exe") && context.Contains("PID: 100"))),
|
|
Times.Once);
|
|
Assert.Same(rowProcess, viewModel.SelectedProcess);
|
|
Assert.Equal("CPU assignment applied successfully to Game.exe using AffinityMask.", viewModel.StatusMessage);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Affinity", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Success, entry.Severity);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyContextAffinityCommand_WhenRowProcessDiffersFromSelectedProcess_UsesRowProcess()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var coordinator = CreateAffinityCoordinator();
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
processAffinityApplyCoordinator: coordinator.Object);
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
new CpuCoreModel { LogicalCoreId = 1, IsSelected = true },
|
|
];
|
|
var oldSelectedProcess = CreateProcess(processId: 1, name: "Old.exe");
|
|
var rowProcess = CreateProcess(processId: 2, name: "Row.exe");
|
|
viewModel.SelectedProcess = oldSelectedProcess;
|
|
|
|
await viewModel.ApplyContextAffinityCommand.ExecuteAsync(rowProcess);
|
|
|
|
coordinator.Verify(
|
|
service => service.ApplyCoreSelectionAsync(
|
|
rowProcess,
|
|
It.IsAny<IReadOnlyList<bool>>(),
|
|
"Manual Process tab context menu CPU selection",
|
|
CpuAssignmentMode.Automatic,
|
|
default),
|
|
Times.Once);
|
|
coordinator.Verify(
|
|
service => service.ApplyCoreSelectionAsync(
|
|
oldSelectedProcess,
|
|
It.IsAny<IReadOnlyList<bool>>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<CpuAssignmentMode>(),
|
|
default),
|
|
Times.Never);
|
|
Assert.Same(rowProcess, viewModel.SelectedProcess);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyContextAffinityCommand_DoesNotCallLegacyLongDirectly()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var coordinator = CreateAffinityCoordinator();
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
processAffinityApplyCoordinator: coordinator.Object);
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
];
|
|
var rowProcess = CreateProcess();
|
|
|
|
await viewModel.ApplyContextAffinityCommand.ExecuteAsync(rowProcess);
|
|
|
|
coordinator.Verify(
|
|
service => service.ApplyCoreSelectionAsync(
|
|
rowProcess,
|
|
It.IsAny<IReadOnlyList<bool>>(),
|
|
"Manual Process tab context menu CPU selection",
|
|
CpuAssignmentMode.Automatic,
|
|
default),
|
|
Times.Once);
|
|
processService.Verify(
|
|
service => service.SetProcessorAffinity(It.IsAny<ProcessModel>(), It.IsAny<long>()),
|
|
Times.Never);
|
|
}
|
|
|
|
[Fact]
|
|
public void ContextCpuPriorityActions_DoNotExposeRealtimeAsNormalAction()
|
|
{
|
|
var viewModel = CreateViewModel(CreateProcessService().Object);
|
|
|
|
Assert.DoesNotContain(ProcessPriorityClass.RealTime, viewModel.ContextMenuCpuPriorityActions);
|
|
Assert.Contains(ProcessPriorityClass.High, viewModel.ContextMenuCpuPriorityActions);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SetPriorityCommand_WhenRealtimeRequested_LogsVisibleBlockedEntry()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(processService.Object, activityAuditService: audit);
|
|
viewModel.SelectedProcess = CreateProcess();
|
|
|
|
await viewModel.SetPriorityCommand.ExecuteAsync(ProcessPriorityClass.RealTime);
|
|
|
|
processService.Verify(
|
|
service => service.SetProcessPriority(It.IsAny<ProcessModel>(), ProcessPriorityClass.RealTime),
|
|
Times.Never);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Priority", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Warning, entry.Severity);
|
|
Assert.Equal(ProcessOperationUserMessages.RealtimePriorityBlocked, entry.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ContextMemoryPriorityCommand_CallsMemoryPriorityService()
|
|
{
|
|
var memoryPriorityService = new Mock<IProcessMemoryPriorityService>(MockBehavior.Strict);
|
|
memoryPriorityService
|
|
.Setup(service => service.SetMemoryPriorityAsync(It.IsAny<ProcessModel>(), ProcessMemoryPriority.Low))
|
|
.ReturnsAsync(ProcessOperationResult.Succeeded("Memory priority applied.", "ok"));
|
|
memoryPriorityService
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(ProcessMemoryPriority.Low);
|
|
var enhancedLoggingService = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var process = CreateProcess();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
memoryPriorityService: memoryPriorityService.Object,
|
|
enhancedLoggingService: enhancedLoggingService.Object,
|
|
activityAuditService: audit);
|
|
|
|
await viewModel.SetContextMemoryPriorityLowCommand.ExecuteAsync(process);
|
|
|
|
memoryPriorityService.Verify(
|
|
service => service.SetMemoryPriorityAsync(process, ProcessMemoryPriority.Low),
|
|
Times.Once);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Memory Priority", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Success, entry.Severity);
|
|
enhancedLoggingService.Verify(
|
|
service => service.LogUserActionAsync(
|
|
"ProcessMemoryPriorityChanged",
|
|
It.Is<string>(details => details.Contains("Game.exe") && details.Contains("Low")),
|
|
It.Is<string>(context => context.Contains("PID: 42"))),
|
|
Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ContextMemoryPriorityCommand_WhenServiceFails_ShowsSafeUserMessage()
|
|
{
|
|
var memoryPriorityService = new Mock<IProcessMemoryPriorityService>(MockBehavior.Strict);
|
|
memoryPriorityService
|
|
.Setup(service => service.SetMemoryPriorityAsync(It.IsAny<ProcessModel>(), ProcessMemoryPriority.Normal))
|
|
.ReturnsAsync(ProcessOperationResult.Failed(
|
|
"AccessDenied",
|
|
ProcessOperationUserMessages.AccessDenied,
|
|
"Access is denied.",
|
|
isAccessDenied: true));
|
|
memoryPriorityService
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(ProcessMemoryPriority.Normal);
|
|
var process = CreateProcess();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
memoryPriorityService: memoryPriorityService.Object,
|
|
activityAuditService: audit);
|
|
|
|
await viewModel.SetContextMemoryPriorityNormalCommand.ExecuteAsync(process);
|
|
|
|
Assert.Equal(ProcessOperationUserMessages.AccessDenied, viewModel.StatusMessage);
|
|
Assert.True(viewModel.HasError);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Memory Priority", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Warning, entry.Severity);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ContextMemoryPriorityCommand_WhenSuccessful_UpdatesSelectedProcessSummary()
|
|
{
|
|
var memoryPriorityService = new Mock<IProcessMemoryPriorityService>(MockBehavior.Strict);
|
|
memoryPriorityService
|
|
.Setup(service => service.SetMemoryPriorityAsync(It.IsAny<ProcessModel>(), ProcessMemoryPriority.BelowNormal))
|
|
.ReturnsAsync(ProcessOperationResult.Succeeded("Memory priority applied.", "ok"));
|
|
memoryPriorityService
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(ProcessMemoryPriority.BelowNormal);
|
|
var process = CreateProcess();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
memoryPriorityService: memoryPriorityService.Object);
|
|
|
|
await viewModel.SetContextMemoryPriorityBelowNormalCommand.ExecuteAsync(process);
|
|
|
|
Assert.Equal(ProcessMemoryPriority.BelowNormal, viewModel.SelectedProcessSummary.MemoryPriority);
|
|
Assert.Equal("Memory priority: BelowNormal", viewModel.SelectedProcessSummary.MemoryPriorityText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task PriorityPickers_StartFromTheSelectedProcessCurrentValues()
|
|
{
|
|
var memoryPriorityService = new Mock<IProcessMemoryPriorityService>();
|
|
memoryPriorityService
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(ProcessMemoryPriority.Low);
|
|
memoryPriorityService
|
|
.Setup(service => service.GetIoPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync((ProcessIoPriority?)null);
|
|
var viewModel = CreateViewModel(CreateProcessService().Object, memoryPriorityService: memoryPriorityService.Object);
|
|
var process = CreateProcess();
|
|
process.Priority = ProcessPriorityClass.High;
|
|
|
|
await viewModel.SelectedProcessSummary.UpdateAsync(process);
|
|
|
|
Assert.Equal(ProcessPriorityClass.High, viewModel.PendingCpuPriority);
|
|
Assert.Equal(ProcessMemoryPriority.Low, viewModel.PendingMemoryPriority);
|
|
Assert.Null(viewModel.PendingIoPriority); // unreadable: the picker stays empty instead of guessing
|
|
}
|
|
|
|
[Fact]
|
|
public void ProcessCounter_NeverShowsMoreVisibleThanTotal()
|
|
{
|
|
var viewModel = CreateViewModel(CreateProcessService().Object);
|
|
viewModel.TotalProcessCount = 1; // stale snapshot from an earlier batch load
|
|
foreach (var pid in new[] { 101, 102, 103 })
|
|
{
|
|
viewModel.Processes.Add(new ProcessModel { ProcessId = pid, Name = $"p{pid}" });
|
|
}
|
|
|
|
// Filtering is debounced through the dispatcher in the app; call the filter step directly.
|
|
typeof(ProcessViewModel)
|
|
.GetMethod("FilterProcesses", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance)!
|
|
.Invoke(viewModel, null);
|
|
|
|
Assert.Equal(3, viewModel.FilteredProcesses.Count);
|
|
Assert.Equal(3, viewModel.TotalProcessCount);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CopyContextProcessInfo_IncludesNamePidAndPath()
|
|
{
|
|
string? copiedText = null;
|
|
var process = CreateProcess();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
clipboardSetter: text => copiedText = text);
|
|
|
|
await viewModel.CopyContextProcessInfoCommand.ExecuteAsync(process);
|
|
|
|
Assert.NotNull(copiedText);
|
|
Assert.Contains("Name: Game.exe", copiedText);
|
|
Assert.Contains("PID: 42", copiedText);
|
|
Assert.Contains(@"Path: C:\Games\Game.exe", copiedText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CopyContextProcessInfo_WhenPathMissing_DoesNotThrow()
|
|
{
|
|
string? copiedText = null;
|
|
var process = CreateProcess(path: string.Empty);
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
clipboardSetter: text => copiedText = text);
|
|
|
|
var exception = await Record.ExceptionAsync(
|
|
() => viewModel.CopyContextProcessInfoCommand.ExecuteAsync(process));
|
|
|
|
Assert.Null(exception);
|
|
Assert.Contains("Path: unavailable", copiedText);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task OpenContextExecutableLocation_WhenPathMissing_DoesNotThrow()
|
|
{
|
|
var viewModel = CreateViewModel(CreateProcessService().Object);
|
|
|
|
var exception = await Record.ExceptionAsync(
|
|
() => viewModel.OpenContextExecutableLocationCommand.ExecuteAsync(CreateProcess(path: string.Empty)));
|
|
|
|
Assert.Null(exception);
|
|
Assert.Equal("Executable path is unavailable for Game.exe.", viewModel.StatusMessage);
|
|
Assert.True(viewModel.HasError);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ClearContextCpuSetsCommand_CallsSafeCpuSetClearPath()
|
|
{
|
|
var processService = CreateProcessService();
|
|
processService
|
|
.Setup(service => service.ClearProcessCpuSetAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(true);
|
|
var process = CreateProcess();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(processService.Object, activityAuditService: audit);
|
|
|
|
await viewModel.ClearContextCpuSetsCommand.ExecuteAsync(process);
|
|
|
|
processService.Verify(service => service.ClearProcessCpuSetAsync(process), Times.Once);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Affinity", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Success, entry.Severity);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RefreshContextProcessInfoCommand_RefreshesSelectedProcessInfo()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var process = CreateProcess();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(processService.Object, activityAuditService: audit);
|
|
|
|
await viewModel.RefreshContextProcessInfoCommand.ExecuteAsync(process);
|
|
|
|
processService.Verify(service => service.RefreshProcessInfo(process), Times.Once);
|
|
Assert.Equal("Process info refreshed for Game.exe.", viewModel.StatusMessage);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Process", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Success, entry.Severity);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RefreshProcessesCommand_DoesNotCreateActivityAuditEntry()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(processService.Object, activityAuditService: audit);
|
|
|
|
await viewModel.RefreshProcessesCommand.ExecuteAsync(null);
|
|
|
|
Assert.Empty(await audit.GetEntriesAsync());
|
|
}
|
|
|
|
[Fact]
|
|
public async Task LockProcessList_WhenEnabled_SkipsRefreshAndKeepsSelection()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(processService.Object, activityAuditService: audit);
|
|
var selected = CreateProcess(processId: 42);
|
|
viewModel.Processes = new ObservableCollection<ProcessModel> { selected };
|
|
viewModel.FilteredProcesses = new ObservableCollection<ProcessModel> { selected };
|
|
viewModel.SelectedProcess = selected;
|
|
|
|
viewModel.IsProcessListLocked = true;
|
|
await viewModel.RefreshProcessesCommand.ExecuteAsync(null);
|
|
|
|
processService.Verify(service => service.GetProcessesAsync(), Times.Never);
|
|
Assert.Same(selected, viewModel.SelectedProcess);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Process", entry.Category);
|
|
Assert.Equal("Lock process list enabled.", entry.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RefreshProcessesCommand_WhenProcessViewInactive_SkipsProcessRead()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var viewModel = CreateViewModel(processService.Object);
|
|
|
|
viewModel.SetProcessViewActive(false);
|
|
await viewModel.RefreshProcessesCommand.ExecuteAsync(null);
|
|
|
|
processService.Verify(service => service.GetProcessesAsync(), Times.Never);
|
|
processService.Verify(service => service.GetActiveApplicationsAsync(), Times.Never);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task RefreshProcessesCommand_WhenRefreshPaused_SkipsProcessRead()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var viewModel = CreateViewModel(processService.Object);
|
|
|
|
viewModel.PauseRefresh();
|
|
await viewModel.RefreshProcessesCommand.ExecuteAsync(null);
|
|
|
|
processService.Verify(service => service.GetProcessesAsync(), Times.Never);
|
|
processService.Verify(service => service.GetActiveApplicationsAsync(), Times.Never);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task LoadProcessesCommand_WhenProcessViewInactive_DoesNotPreloadVirtualizedBatch()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var virtualizedProcessService = CreateVirtualizedProcessService(totalProcessCount: 100);
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
virtualizedProcessService: virtualizedProcessService.Object);
|
|
|
|
viewModel.SetProcessViewActive(false);
|
|
await viewModel.LoadProcessesCommand.ExecuteAsync(null);
|
|
|
|
virtualizedProcessService.Verify(
|
|
service => service.PreloadNextBatchAsync(It.IsAny<int>(), It.IsAny<bool>()),
|
|
Times.Never);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task LoadProcessesCommand_WhenProcessListLocked_DoesNotPreloadVirtualizedBatch()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var virtualizedProcessService = CreateVirtualizedProcessService(totalProcessCount: 100);
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
virtualizedProcessService: virtualizedProcessService.Object);
|
|
|
|
viewModel.IsProcessListLocked = true;
|
|
await viewModel.LoadProcessesCommand.ExecuteAsync(null);
|
|
|
|
virtualizedProcessService.Verify(
|
|
service => service.PreloadNextBatchAsync(It.IsAny<int>(), It.IsAny<bool>()),
|
|
Times.Never);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task LockProcessList_WhenDisabled_RefreshesOnceWithoutPersistentRuleSettingChange()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(processService.Object, activityAuditService: audit);
|
|
|
|
viewModel.IsProcessListLocked = true;
|
|
viewModel.IsProcessListLocked = false;
|
|
|
|
processService.Verify(service => service.GetProcessesAsync(), Times.Once);
|
|
var entries = await audit.GetEntriesAsync();
|
|
Assert.Contains(entries, entry => entry.Message == "Lock process list enabled.");
|
|
Assert.Contains(entries, entry => entry.Message == "Lock process list disabled.");
|
|
Assert.DoesNotContain(entries, entry => entry.Message.Contains("refreshed", StringComparison.OrdinalIgnoreCase));
|
|
Assert.DoesNotContain(entries, entry => entry.Message.Contains("Apply saved rules", StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ContextMenuActions_DoNotCreatePersistentRules()
|
|
{
|
|
var processService = CreateProcessService();
|
|
var memoryPriorityService = new Mock<IProcessMemoryPriorityService>(MockBehavior.Strict);
|
|
memoryPriorityService
|
|
.Setup(service => service.SetMemoryPriorityAsync(It.IsAny<ProcessModel>(), ProcessMemoryPriority.VeryLow))
|
|
.ReturnsAsync(ProcessOperationResult.Succeeded("Memory priority applied.", "ok"));
|
|
memoryPriorityService
|
|
.Setup(service => service.GetMemoryPriorityAsync(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(ProcessMemoryPriority.VeryLow);
|
|
var ruleStore = new Mock<IPersistentProcessRuleStore>(MockBehavior.Strict);
|
|
ruleStore
|
|
.Setup(store => store.LoadAsync())
|
|
.ReturnsAsync(Array.Empty<PersistentProcessRule>());
|
|
var viewModel = CreateViewModel(
|
|
processService.Object,
|
|
memoryPriorityService: memoryPriorityService.Object,
|
|
persistentRuleStore: ruleStore.Object,
|
|
clipboardSetter: _ => { });
|
|
var process = CreateProcess();
|
|
|
|
await viewModel.SetContextAboveNormalPriorityCommand.ExecuteAsync(process);
|
|
await viewModel.SetContextMemoryPriorityVeryLowCommand.ExecuteAsync(process);
|
|
await viewModel.CopyContextProcessInfoCommand.ExecuteAsync(process);
|
|
|
|
ruleStore.Verify(store => store.SaveAsync(It.IsAny<IReadOnlyList<PersistentProcessRule>>()), Times.Never);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SaveCurrentSettingsAsRuleCommand_CreatesRuleForSelectedProcess()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var enhancedLoggingService = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore),
|
|
enhancedLoggingService: enhancedLoggingService.Object);
|
|
var process = CreateProcess();
|
|
viewModel.SelectedProcess = process;
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
new CpuCoreModel { LogicalCoreId = 1, IsSelected = true },
|
|
];
|
|
|
|
await viewModel.SaveCurrentSettingsAsRuleCommand.ExecuteAsync(null);
|
|
|
|
var rule = Assert.Single(ruleStore.SavedRules);
|
|
Assert.Equal(process.Name, rule.ProcessName);
|
|
Assert.Equal(process.ExecutablePath, rule.ExecutablePath);
|
|
Assert.Equal("Saved rule for Game.exe.", viewModel.StatusMessage);
|
|
enhancedLoggingService.Verify(
|
|
service => service.LogUserActionAsync(
|
|
"PersistentRuleSaved",
|
|
"Saved rule for Game.exe.",
|
|
It.Is<string>(context => context.Contains("Process: Game.exe") && context.Contains("PID: 42"))),
|
|
Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SaveCurrentSettingsAsRuleCommand_UpdatesExistingMatchingRule()
|
|
{
|
|
var existing = new PersistentProcessRule
|
|
{
|
|
Id = "rule-1",
|
|
Name = "Old",
|
|
IsEnabled = true,
|
|
ProcessName = "Game.exe",
|
|
ExecutablePath = @"C:\Games\Game.exe",
|
|
CreatedAt = DateTime.UtcNow.AddDays(-1),
|
|
UpdatedAt = DateTime.UtcNow.AddDays(-1),
|
|
};
|
|
var ruleStore = new CapturingRuleStore([existing]);
|
|
var enhancedLoggingService = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore),
|
|
enhancedLoggingService: enhancedLoggingService.Object);
|
|
|
|
await viewModel.SaveCurrentSettingsAsRuleCommand.ExecuteAsync(CreateProcess(priority: ProcessPriorityClass.High));
|
|
|
|
var rule = Assert.Single(ruleStore.SavedRules);
|
|
Assert.Equal("rule-1", rule.Id);
|
|
Assert.Equal(ProcessPriorityClass.High, rule.Priority);
|
|
Assert.Equal("Updated saved rule for Game.exe.", viewModel.StatusMessage);
|
|
enhancedLoggingService.Verify(
|
|
service => service.LogUserActionAsync(
|
|
"PersistentRuleSaved",
|
|
"Updated saved rule for Game.exe.",
|
|
It.Is<string>(context => context.Contains("Process: Game.exe") && context.Contains("PID: 42"))),
|
|
Times.Once);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SaveCurrentSettingsAsRuleCommand_WithNormalPriorityAndNoAffinityOrMemoryPriority_ShowsNoActionMessage()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore));
|
|
var process = CreateProcess(priority: ProcessPriorityClass.Normal, affinity: 0);
|
|
|
|
await viewModel.SaveCurrentSettingsAsRuleCommand.ExecuteAsync(process);
|
|
|
|
Assert.Empty(ruleStore.SavedRules);
|
|
Assert.Equal("There are no current settings to save as a rule.", viewModel.StatusMessage);
|
|
Assert.True(viewModel.HasError);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SaveCurrentSettingsAsRuleCommand_WithAffinityAndNormalPriority_DoesNotSaveApplyPriorityOnStart()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore));
|
|
var process = CreateProcess(priority: ProcessPriorityClass.Normal, affinity: 0x5);
|
|
|
|
await viewModel.SaveCurrentSettingsAsRuleCommand.ExecuteAsync(process);
|
|
|
|
var rule = Assert.Single(ruleStore.SavedRules);
|
|
Assert.Equal(0x5, rule.LegacyAffinityMask);
|
|
Assert.Null(rule.Priority);
|
|
Assert.False(rule.ApplyPriorityOnStart);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyAffinityAndSaveAsRuleCommand_AppliesAffinityBeforeSavingRule()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var coordinator = CreateAffinityCoordinator();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
processAffinityApplyCoordinator: coordinator.Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore));
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
new CpuCoreModel { LogicalCoreId = 1, IsSelected = false },
|
|
];
|
|
var process = CreateProcess();
|
|
|
|
await viewModel.ApplyAffinityAndSaveAsRuleCommand.ExecuteAsync(process);
|
|
|
|
coordinator.Verify(
|
|
service => service.ApplyCoreSelectionAsync(
|
|
process,
|
|
It.Is<IReadOnlyList<bool>>(mask => mask.Count == 2 && mask[0] && !mask[1]),
|
|
"Manual Process tab context menu CPU selection",
|
|
CpuAssignmentMode.Automatic,
|
|
default),
|
|
Times.Once);
|
|
var rule = Assert.Single(ruleStore.SavedRules);
|
|
Assert.Equal(1, rule.LegacyAffinityMask);
|
|
Assert.True(rule.ApplyAffinityOnStart);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyAffinityAndSaveAsRuleCommand_WhenAffinityApplyFails_DoesNotSaveRule()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var coordinator = new Mock<IProcessAffinityApplyCoordinator>(MockBehavior.Strict);
|
|
coordinator
|
|
.Setup(service => service.ApplyCoreSelectionAsync(
|
|
It.IsAny<ProcessModel>(),
|
|
It.IsAny<IReadOnlyList<bool>>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<CpuAssignmentMode>(),
|
|
default))
|
|
.ReturnsAsync(AffinityApplyResult.Failed(
|
|
AffinityApplyErrorCodes.AccessDenied,
|
|
ProcessOperationUserMessages.AccessDenied,
|
|
"Access denied.",
|
|
isAccessDenied: true));
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
processAffinityApplyCoordinator: coordinator.Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore),
|
|
activityAuditService: audit);
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
];
|
|
|
|
await viewModel.ApplyAffinityAndSaveAsRuleCommand.ExecuteAsync(CreateProcess());
|
|
|
|
Assert.Empty(ruleStore.SavedRules);
|
|
Assert.Equal(ProcessOperationUserMessages.AccessDenied, viewModel.StatusMessage);
|
|
Assert.True(viewModel.HasError);
|
|
var entry = Assert.Single(await audit.GetEntriesAsync());
|
|
Assert.Equal("Affinity", entry.Category);
|
|
Assert.Equal(ActivityAuditSeverity.Warning, entry.Severity);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyAffinityAndSaveAsRuleCommand_UsesRowProcessInsteadOfStaleSelectedProcess()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var coordinator = CreateAffinityCoordinator();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
processAffinityApplyCoordinator: coordinator.Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore));
|
|
viewModel.CpuCores =
|
|
[
|
|
new CpuCoreModel { LogicalCoreId = 0, IsSelected = true },
|
|
];
|
|
var staleSelected = CreateProcess(name: "Old.exe", path: @"C:\Old\Old.exe");
|
|
var rowProcess = CreateProcess(name: "Row.exe", path: @"C:\Row\Row.exe");
|
|
viewModel.SelectedProcess = staleSelected;
|
|
|
|
await viewModel.ApplyAffinityAndSaveAsRuleCommand.ExecuteAsync(rowProcess);
|
|
|
|
coordinator.Verify(
|
|
service => service.ApplyCoreSelectionAsync(
|
|
rowProcess,
|
|
It.IsAny<IReadOnlyList<bool>>(),
|
|
It.IsAny<string>(),
|
|
CpuAssignmentMode.Automatic,
|
|
default),
|
|
Times.Once);
|
|
var rule = Assert.Single(ruleStore.SavedRules);
|
|
Assert.Equal("Row.exe", rule.ProcessName);
|
|
Assert.Equal(@"C:\Row\Row.exe", rule.ExecutablePath);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task SaveCurrentSettingsAsRuleCommand_UpdatesSelectedProcessSummary()
|
|
{
|
|
var ruleStore = new CapturingRuleStore();
|
|
var viewModel = CreateViewModel(
|
|
CreateProcessService().Object,
|
|
persistentRuleStore: ruleStore,
|
|
processRuleCreationService: CreateRuleCreationService(ruleStore));
|
|
var process = CreateProcess();
|
|
|
|
await viewModel.SaveCurrentSettingsAsRuleCommand.ExecuteAsync(process);
|
|
|
|
Assert.True(viewModel.SelectedProcessSummary.HasThreadPilotRule);
|
|
Assert.Equal("Saved rule exists: Game.exe rule", viewModel.SelectedProcessSummary.RuleStatusText);
|
|
}
|
|
|
|
private static Mock<IProcessService> CreateProcessService()
|
|
{
|
|
var processService = new Mock<IProcessService>(MockBehavior.Loose);
|
|
processService
|
|
.Setup(service => service.GetProcessesAsync())
|
|
.ReturnsAsync(new ObservableCollection<ProcessModel>());
|
|
processService
|
|
.Setup(service => service.GetActiveApplicationsAsync())
|
|
.ReturnsAsync(new ObservableCollection<ProcessModel>());
|
|
processService
|
|
.Setup(service => service.IsProcessStillRunning(It.IsAny<ProcessModel>()))
|
|
.ReturnsAsync(true);
|
|
processService
|
|
.Setup(service => service.RefreshProcessInfo(It.IsAny<ProcessModel>()))
|
|
.Returns(Task.CompletedTask);
|
|
return processService;
|
|
}
|
|
|
|
private static Mock<IVirtualizedProcessService> CreateVirtualizedProcessService(int totalProcessCount)
|
|
{
|
|
var virtualizedProcessService = new Mock<IVirtualizedProcessService>(MockBehavior.Loose);
|
|
virtualizedProcessService.SetupProperty(
|
|
service => service.Configuration,
|
|
new VirtualizedProcessConfig());
|
|
virtualizedProcessService
|
|
.Setup(service => service.InitializeAsync())
|
|
.Returns(Task.CompletedTask);
|
|
virtualizedProcessService
|
|
.Setup(service => service.GetTotalProcessCountAsync(It.IsAny<bool>()))
|
|
.ReturnsAsync(totalProcessCount);
|
|
virtualizedProcessService
|
|
.Setup(service => service.LoadProcessBatchAsync(It.IsAny<int>(), It.IsAny<bool>()))
|
|
.ReturnsAsync(new ProcessBatchResult
|
|
{
|
|
Processes = [CreateProcess()],
|
|
BatchIndex = 0,
|
|
TotalBatches = 2,
|
|
TotalProcessCount = totalProcessCount,
|
|
HasMoreBatches = true,
|
|
});
|
|
return virtualizedProcessService;
|
|
}
|
|
|
|
private static Mock<IProcessAffinityApplyCoordinator> CreateAffinityCoordinator()
|
|
{
|
|
var coordinator = new Mock<IProcessAffinityApplyCoordinator>(MockBehavior.Strict);
|
|
coordinator
|
|
.Setup(service => service.ApplyCoreSelectionAsync(
|
|
It.IsAny<ProcessModel>(),
|
|
It.IsAny<IReadOnlyList<bool>>(),
|
|
It.IsAny<string>(),
|
|
It.IsAny<CpuAssignmentMode>(),
|
|
default))
|
|
.ReturnsAsync(AffinityApplyResult.Succeeded(1, 1));
|
|
return coordinator;
|
|
}
|
|
|
|
private static ProcessViewModel CreateViewModel(
|
|
IProcessService processService,
|
|
IProcessAffinityApplyCoordinator? processAffinityApplyCoordinator = null,
|
|
IProcessMemoryPriorityService? memoryPriorityService = null,
|
|
IPersistentProcessRuleStore? persistentRuleStore = null,
|
|
IProcessRuleCreationService? processRuleCreationService = null,
|
|
Action<string>? clipboardSetter = null,
|
|
Action<string>? executableLocationOpener = null,
|
|
IEnhancedLoggingService? enhancedLoggingService = null,
|
|
IActivityAuditService? activityAuditService = null,
|
|
IVirtualizedProcessService? virtualizedProcessService = null)
|
|
{
|
|
if (virtualizedProcessService == null)
|
|
{
|
|
var virtualizedProcessServiceMock = new Mock<IVirtualizedProcessService>(MockBehavior.Loose);
|
|
virtualizedProcessServiceMock.SetupProperty(
|
|
service => service.Configuration,
|
|
new VirtualizedProcessConfig());
|
|
virtualizedProcessService = virtualizedProcessServiceMock.Object;
|
|
}
|
|
|
|
var cpuTopologyService = new Mock<ICpuTopologyService>(MockBehavior.Loose);
|
|
var powerPlanService = new Mock<IPowerPlanService>(MockBehavior.Loose);
|
|
var notificationService = new Mock<INotificationService>(MockBehavior.Loose);
|
|
var systemTrayService = new Mock<ISystemTrayService>(MockBehavior.Loose);
|
|
var coreMaskService = new Mock<ICoreMaskService>(MockBehavior.Loose);
|
|
var associationService = new Mock<IProcessPowerPlanAssociationService>(MockBehavior.Loose);
|
|
var gameModeService = new Mock<IGameModeService>(MockBehavior.Loose);
|
|
|
|
return new ProcessViewModel(
|
|
NullLogger<ProcessViewModel>.Instance,
|
|
processService,
|
|
new ProcessFilterService(),
|
|
virtualizedProcessService,
|
|
cpuTopologyService.Object,
|
|
powerPlanService.Object,
|
|
notificationService.Object,
|
|
systemTrayService.Object,
|
|
coreMaskService.Object,
|
|
associationService.Object,
|
|
gameModeService.Object,
|
|
processAffinityApplyCoordinator: processAffinityApplyCoordinator,
|
|
enhancedLoggingService: enhancedLoggingService,
|
|
activityAuditService: activityAuditService,
|
|
memoryPriorityService: memoryPriorityService,
|
|
persistentRuleStore: persistentRuleStore,
|
|
persistentRuleMatcher: new PersistentProcessRuleMatcher(),
|
|
processRuleCreationService: processRuleCreationService,
|
|
clipboardSetter: clipboardSetter,
|
|
executableLocationOpener: executableLocationOpener);
|
|
}
|
|
|
|
private static ProcessModel CreateProcess(
|
|
string name = "Game.exe",
|
|
int processId = 42,
|
|
string path = @"C:\Games\Game.exe",
|
|
ProcessPriorityClass priority = ProcessPriorityClass.Normal,
|
|
long affinity = 0xF)
|
|
=> new()
|
|
{
|
|
ProcessId = processId,
|
|
Name = name,
|
|
ExecutablePath = path,
|
|
CpuUsage = 1.5,
|
|
MemoryUsage = 128 * 1024 * 1024,
|
|
Priority = priority,
|
|
ProcessorAffinity = affinity,
|
|
Classification = ProcessClassification.ForegroundApp,
|
|
};
|
|
|
|
private static ProcessRuleCreationService CreateRuleCreationService(IPersistentProcessRuleStore ruleStore) =>
|
|
new(
|
|
ruleStore,
|
|
topologyProvider: null,
|
|
new CpuSelectionMigrationService(),
|
|
NullLogger<ProcessRuleCreationService>.Instance);
|
|
|
|
private sealed class CapturingRuleStore(IReadOnlyList<PersistentProcessRule>? initialRules = null)
|
|
: IPersistentProcessRuleStore
|
|
{
|
|
public IReadOnlyList<PersistentProcessRule> SavedRules { get; private set; } = initialRules ?? [];
|
|
|
|
public Task<IReadOnlyList<PersistentProcessRule>> LoadAsync() =>
|
|
Task.FromResult(this.SavedRules);
|
|
|
|
public Task SaveAsync(IReadOnlyList<PersistentProcessRule> rules)
|
|
{
|
|
this.SavedRules = rules.ToList();
|
|
return Task.CompletedTask;
|
|
}
|
|
}
|
|
}
|
|
}
|