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:
2026-11-29 21:42:41 +02:00
parent ada3c77778
commit 17774b40b8
31 changed files with 649 additions and 693 deletions
@@ -21,6 +21,7 @@ public class LeakMonitorInitTests
public LeakMonitorInitTests()
{
_haContextMock.Setup(h => h.StateAllChanges()).Returns(_stateChanges);
_loggerMock.Setup(l => l.IsEnabled(It.IsAny<LogLevel>())).Returns(true);
}
private LeakMonitorInit CreateSut(LeakMonitorOptions? options = null)
@@ -40,14 +41,12 @@ public class LeakMonitorInitTests
private void VerifyLogged(LogLevel level, Times times)
{
_loggerMock.Verify(
l => l.Log(
level,
It.IsAny<EventId>(),
It.IsAny<It.IsAnyType>(),
It.IsAny<Exception?>(),
It.IsAny<Func<It.IsAnyType, Exception?, string>>()),
times);
var logCount = _loggerMock.Invocations.Count(invocation =>
invocation.Method.Name == nameof(ILogger.Log) &&
invocation.Arguments[0] is LogLevel loggedLevel &&
loggedLevel == level);
times.Validate(logCount);
}
#region HandleStateChange
@@ -170,7 +169,7 @@ public class LeakMonitorInitTests
[MemberData(nameof(LeakMonitorTestData.BlankSensorIds), MemberType = typeof(LeakMonitorTestData))]
public void InitializeAsync_WithBlankSensorId_ShouldStillSubscribeAndForward(string sensorEntityId)
{
var sut = CreateSut(LeakMonitorTestData.CreateOptions(sensorEntityIds: [sensorEntityId]));
CreateSut(LeakMonitorTestData.CreateOptions(sensorEntityIds: [sensorEntityId]));
_stateChanges.SubscriptionCount.Should().Be(1);