Clear the residual Qodana findings
- Drop the leftover unused using, parameter and date-time attribute reader - Merge the remaining enum guard into its pattern - Make the NordPool price DTO init-only - Replace the four non-serializable theory matrices with single tests that iterate the same rows, so xUnit can still report them - Replace Array.Empty with collection expressions and drop unused locals, redundant default arguments and duplicated tuple names - Throw from the unreachable shower default instead of an empty section - Cover the configurable PowerMonitor option overrides in a test so the init setters have a caller
This commit is contained in:
@@ -667,50 +667,46 @@ public class NordPoolPriceServiceTests
|
||||
|
||||
#region ShouldFetchNewPrices
|
||||
|
||||
private static NordPoolPrice CreatePrices(params double?[] values) => new()
|
||||
{
|
||||
Prices = [.. values.Select(price => new NordPoolDayPrice { Price = price })]
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// so the "tomorrow missing" cases are covered separately below). xUnit cannot serialize
|
||||
/// <see cref="NordPoolPrice"/> rows, so the matrix runs inside a single test.
|
||||
/// </summary>
|
||||
public static TheoryData<string, DateOnly?, NordPoolPrice?, NordPoolPrice?, bool> ShouldFetchScenarios()
|
||||
[Fact]
|
||||
public void ShouldFetchNewPrices_ShouldMatchScenario()
|
||||
{
|
||||
var data = new TheoryData<string, DateOnly?, NordPoolPrice?, NordPoolPrice?, bool>();
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
|
||||
static NordPoolPrice Prices(params double?[] values) => new()
|
||||
(string Scenario, DateOnly? LastFetchedDate, NordPoolPrice? TodayPrice, NordPoolPrice? TomorrowPrice, bool Expected)[] cases =
|
||||
[
|
||||
("no fetch date yet", null, CreatePrices(12.50), CreatePrices(18.71), true),
|
||||
("last fetch was yesterday", today.AddDays(-1), CreatePrices(12.50), CreatePrices(18.71), true),
|
||||
("last fetch date is in the future", today.AddDays(1), CreatePrices(12.50), CreatePrices(18.71), false),
|
||||
("today prices are null", today, new NordPoolPrice { Prices = null }, CreatePrices(18.71), true),
|
||||
("today prices are empty", today, new NordPoolPrice { Prices = [] }, CreatePrices(18.71), true),
|
||||
("today and tomorrow prices present", today, CreatePrices(12.50), CreatePrices(18.71), false),
|
||||
("price values are null but entries exist", today, CreatePrices((double?)null), CreatePrices((double?)null), false),
|
||||
("all price payloads are null", today, null, null, true)
|
||||
];
|
||||
|
||||
foreach (var (scenario, lastFetchedDate, todayPrice, tomorrowPrice, expected) in cases)
|
||||
{
|
||||
Prices = [.. values.Select(price => new NordPoolDayPrice { Price = price })]
|
||||
};
|
||||
// Arrange
|
||||
_sut.LastFetchedDate = lastFetchedDate;
|
||||
_sut.TodayNordPoolPrice = todayPrice;
|
||||
_sut.TomorrowNordPoolPrice = tomorrowPrice;
|
||||
|
||||
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;
|
||||
}
|
||||
// Act
|
||||
var result = _sut.ShouldFetchNewPrices(DateOnly.FromDateTime(DateTime.Now));
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(ShouldFetchScenarios))]
|
||||
public void ShouldFetchNewPrices_ShouldMatchScenario(
|
||||
string scenario,
|
||||
DateOnly? lastFetchedDate,
|
||||
NordPoolPrice? todayPrice,
|
||||
NordPoolPrice? tomorrowPrice,
|
||||
bool expected)
|
||||
{
|
||||
// Arrange
|
||||
_sut.LastFetchedDate = lastFetchedDate;
|
||||
_sut.TodayNordPoolPrice = todayPrice;
|
||||
_sut.TomorrowNordPoolPrice = tomorrowPrice;
|
||||
|
||||
// Act
|
||||
var result = _sut.ShouldFetchNewPrices(DateOnly.FromDateTime(DateTime.Now));
|
||||
|
||||
// Assert
|
||||
result.Should().Be(expected, $"scenario: {scenario}");
|
||||
// Assert
|
||||
result.Should().Be(expected, $"scenario: {scenario}");
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -782,35 +778,32 @@ public class NordPoolPriceServiceTests
|
||||
_sut.LastFetchedDate.Should().Be(today);
|
||||
}
|
||||
|
||||
public static TheoryData<NordPoolPrice?> UnusableTomorrowPrices => new()
|
||||
/// <summary>
|
||||
/// Rows are not serializable as theory data, so the three unusable payloads are exercised in one test.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void RollOverPrices_WithoutUsableTomorrowPrices_ShouldResetTodayToEmptyPrice()
|
||||
{
|
||||
{ null },
|
||||
{ new NordPoolPrice { Prices = null } },
|
||||
{ new NordPoolPrice { Prices = [] } }
|
||||
};
|
||||
NordPoolPrice?[] unusablePrices = [null, new() { Prices = null }, new() { Prices = [] }];
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(UnusableTomorrowPrices))]
|
||||
public void RollOverPrices_WithoutUsableTomorrowPrices_ShouldResetTodayToEmptyPrice(NordPoolPrice? tomorrow)
|
||||
{
|
||||
// Arrange
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice
|
||||
foreach (var tomorrow in unusablePrices)
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
|
||||
};
|
||||
_sut.TomorrowNordPoolPrice = tomorrow;
|
||||
_sut.DayQuartersIndex = 42;
|
||||
var today = new DateOnly(2026, 4, 1);
|
||||
// Arrange
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = [new() { Price = 12.50 }] };
|
||||
_sut.TomorrowNordPoolPrice = tomorrow;
|
||||
_sut.DayQuartersIndex = 42;
|
||||
var today = new DateOnly(2026, 4, 1);
|
||||
|
||||
// Act
|
||||
_sut.RollOverPrices(today);
|
||||
// Act
|
||||
_sut.RollOverPrices(today);
|
||||
|
||||
// Assert — nothing usable to promote, so today becomes an empty payload
|
||||
_sut.TodayNordPoolPrice.Should().NotBeNull();
|
||||
_sut.TodayNordPoolPrice!.Prices.Should().BeNull();
|
||||
_sut.TomorrowNordPoolPrice.Should().BeNull();
|
||||
_sut.DayQuartersIndex.Should().Be(-1);
|
||||
_sut.LastFetchedDate.Should().Be(today);
|
||||
// Assert — nothing usable to promote, so today becomes an empty payload
|
||||
_sut.TodayNordPoolPrice.Should().NotBeNull();
|
||||
_sut.TodayNordPoolPrice!.Prices.Should().BeNull();
|
||||
_sut.TomorrowNordPoolPrice.Should().BeNull();
|
||||
_sut.DayQuartersIndex.Should().Be(-1);
|
||||
_sut.LastFetchedDate.Should().Be(today);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
Reference in New Issue
Block a user