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
12 changes: 12 additions & 0 deletions src/Daqifi.Core.Tests/Firmware/FirmwareUpdateServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,18 @@ namespace Daqifi.Core.Tests.Firmware;

public class FirmwareUpdateServiceTests
{
[Fact]
public void Constructor_WithoutLogger_UsesNullLogger_DoesNotThrow()
{
// #340: the service is usable without wiring a logger (falls back to NullLogger).
var ex = Record.Exception(() => new FirmwareUpdateService(
new FakeHidTransport(),
new FakeFirmwareDownloadService(),
new FakeExternalProcessRunner()));

Assert.Null(ex);
}

[Fact]
public async Task UpdateFirmwareAsync_HappyPath_TransitionsThroughExpectedStatesAndReportsProgress()
{
Expand Down
15 changes: 9 additions & 6 deletions src/Daqifi.Core/Firmware/FirmwareUpdateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Daqifi.Core.Device;
using Daqifi.Core.Device.Discovery;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Daqifi.Core.Firmware;

Expand Down Expand Up @@ -143,16 +144,18 @@ private static readonly IReadOnlySet<FirmwareUpdateState> CleanupEligibleStates
private bool _disposed;

/// <summary>
/// Initializes a new firmware update service. <paramref name="usbLocationProvider"/> resolves
/// an enumerated bootloader's USB physical-location key when targeting by
/// <c>targetLocationKey</c>; when null, a platform-default provider is used (Windows → WMI,
/// others → no-op fallback, which makes location-key targeting a no-op).
/// Initializes a new firmware update service. The optional <paramref name="logger"/> defaults to
/// a no-op logger (<see cref="NullLogger{T}.Instance"/>) when omitted, so the service is usable
/// without wiring up logging. <paramref name="usbLocationProvider"/> resolves an enumerated
/// bootloader's USB physical-location key when targeting by <c>targetLocationKey</c>; when null,
/// a platform-default provider is used (Windows → WMI, others → no-op fallback, which makes
/// location-key targeting a no-op).
/// </summary>
public FirmwareUpdateService(
IHidTransport hidTransport,
IFirmwareDownloadService firmwareDownloadService,
IExternalProcessRunner externalProcessRunner,
ILogger<FirmwareUpdateService> logger,
ILogger<FirmwareUpdateService>? logger = null,
IBootloaderProtocol? bootloaderProtocol = null,
IHidDeviceEnumerator? hidDeviceEnumerator = null,
FirmwareUpdateServiceOptions? options = null,
Expand All @@ -161,7 +164,7 @@ public FirmwareUpdateService(
_hidTransport = hidTransport ?? throw new ArgumentNullException(nameof(hidTransport));
FirmwareDownloadService = firmwareDownloadService ?? throw new ArgumentNullException(nameof(firmwareDownloadService));
_externalProcessRunner = externalProcessRunner ?? throw new ArgumentNullException(nameof(externalProcessRunner));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_logger = logger ?? NullLogger<FirmwareUpdateService>.Instance;
_bootloaderProtocol = bootloaderProtocol ?? new Pic32BootloaderProtocol();
_hidDeviceEnumerator = hidDeviceEnumerator ?? new HidLibraryDeviceEnumerator();
_options = options ?? new FirmwareUpdateServiceOptions();
Expand Down