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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user