9553bfd20d
* perf: defer inactive view initialization * perf: eliminate redundant powercfg refreshes * perf: suspend hidden log updates * perf: back off WMI recovery * perf: reuse static process metadata * test: cover low-overhead runtime policies
82 lines
3.2 KiB
C#
82 lines
3.2 KiB
C#
namespace ThreadPilot.Core.Tests
|
|
{
|
|
using CommunityToolkit.Mvvm.Input;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.Abstractions;
|
|
using Moq;
|
|
using ThreadPilot.Models;
|
|
using ThreadPilot.Services;
|
|
using ThreadPilot.ViewModels;
|
|
|
|
public sealed class LogViewerActivityAuditTests
|
|
{
|
|
[Fact]
|
|
public async Task InitializeAsync_LoadsVisibleThreadPilotActivityEntries()
|
|
{
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
await audit.LogSuccessAsync("Power Plans", "Applied power plan Gaming", "Guid: game");
|
|
var viewModel = CreateViewModel(audit);
|
|
|
|
await viewModel.InitializeAsync();
|
|
|
|
var entry = Assert.Single(viewModel.LogEntries);
|
|
Assert.Equal("Power Plans", entry.Category);
|
|
Assert.Equal("Applied power plan Gaming", entry.Message);
|
|
Assert.Equal(LogLevel.Information, entry.Level);
|
|
Assert.Equal("Guid: game", entry.Details);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ActivityEntryAdded_UpdatesOnlyWhileViewerIsActive()
|
|
{
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
var viewModel = CreateViewModel(audit);
|
|
|
|
await audit.LogInfoAsync("Process", "Hidden entry");
|
|
Assert.Empty(viewModel.LogEntries);
|
|
|
|
await viewModel.SetActiveAsync(true);
|
|
await audit.LogInfoAsync("Process", "Visible entry");
|
|
|
|
Assert.Equal(2, viewModel.LogEntries.Count);
|
|
Assert.Equal("Visible entry", viewModel.LogEntries[0].Message);
|
|
|
|
await viewModel.SetActiveAsync(false);
|
|
await audit.LogInfoAsync("Process", "Another hidden entry");
|
|
Assert.Equal(2, viewModel.LogEntries.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ClearLogsCommand_ClearsOnlyVisibleActivityDisplayWithoutAddingNoise()
|
|
{
|
|
var audit = new ActivityAuditService(NullLogger<ActivityAuditService>.Instance);
|
|
await audit.LogSuccessAsync("Power Plans", "Applied power plan Gaming");
|
|
var viewModel = CreateViewModel(audit);
|
|
await viewModel.InitializeAsync();
|
|
|
|
await ((IAsyncRelayCommand)viewModel.ClearLogsCommand).ExecuteAsync(null);
|
|
|
|
Assert.Empty(viewModel.LogEntries);
|
|
Assert.Single(await audit.GetEntriesAsync());
|
|
}
|
|
|
|
private static LogViewerViewModel CreateViewModel(IActivityAuditService audit)
|
|
{
|
|
var logging = new Mock<IEnhancedLoggingService>(MockBehavior.Loose);
|
|
logging
|
|
.Setup(service => service.GetLogStatisticsAsync())
|
|
.ReturnsAsync(new LogFileStatistics());
|
|
var settings = new Mock<IApplicationSettingsService>(MockBehavior.Loose);
|
|
settings
|
|
.SetupGet(service => service.Settings)
|
|
.Returns(new ApplicationSettingsModel());
|
|
|
|
return new LogViewerViewModel(
|
|
audit,
|
|
logging.Object,
|
|
settings.Object,
|
|
NullLogger<LogViewerViewModel>.Instance);
|
|
}
|
|
}
|
|
}
|