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
19 changes: 14 additions & 5 deletions SysManager/SysManager.Tests/AboutViewModelTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ namespace SysManager.Tests;

public class AboutViewModelTests
{
/// <summary>
/// Builds an AboutViewModel WITHOUT the startup update-check, so default-state
/// assertions don't race the constructor's async network fetch (which populates
/// UpdateStatus / LatestNotes / LatestVersionLabel / LatestPublishedLabel /
/// UpdateAvailable).
/// </summary>
private static AboutViewModel NewVmNoAutoCheck() =>
new(new UpdateService(), new SystemReportService(new SystemInfoService(), new DiskHealthService()), autoCheck: false);

[Fact]
public void Constructs_WithDefaultService()
{
Expand Down Expand Up @@ -50,14 +59,14 @@ public void ReleaseHistory_StartsEmpty()
[Fact]
public void UpdateStatus_HasInitialMessage()
{
var vm = new AboutViewModel();
var vm = NewVmNoAutoCheck();
Assert.False(string.IsNullOrWhiteSpace(vm.UpdateStatus));
}

[Fact]
public void UpdateAvailable_DefaultsFalse()
{
var vm = new AboutViewModel();
var vm = NewVmNoAutoCheck();
Assert.False(vm.UpdateAvailable);
}

Expand Down Expand Up @@ -192,21 +201,21 @@ public async Task CheckForUpdatesCommand_NeverThrows()
[Fact]
public void LatestVersionLabel_DefaultsEmpty()
{
var vm = new AboutViewModel();
var vm = NewVmNoAutoCheck();
Assert.Equal(string.Empty, vm.LatestVersionLabel);
}

[Fact]
public void LatestPublishedLabel_DefaultsEmpty()
{
var vm = new AboutViewModel();
var vm = NewVmNoAutoCheck();
Assert.Equal(string.Empty, vm.LatestPublishedLabel);
}

[Fact]
public void LatestNotes_DefaultsEmpty()
{
var vm = new AboutViewModel();
var vm = NewVmNoAutoCheck();
Assert.Equal(string.Empty, vm.LatestNotes);
}

Expand Down
12 changes: 11 additions & 1 deletion SysManager/SysManager/ViewModels/AboutViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,20 @@ public sealed partial class AboutViewModel : ViewModelBase
public AboutViewModel() : this(new UpdateService(), new SystemReportService(new SystemInfoService(), new DiskHealthService())) { }

public AboutViewModel(UpdateService updates, SystemReportService reportService)
: this(updates, reportService, autoCheck: true) { }

/// <summary>
/// Core constructor. <paramref name="autoCheck"/> controls whether the
/// startup update-check (a live network call that populates the update
/// properties) runs. Production always passes true; tests pass false to
/// assert the constructor's default state without racing the async fetch.
/// </summary>
internal AboutViewModel(UpdateService updates, SystemReportService reportService, bool autoCheck)
{
_updates = updates;
_reportService = reportService;
InitializeAsync(InitAsync);
if (autoCheck)
InitializeAsync(InitAsync);
}

private async Task InitAsync()
Expand Down
Loading