Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Configuration/ProcessPowerPlanAssociations.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"DefaultPowerPlanGuid": "",
"DefaultPowerPlanName": "",
"IsEventBasedMonitoringEnabled": true,
"IsFallbackPollingEnabled": true,
"PollingIntervalSeconds": 5,
"PreventDuplicatePowerPlanChanges": true,
"PowerPlanChangeDelayMs": 250,
"Associations": [
Expand Down
14 changes: 0 additions & 14 deletions Models/ProcessMonitorConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@ public partial class ProcessMonitorConfiguration : ObservableObject
[ObservableProperty]
private string defaultPowerPlanName = string.Empty;

[ObservableProperty]
private bool isEventBasedMonitoringEnabled = true;

[ObservableProperty]
private bool isFallbackPollingEnabled = true;

[ObservableProperty]
private int pollingIntervalSeconds = 5;

[ObservableProperty]
private bool preventDuplicatePowerPlanChanges = true;

Expand Down Expand Up @@ -95,11 +86,6 @@ public List<string> Validate()
{
var errors = new List<string>();

if (this.PollingIntervalSeconds < 1)
{
errors.Add("Polling interval must be at least 1 second");
}

if (this.PowerPlanChangeDelayMs < 0)
{
errors.Add("Power plan change delay cannot be negative");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace ThreadPilot.Core.Tests
{
using System.Text.Json;
using ThreadPilot.Models;

public sealed class ProcessMonitorConfigurationTests
{
[Fact]
public void LegacyMonitoringFields_AreIgnoredWhenConfigurationIsDeserialized()
{
const string json = """
{
"isEventBasedMonitoringEnabled": false,
"isFallbackPollingEnabled": false,
"pollingIntervalSeconds": 1,
"preventDuplicatePowerPlanChanges": false
}
""";

var configuration = JsonSerializer.Deserialize<ProcessMonitorConfiguration>(json, new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
});

Assert.NotNull(configuration);
Assert.False(configuration.PreventDuplicatePowerPlanChanges);
}

[Theory]
[InlineData("IsEventBasedMonitoringEnabled")]
[InlineData("IsFallbackPollingEnabled")]
[InlineData("PollingIntervalSeconds")]
public void DoesNotExposeDuplicateMonitoringProperties(string propertyName)
{
Assert.Null(typeof(ProcessMonitorConfiguration).GetProperty(propertyName));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
namespace ThreadPilot.Core.Tests
{
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using ThreadPilot.Models;
using ThreadPilot.Services;

public sealed class ProcessMonitorServiceSettingsTests
{
[Fact]
public async Task StartMonitoringAsync_WhenWmiDisabled_DoesNotReportWmiAsAvailable()
{
using var monitor = CreateMonitor(new ApplicationSettingsModel
{
EnableWmiMonitoring = false,
EnableFallbackPolling = false,
});

await monitor.StartMonitoringAsync();

Assert.False(monitor.IsWmiAvailable);
}

[Fact]
public async Task StartMonitoringAsync_WhenFallbackDisabled_DoesNotActivateFallbackWhenWmiIsDisabled()
{
using var monitor = CreateMonitor(new ApplicationSettingsModel
{
EnableWmiMonitoring = false,
EnableFallbackPolling = false,
});

await monitor.StartMonitoringAsync();

Assert.False(monitor.IsFallbackPollingActive);
}

[Fact]
public async Task StartMonitoringAsync_UsesFallbackPollingIntervalFromApplicationSettings()
{
using var monitor = CreateMonitor(new ApplicationSettingsModel
{
EnableWmiMonitoring = false,
EnableFallbackPolling = true,
FallbackPollingIntervalMs = 12345,
});
var messages = new List<string?>();
monitor.MonitoringStatusChanged += (_, status) => messages.Add(status.StatusMessage);

await monitor.StartMonitoringAsync();

Assert.True(monitor.IsFallbackPollingActive);
Assert.Contains("Fallback polling started (interval: 12345ms)", messages);
}

private static ProcessMonitorService CreateMonitor(ApplicationSettingsModel settings)
{
var processService = new Mock<IProcessService>(MockBehavior.Strict);
processService.Setup(service => service.GetProcessesAsync())
.ReturnsAsync(new System.Collections.ObjectModel.ObservableCollection<ProcessModel>());
var settingsService = new Mock<IApplicationSettingsService>(MockBehavior.Strict);
settingsService.SetupGet(service => service.Settings).Returns(settings);
return new ProcessMonitorService(
processService.Object,
settingsService.Object,
NullLogger<ProcessMonitorService>.Instance);
}
}
}
18 changes: 0 additions & 18 deletions ViewModels/ProcessPowerPlanAssociationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,6 @@ public partial class ProcessPowerPlanAssociationViewModel : BaseViewModel
[ObservableProperty]
private PowerPlanModel? defaultPowerPlan;

[ObservableProperty]
private bool isMonitoringEnabled = true;

[ObservableProperty]
private bool isEventBasedMonitoringEnabled = true;

[ObservableProperty]
private bool isFallbackPollingEnabled = true;

[ObservableProperty]
private int pollingIntervalSeconds = 5;

[ObservableProperty]
private bool preventDuplicatePowerPlanChanges = true;

Expand Down Expand Up @@ -182,9 +170,6 @@ public async Task LoadDataAsync()

// Load configuration settings
var config = this.associationService.Configuration;
this.IsEventBasedMonitoringEnabled = config.IsEventBasedMonitoringEnabled;
this.IsFallbackPollingEnabled = config.IsFallbackPollingEnabled;
this.PollingIntervalSeconds = config.PollingIntervalSeconds;
this.PreventDuplicatePowerPlanChanges = config.PreventDuplicatePowerPlanChanges;
this.PowerPlanChangeDelayMs = config.PowerPlanChangeDelayMs;

Expand Down Expand Up @@ -391,9 +376,6 @@ public async Task SaveConfigurationAsync()

// Update configuration with current settings
var config = this.associationService.Configuration;
config.IsEventBasedMonitoringEnabled = this.IsEventBasedMonitoringEnabled;
config.IsFallbackPollingEnabled = this.IsFallbackPollingEnabled;
config.PollingIntervalSeconds = this.PollingIntervalSeconds;
config.PreventDuplicatePowerPlanChanges = this.PreventDuplicatePowerPlanChanges;
config.PowerPlanChangeDelayMs = this.PowerPlanChangeDelayMs;

Expand Down
15 changes: 0 additions & 15 deletions Views/ProcessPowerPlanAssociationView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,6 @@
<!-- Automation Monitoring Settings -->
<GroupBox Header="{DynamicResource ProcessPowerPlanAssociationView_SettingsTitle}" Margin="0,0,0,15">
<StackPanel>
<CheckBox Content="{DynamicResource ProcessPowerPlanAssociationView_EnableWmi}"
IsChecked="{Binding IsEventBasedMonitoringEnabled}"
Margin="0,0,0,10"/>

<CheckBox Content="{DynamicResource ProcessPowerPlanAssociationView_EnableFallback}"
IsChecked="{Binding IsFallbackPollingEnabled}"
Margin="0,0,0,10"/>

<StackPanel Orientation="Horizontal" Margin="0,0,0,10">
<TextBlock Text="{DynamicResource ProcessPowerPlanAssociationView_PollingInterval}"
VerticalAlignment="Center" Margin="0,0,10,0"/>
<TextBox Text="{Binding PollingIntervalSeconds}"
Width="60" Padding="5"/>
</StackPanel>

<CheckBox Content="{DynamicResource ProcessPowerPlanAssociationView_PreventDuplicates}"
IsChecked="{Binding PreventDuplicatePowerPlanChanges}"
Margin="0,0,0,10"/>
Expand Down
Loading