Convert test data sources to typed TheoryData
Replace untyped MemberData sources with TheoryData<...>, use collection expressions for array and list literals, drop redundant casts and null suppressions, and give log-assertion helpers an IsEnabled setup so guarded log calls stay verifiable.
This commit is contained in:
@@ -5,20 +5,13 @@ using Moq;
|
||||
using NetDaemon.HassModel;
|
||||
using NetDaemon.HassModel.Entities;
|
||||
using PowerMonitorManager;
|
||||
using PowerMonitorManager.Models;
|
||||
|
||||
namespace PowerMonitor.Manager.Tests;
|
||||
|
||||
public class PowerSensorDiscoveryServiceTests
|
||||
{
|
||||
private readonly Mock<IHaContext> _haContextMock;
|
||||
private readonly Mock<ILogger<PowerSensorDiscoveryService>> _loggerMock;
|
||||
|
||||
public PowerSensorDiscoveryServiceTests()
|
||||
{
|
||||
_haContextMock = new Mock<IHaContext>();
|
||||
_loggerMock = new Mock<ILogger<PowerSensorDiscoveryService>>();
|
||||
}
|
||||
private readonly Mock<IHaContext> _haContextMock = new();
|
||||
private readonly Mock<ILogger<PowerSensorDiscoveryService>> _loggerMock = new();
|
||||
|
||||
private PowerSensorDiscoveryService CreateSut(
|
||||
string mainMeterEntityId = PowerMonitorTestData.MainMeterEntityId,
|
||||
@@ -47,12 +40,12 @@ public class PowerSensorDiscoveryServiceTests
|
||||
params (string EntityId, string? DeviceClass, string? Unit, string? FriendlyName)[] entities) =>
|
||||
_haContextMock
|
||||
.Setup(h => h.GetAllEntities())
|
||||
.Returns(entities.Select(entity => SetupEntity(entity.EntityId, entity.DeviceClass, entity.Unit, entity.FriendlyName)).ToList());
|
||||
.Returns([.. entities.Select(entity => SetupEntity(entity.EntityId, entity.DeviceClass, entity.Unit, entity.FriendlyName))]);
|
||||
|
||||
private void SetupEntitiesWithoutState(params string[] entityIds) =>
|
||||
_haContextMock
|
||||
.Setup(h => h.GetAllEntities())
|
||||
.Returns(entityIds.Select(entityId => new Entity(_haContextMock.Object, entityId)).ToList());
|
||||
.Returns([.. entityIds.Select(entityId => new Entity(_haContextMock.Object, entityId))]);
|
||||
|
||||
#region Discovery
|
||||
|
||||
@@ -346,7 +339,7 @@ public class PowerSensorDiscoveryServiceTests
|
||||
var sut = CreateSut();
|
||||
|
||||
// Act
|
||||
var result = sut.IsPowerSensor(entity);
|
||||
var result = PowerSensorDiscoveryService.IsPowerSensor(entity);
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected, $"scenario: {scenario}");
|
||||
@@ -361,7 +354,7 @@ public class PowerSensorDiscoveryServiceTests
|
||||
var sut = CreateSut();
|
||||
|
||||
// Act
|
||||
var result = sut.IsPowerSensor(entity);
|
||||
var result = PowerSensorDiscoveryService.IsPowerSensor(entity);
|
||||
|
||||
// Assert
|
||||
result.Should().BeFalse();
|
||||
|
||||
Reference in New Issue
Block a user