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
@@ -316,7 +316,7 @@ public class NordPoolPriceServiceTests
};
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
result.Should().NotBeNull();
@@ -341,7 +341,7 @@ public class NordPoolPriceServiceTests
};
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
result.Should().NotBeNull();
@@ -356,7 +356,7 @@ public class NordPoolPriceServiceTests
var inputPrice = new NordPoolPrice { Prices = null };
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
result.Should().NotBeNull();
@@ -380,7 +380,7 @@ public class NordPoolPriceServiceTests
};
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
result.Should().NotBeNull();
@@ -395,7 +395,7 @@ public class NordPoolPriceServiceTests
var inputPrice = new NordPoolPrice { Prices = new List<NordPoolDayPrice>() };
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
result.Should().NotBeNull();
@@ -417,7 +417,7 @@ public class NordPoolPriceServiceTests
};
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
result.Should().NotBeNull();
@@ -437,7 +437,7 @@ public class NordPoolPriceServiceTests
};
// Act
var result = _sut.AdjustedNordPoolPrice(inputPrice);
var result = NordPoolPriceService.AdjustedNordPoolPrice(inputPrice);
// Assert
inputPrice.Prices[0].Price.Should().Be(81.0);
@@ -627,7 +627,7 @@ public class NordPoolPriceServiceTests
// Arrange
var index = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
var prices = Enumerable.Range(0, NordPoolConsts.MaxDailyIntervals)
.Select(i => new NordPoolDayPrice { Price = 99.0 })
.Select(_ => new NordPoolDayPrice { Price = 99.0 })
.ToList();
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
@@ -671,23 +671,25 @@ public class NordPoolPriceServiceTests
/// Scenarios that do not depend on the time of day (tomorrow's prices are published after 13:00,
/// so the "tomorrow missing" cases are covered separately below).
/// </summary>
public static IEnumerable<object?[]> ShouldFetchScenarios()
public static TheoryData<string, DateOnly?, NordPoolPrice?, NordPoolPrice?, bool> ShouldFetchScenarios()
{
var data = new TheoryData<string, DateOnly?, NordPoolPrice?, NordPoolPrice?, bool>();
var today = DateOnly.FromDateTime(DateTime.Now);
static NordPoolPrice Prices(params double?[] values) => new()
{
Prices = values.Select(price => new NordPoolDayPrice { Price = price }).ToList()
Prices = [.. values.Select(price => new NordPoolDayPrice { Price = price })]
};
yield return ["no fetch date yet", (DateOnly?)null, Prices(12.50), Prices(18.71), true];
yield return ["last fetch was yesterday", today.AddDays(-1), Prices(12.50), Prices(18.71), true];
yield return ["last fetch date is in the future", today.AddDays(1), Prices(12.50), Prices(18.71), false];
yield return ["today prices are null", today, new NordPoolPrice { Prices = null }, Prices(18.71), true];
yield return ["today prices are empty", today, new NordPoolPrice { Prices = [] }, Prices(18.71), true];
yield return ["today and tomorrow prices present", today, Prices(12.50), Prices(18.71), false];
yield return ["price values are null but entries exist", today, Prices((double?)null), Prices((double?)null), false];
yield return ["all price payloads are null", today, (NordPoolPrice?)null, (NordPoolPrice?)null, true];
data.Add("no fetch date yet", null, Prices(12.50), Prices(18.71), true);
data.Add("last fetch was yesterday", today.AddDays(-1), Prices(12.50), Prices(18.71), true);
data.Add("last fetch date is in the future", today.AddDays(1), Prices(12.50), Prices(18.71), false);
data.Add("today prices are null", today, new NordPoolPrice { Prices = null }, Prices(18.71), true);
data.Add("today prices are empty", today, new NordPoolPrice { Prices = [] }, Prices(18.71), true);
data.Add("today and tomorrow prices present", today, Prices(12.50), Prices(18.71), false);
data.Add("price values are null but entries exist", today, Prices((double?)null), Prices((double?)null), false);
data.Add("all price payloads are null", today, null, null, true);
return data;
}
[Theory]
@@ -780,12 +782,12 @@ public class NordPoolPriceServiceTests
_sut.LastFetchedDate.Should().Be(today);
}
public static IEnumerable<object?[]> UnusableTomorrowPrices =>
[
[null],
[new NordPoolPrice { Prices = null }],
[new NordPoolPrice { Prices = [] }]
];
public static TheoryData<NordPoolPrice?> UnusableTomorrowPrices => new()
{
{ null },
{ new NordPoolPrice { Prices = null } },
{ new NordPoolPrice { Prices = [] } }
};
[Theory]
[MemberData(nameof(UnusableTomorrowPrices))]