- Download and apply are separate steps: applying first ends the elevated session and waits for the Elevator to exit (it runs from the folder Velopack replaces, and the non-elevated updater can't kill it or overwrite its locked files), and a command started during the download postpones the restart instead of being killed halfway. - UpdateErrorMapper.Map(Exception) looks through wrapper/aggregate exceptions for the HTTP status; HttpClient timeouts now map to Offline instead of being rethrown as cancellations (which left the dialog stuck on "Checking"). User cancellation is still distinguished. - Closing the update dialog with its title-bar X cancels the download; otherwise it finished in the background and restarted the app, possibly mid-command. - The startup prompt never opens over another dialog; the "command running" guard reads the shared ExecutionViewModel (now a singleton) instead of MainWindow.DataContext. - Settings' "Last checked" only updates when a check actually succeeded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
89 lines
3.1 KiB
C#
89 lines
3.1 KiB
C#
using CommandForge.Application.Ports;
|
|
using CommandForge.Application.UseCases;
|
|
|
|
namespace CommandForge.Tests;
|
|
|
|
/// <summary>
|
|
/// Verifies <see cref="CheckForUpdateUseCase"/> passes results/errors through and surfaces support,
|
|
/// using a hand-rolled fake (no mocking framework, matching the repo's fake style).
|
|
/// </summary>
|
|
public sealed class CheckForUpdateUseCaseTests
|
|
{
|
|
[Fact]
|
|
public async Task ExecuteAsync_ReturnsServiceResult()
|
|
{
|
|
var fake = new FakeUpdateService { Result = UpdateCheckResult.Available("1.2.3") };
|
|
var useCase = new CheckForUpdateUseCase(fake);
|
|
|
|
var result = await useCase.ExecuteAsync(TestContext.Current.CancellationToken);
|
|
|
|
Assert.True(result.HasUpdate);
|
|
Assert.Equal("1.2.3", result.NewVersion);
|
|
Assert.True(result.IsSuccess);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ExecuteAsync_PropagatesError()
|
|
{
|
|
var fake = new FakeUpdateService { Result = UpdateCheckResult.Failed(UpdateError.RateLimited) };
|
|
var useCase = new CheckForUpdateUseCase(fake);
|
|
|
|
var result = await useCase.ExecuteAsync(TestContext.Current.CancellationToken);
|
|
|
|
Assert.False(result.HasUpdate);
|
|
Assert.False(result.IsSuccess);
|
|
Assert.Equal(UpdateError.RateLimited, result.Error);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)]
|
|
[InlineData(false)]
|
|
public void IsSupported_ReflectsService(bool supported)
|
|
{
|
|
var useCase = new CheckForUpdateUseCase(new FakeUpdateService { IsUpdateSupported = supported });
|
|
Assert.Equal(supported, useCase.IsSupported);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DownloadAsync_PropagatesError()
|
|
{
|
|
var fake = new FakeUpdateService { DownloadResult = UpdateError.Offline };
|
|
var useCase = new CheckForUpdateUseCase(fake);
|
|
|
|
var error = await useCase.DownloadAsync(progress: null, TestContext.Current.CancellationToken);
|
|
|
|
Assert.Equal(UpdateError.Offline, error);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ApplyAndRestartAsync_PropagatesError()
|
|
{
|
|
var fake = new FakeUpdateService { ApplyResult = UpdateError.Unknown };
|
|
var useCase = new CheckForUpdateUseCase(fake);
|
|
|
|
var error = await useCase.ApplyAndRestartAsync(TestContext.Current.CancellationToken);
|
|
|
|
Assert.Equal(UpdateError.Unknown, error);
|
|
}
|
|
|
|
private sealed class FakeUpdateService : IUpdateService
|
|
{
|
|
public bool IsUpdateSupported { get; init; } = true;
|
|
|
|
public UpdateCheckResult Result { get; init; } = UpdateCheckResult.UpToDate;
|
|
|
|
public UpdateError DownloadResult { get; init; } = UpdateError.None;
|
|
|
|
public UpdateError ApplyResult { get; init; } = UpdateError.None;
|
|
|
|
public Task<UpdateCheckResult> CheckForUpdatesAsync(CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(Result);
|
|
|
|
public Task<UpdateError> DownloadAsync(IProgress<int>? progress, CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(DownloadResult);
|
|
|
|
public Task<UpdateError> ApplyAndRestartAsync(CancellationToken cancellationToken = default)
|
|
=> Task.FromResult(ApplyResult);
|
|
}
|
|
}
|