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:
@@ -49,20 +49,20 @@ public class CheapestIntervalsFinderTests
|
||||
|
||||
#region FindCheapestIntervals
|
||||
|
||||
public static IEnumerable<object[]> FilteringCases =>
|
||||
[
|
||||
["deadline includes interval ending exactly at it", new[] { 4.93, 5.63, 6.20 }, 10, double.MaxValue, 1_800.0, 2],
|
||||
["deadline excludes interval ending one second late", new[] { 4.93, 5.63, 6.20 }, 10, double.MaxValue, 1_799.0, 1],
|
||||
["deadline before first interval", new[] { 4.93, 5.63, 6.20 }, 10, double.MaxValue, -1.0, 0],
|
||||
["price cap is inclusive", new[] { 12.50, 12.51 }, 10, 12.50, 86_400.0, 1],
|
||||
["zero price cap keeps non-positive prices", new[] { -1.50, 0.0, 0.01, 2.0 }, 10, 0.0, 86_400.0, 2],
|
||||
["all prices above cap", new[] { 17.91, 24.92, 22.44 }, 4, 10.0, 86_400.0, 0],
|
||||
["fewer available than requested", new[] { 6.20, 8.96 }, 10, double.MaxValue, 86_400.0, 2],
|
||||
["zero intervals requested", new[] { 17.91, 6.20 }, 0, double.MaxValue, 86_400.0, 0],
|
||||
["negative intervals requested", new[] { 17.91, 6.20 }, -1, double.MaxValue, 86_400.0, 0],
|
||||
["deadline and price cap combined", new[] { 17.91, 6.20, 12.50, 4.93, 8.96, 2.50 }, 2, 10.0, 4_500.0, 2],
|
||||
["all prices equal", new[] { 12.50, 12.50, 12.50, 12.50, 12.50 }, 3, double.MaxValue, 86_400.0, 3]
|
||||
];
|
||||
public static TheoryData<string, double[], int, double, double, int> FilteringCases => new()
|
||||
{
|
||||
{ "deadline includes interval ending exactly at it", [4.93, 5.63, 6.20], 10, double.MaxValue, 1_800.0, 2 },
|
||||
{ "deadline excludes interval ending one second late", [4.93, 5.63, 6.20], 10, double.MaxValue, 1_799.0, 1 },
|
||||
{ "deadline before first interval", [4.93, 5.63, 6.20], 10, double.MaxValue, -1.0, 0 },
|
||||
{ "price cap is inclusive", [12.50, 12.51], 10, 12.50, 86_400.0, 1 },
|
||||
{ "zero price cap keeps non-positive prices", [-1.50, 0.0, 0.01, 2.0], 10, 0.0, 86_400.0, 2 },
|
||||
{ "all prices above cap", [17.91, 24.92, 22.44], 4, 10.0, 86_400.0, 0 },
|
||||
{ "fewer available than requested", [6.20, 8.96], 10, double.MaxValue, 86_400.0, 2 },
|
||||
{ "zero intervals requested", [17.91, 6.20], 0, double.MaxValue, 86_400.0, 0 },
|
||||
{ "negative intervals requested", [17.91, 6.20], -1, double.MaxValue, 86_400.0, 0 },
|
||||
{ "deadline and price cap combined", [17.91, 6.20, 12.50, 4.93, 8.96, 2.50], 2, 10.0, 4_500.0, 2 },
|
||||
{ "all prices equal", [12.50, 12.50, 12.50, 12.50, 12.50], 3, double.MaxValue, 86_400.0, 3 }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(FilteringCases))]
|
||||
@@ -304,19 +304,19 @@ public class CheapestIntervalsFinderTests
|
||||
|
||||
#region IsCurrentIntervalCheap
|
||||
|
||||
public static IEnumerable<object[]> CurrentIntervalCases =>
|
||||
[
|
||||
["inside interval", 10 * Hour + 7 * 60, new[] { Interval(10 * Hour, 10 * Hour + Quarter) }, true],
|
||||
["exactly at start", 10 * Hour, new[] { Interval(10 * Hour, 10 * Hour + Quarter) }, true],
|
||||
["exactly at end", 10 * Hour + Quarter, new[] { Interval(10 * Hour, 10 * Hour + Quarter) }, false],
|
||||
["outside all intervals", 12 * Hour, new[] { Interval(10 * Hour, 10 * Hour + Quarter), Interval(14 * Hour, 14 * Hour + Quarter) }, false],
|
||||
["boundary between adjacent intervals", 10 * Hour + Quarter, new[] { Interval(10 * Hour, 10 * Hour + Quarter, price: 8.96, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, price: 6.20, rank: 2) }, true],
|
||||
["unsorted intervals", 14 * Hour + 5 * 60, new[] { Interval(14 * Hour, 14 * Hour + Quarter, price: 4.93, rank: 2), Interval(10 * Hour, 10 * Hour + Quarter, price: 6.20, rank: 1) }, true],
|
||||
["before first interval", 10 * Hour - 1, new[] { Interval(10 * Hour, 10 * Hour + Quarter) }, false],
|
||||
["in gap between intervals", 10 * Hour + 2 * Quarter, new[] { Interval(10 * Hour, 10 * Hour + Quarter), Interval(11 * Hour, 11 * Hour + Quarter) }, false],
|
||||
["middle of three consecutive intervals", 10 * Hour + Quarter + 5 * 60, new[] { Interval(10 * Hour, 10 * Hour + Quarter, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, rank: 2), Interval(10 * Hour + 2 * Quarter, 10 * Hour + 3 * Quarter, rank: 3) }, true],
|
||||
["empty interval list", 12 * Hour, Array.Empty<CheapestIntervalResult>(), false]
|
||||
];
|
||||
public static TheoryData<string, int, CheapestIntervalResult[], bool> CurrentIntervalCases => new()
|
||||
{
|
||||
{ "inside interval", 10 * Hour + 7 * 60, [Interval(10 * Hour, 10 * Hour + Quarter)], true },
|
||||
{ "exactly at start", 10 * Hour, [Interval(10 * Hour, 10 * Hour + Quarter)], true },
|
||||
{ "exactly at end", 10 * Hour + Quarter, [Interval(10 * Hour, 10 * Hour + Quarter)], false },
|
||||
{ "outside all intervals", 12 * Hour, [Interval(10 * Hour, 10 * Hour + Quarter), Interval(14 * Hour, 14 * Hour + Quarter)], false },
|
||||
{ "boundary between adjacent intervals", 10 * Hour + Quarter, [Interval(10 * Hour, 10 * Hour + Quarter, price: 8.96, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, price: 6.20, rank: 2)], true },
|
||||
{ "unsorted intervals", 14 * Hour + 5 * 60, [Interval(14 * Hour, 14 * Hour + Quarter, price: 4.93, rank: 2), Interval(10 * Hour, 10 * Hour + Quarter, price: 6.20, rank: 1)], true },
|
||||
{ "before first interval", 10 * Hour - 1, [Interval(10 * Hour, 10 * Hour + Quarter)], false },
|
||||
{ "in gap between intervals", 10 * Hour + 2 * Quarter, [Interval(10 * Hour, 10 * Hour + Quarter), Interval(11 * Hour, 11 * Hour + Quarter)], false },
|
||||
{ "middle of three consecutive intervals", 10 * Hour + Quarter + 5 * 60, [Interval(10 * Hour, 10 * Hour + Quarter, rank: 1), Interval(10 * Hour + Quarter, 10 * Hour + 2 * Quarter, rank: 2), Interval(10 * Hour + 2 * Quarter, 10 * Hour + 3 * Quarter, rank: 3)], true },
|
||||
{ "empty interval list", 12 * Hour, [], false }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(CurrentIntervalCases))]
|
||||
|
||||
@@ -161,17 +161,17 @@ public class CompactNordPoolDayPriceTests
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
public static IEnumerable<object[]> InvalidJsonPayloads =>
|
||||
[
|
||||
["empty array", "[]"],
|
||||
["too few elements", "[1,2]"],
|
||||
["extra elements", "[1,2,3,4]"],
|
||||
["missing end of array", "[1,2,3"],
|
||||
["non-numeric start", "[\"abc\",2,3]"],
|
||||
["non-numeric end", "[1,\"abc\",3]"],
|
||||
["non-numeric price", "[1,2,\"abc\"]"],
|
||||
["object instead of array", "{\"start\":1}"]
|
||||
];
|
||||
public static TheoryData<string, string> InvalidJsonPayloads => new()
|
||||
{
|
||||
{ "empty array", "[]" },
|
||||
{ "too few elements", "[1,2]" },
|
||||
{ "extra elements", "[1,2,3,4]" },
|
||||
{ "missing end of array", "[1,2,3" },
|
||||
{ "non-numeric start", "[\"abc\",2,3]" },
|
||||
{ "non-numeric end", "[1,\"abc\",3]" },
|
||||
{ "non-numeric price", "[1,2,\"abc\"]" },
|
||||
{ "object instead of array", "{\"start\":1}" }
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[MemberData(nameof(InvalidJsonPayloads))]
|
||||
@@ -249,7 +249,7 @@ public class CompactNordPoolDayPriceTests
|
||||
var roundTripped = JsonSerializer.Deserialize<List<CompactNordPoolDayPrice>>(json);
|
||||
|
||||
roundTripped.Should().NotBeNull();
|
||||
roundTripped!.Should().HaveCount(compact.Count);
|
||||
roundTripped.Should().HaveCount(compact.Count);
|
||||
roundTripped.Should().BeEquivalentTo(compact);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public class NordPoolEntityServiceTests
|
||||
public void GetInitEntitiesList_ShouldReturnAllEntities()
|
||||
{
|
||||
// Act
|
||||
var result = _sut.GetInitEntitiesList("EUR/kWh");
|
||||
var result = NordPoolEntityService.GetInitEntitiesList("EUR/kWh");
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
@@ -45,7 +45,7 @@ public class NordPoolEntityServiceTests
|
||||
public void GetInitEntitiesList_ShouldHaveCorrectEntityProperties()
|
||||
{
|
||||
// Act
|
||||
var result = _sut.GetInitEntitiesList("EUR/kWh");
|
||||
var result = NordPoolEntityService.GetInitEntitiesList("EUR/kWh");
|
||||
|
||||
// Assert
|
||||
var entity = result.First(e => e.EntityId == "sensor.nordpool_current_price");
|
||||
@@ -58,7 +58,7 @@ public class NordPoolEntityServiceTests
|
||||
public void GetInitEntitiesList_CurrentPriceEntity_ShouldHaveMonetaryDeviceClassConfig()
|
||||
{
|
||||
// Act
|
||||
var result = _sut.GetInitEntitiesList("EUR/kWh");
|
||||
var result = NordPoolEntityService.GetInitEntitiesList("EUR/kWh");
|
||||
|
||||
// Assert
|
||||
var currentPriceEntity = result.First(e => e.EntityId == "sensor.nordpool_current_price");
|
||||
@@ -72,7 +72,7 @@ public class NordPoolEntityServiceTests
|
||||
public void GetInitEntitiesList_ShouldContainExpectedDomains()
|
||||
{
|
||||
// Act
|
||||
var result = _sut.GetInitEntitiesList("EUR/kWh");
|
||||
var result = NordPoolEntityService.GetInitEntitiesList("EUR/kWh");
|
||||
|
||||
// Assert
|
||||
result.Should().OnlyContain(e => e.Domain == "sensor" || e.Domain == "button");
|
||||
@@ -82,7 +82,7 @@ public class NordPoolEntityServiceTests
|
||||
public void GetInitEntitiesList_AllEntities_ShouldHaveUniqueEntityIds()
|
||||
{
|
||||
// Act
|
||||
var result = _sut.GetInitEntitiesList("EUR/kWh");
|
||||
var result = NordPoolEntityService.GetInitEntitiesList("EUR/kWh");
|
||||
|
||||
// Assert
|
||||
result.Select(e => e.EntityId).Should().OnlyHaveUniqueItems();
|
||||
@@ -115,12 +115,9 @@ public class NordPoolEntityServiceTests
|
||||
.Returns(() =>
|
||||
{
|
||||
callCount++;
|
||||
if (callCount == 2)
|
||||
{
|
||||
throw new InvalidOperationException("Entity creation failed");
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
return callCount == 2
|
||||
? throw new InvalidOperationException("Entity creation failed")
|
||||
: Task.CompletedTask;
|
||||
});
|
||||
|
||||
// Act
|
||||
@@ -435,13 +432,13 @@ public class NordPoolEntityServiceTests
|
||||
Times.Once);
|
||||
}
|
||||
|
||||
public static IEnumerable<object?[]> MergedPriceScenarios()
|
||||
public static TheoryData<string, NordPoolPrice?, NordPoolPrice?, int> MergedPriceScenarios()
|
||||
{
|
||||
var data = new TheoryData<string, NordPoolPrice?, NordPoolPrice?, int>();
|
||||
var todayStart = new DateTime(2026, 3, 31, 6, 0, 0, DateTimeKind.Utc);
|
||||
var tomorrowStart = new DateTime(2026, 4, 1, 6, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
yield return
|
||||
[
|
||||
data.Add(
|
||||
"today and tomorrow with null-start entry filtered",
|
||||
new NordPoolPrice
|
||||
{
|
||||
@@ -456,27 +453,26 @@ public class NordPoolEntityServiceTests
|
||||
Prices = [new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }]
|
||||
},
|
||||
2
|
||||
];
|
||||
);
|
||||
|
||||
yield return
|
||||
[
|
||||
data.Add(
|
||||
"only today",
|
||||
new NordPoolPrice { Prices = [new NordPoolDayPrice { Start = todayStart, End = todayStart.AddMinutes(15), Price = 17.91 }] },
|
||||
new NordPoolPrice { Prices = [] },
|
||||
1
|
||||
];
|
||||
);
|
||||
|
||||
yield return
|
||||
[
|
||||
data.Add(
|
||||
"only tomorrow",
|
||||
new NordPoolPrice { Prices = [] },
|
||||
new NordPoolPrice { Prices = [new NordPoolDayPrice { Start = tomorrowStart, End = tomorrowStart.AddMinutes(15), Price = 18.71 }] },
|
||||
1
|
||||
];
|
||||
);
|
||||
|
||||
yield return ["empty lists", new NordPoolPrice { Prices = [] }, new NordPoolPrice { Prices = [] }, 0];
|
||||
yield return ["null lists", new NordPoolPrice { Prices = null }, new NordPoolPrice { Prices = null }, 0];
|
||||
yield return ["null price objects", (NordPoolPrice?)null, (NordPoolPrice?)null, 0];
|
||||
data.Add("empty lists", new NordPoolPrice { Prices = [] }, new NordPoolPrice { Prices = [] }, 0);
|
||||
data.Add("null lists", new NordPoolPrice { Prices = null }, new NordPoolPrice { Prices = null }, 0);
|
||||
data.Add("null price objects", null, null, 0);
|
||||
return data;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
@@ -832,15 +828,17 @@ public class NordPoolEntityServiceTests
|
||||
|
||||
#region Cancellation
|
||||
|
||||
public static IEnumerable<object[]> CancelledOperations()
|
||||
public static TheoryData<string, Func<NordPoolEntityService, Task>> CancelledOperations()
|
||||
{
|
||||
var data = new TheoryData<string, Func<NordPoolEntityService, Task>>();
|
||||
var cancelled = new CancellationToken(canceled: true);
|
||||
var context = CreateDefaultContext();
|
||||
|
||||
yield return ["create entities", (Func<NordPoolEntityService, Task>)(sut => sut.CreateEntitiesAsync("EUR/kWh", cancelled))];
|
||||
yield return ["reset entities", (Func<NordPoolEntityService, Task>)(sut => sut.ResetEntitiesAsync(cancelled))];
|
||||
yield return ["update entities", (Func<NordPoolEntityService, Task>)(sut => sut.UpdateEntitiesAsync(context, cancelled))];
|
||||
yield return ["cleanup entities", (Func<NordPoolEntityService, Task>)(sut => sut.CleanupEntitiesAsync(cancelled))];
|
||||
data.Add("create entities", sut => sut.CreateEntitiesAsync("EUR/kWh", cancelled));
|
||||
data.Add("reset entities", sut => sut.ResetEntitiesAsync(cancelled));
|
||||
data.Add("update entities", sut => sut.UpdateEntitiesAsync(context, cancelled));
|
||||
data.Add("cleanup entities", sut => sut.CleanupEntitiesAsync(cancelled));
|
||||
return data;
|
||||
}
|
||||
|
||||
[Theory]
|
||||
|
||||
@@ -114,7 +114,7 @@ public class NordPoolInitTests
|
||||
.Setup(es => es.CreateEntitiesAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.ThrowsAsync(new InvalidOperationException("create failed"));
|
||||
|
||||
var act = () => sut.InitializeAsync();
|
||||
var act = sut.InitializeAsync;
|
||||
|
||||
await act.Should().ThrowAsync<InvalidOperationException>().WithMessage("create failed");
|
||||
_entityServiceMock.Verify(es => es.ResetEntitiesAsync(It.IsAny<CancellationToken>()), Times.Never);
|
||||
|
||||
@@ -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))]
|
||||
|
||||
@@ -10,8 +10,6 @@ internal static class NordPoolTestData
|
||||
{
|
||||
public static readonly DateTime DayStart = new(2026, 3, 31, 0, 0, 0, DateTimeKind.Utc);
|
||||
|
||||
public static readonly DateTime TomorrowStart = DayStart.AddDays(1);
|
||||
|
||||
/// <summary>
|
||||
/// Builds a contiguous set of 15-minute intervals starting at <paramref name="dayStart"/>.
|
||||
/// </summary>
|
||||
@@ -22,14 +20,16 @@ internal static class NordPoolTestData
|
||||
{
|
||||
var start = dayStart ?? DayStart;
|
||||
|
||||
return Enumerable.Range(0, count)
|
||||
.Select(i => new NordPoolDayPrice
|
||||
{
|
||||
Start = start.AddMinutes(i * NordPoolConsts.MinutesPerInterval),
|
||||
End = start.AddMinutes((i + 1) * NordPoolConsts.MinutesPerInterval),
|
||||
Price = priceFactory(i)
|
||||
})
|
||||
.ToList();
|
||||
return
|
||||
[
|
||||
.. Enumerable.Range(0, count)
|
||||
.Select(i => new NordPoolDayPrice
|
||||
{
|
||||
Start = start.AddMinutes(i * NordPoolConsts.MinutesPerInterval),
|
||||
End = start.AddMinutes((i + 1) * NordPoolConsts.MinutesPerInterval),
|
||||
Price = priceFactory(i)
|
||||
})
|
||||
];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -42,7 +42,7 @@ internal static class NordPoolTestData
|
||||
|
||||
return CreateIntervals(
|
||||
NordPoolConsts.MaxDailyIntervals,
|
||||
i => Math.Round(15.0 * Math.Sin(i / 6.0) + (i % 8) - 2.0, 2),
|
||||
i => Math.Round(15.0 * Math.Sin(i / 6.0) + i % 8 - 2.0, 2),
|
||||
start);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user