feat: add ToCompact extension for NordPoolDayPrice collections
Made-with: Cursor
This commit is contained in:
@@ -150,4 +150,41 @@ public class CompactNordPoolDayPriceTests
|
|||||||
|
|
||||||
act.Should().Throw<JsonException>();
|
act.Should().Throw<JsonException>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToCompact_ShouldConvertAllPrices()
|
||||||
|
{
|
||||||
|
var prices = new List<NordPoolDayPrice>
|
||||||
|
{
|
||||||
|
new() { Start = TestStart, End = TestEnd, Price = 10.0 },
|
||||||
|
new() { Start = TestEnd, End = TestEnd.AddMinutes(15), Price = 11.0 }
|
||||||
|
};
|
||||||
|
|
||||||
|
var result = prices.ToCompact();
|
||||||
|
|
||||||
|
result.Should().HaveCount(2);
|
||||||
|
result[0].Start.Should().Be(TestStartEpoch);
|
||||||
|
result[0].Price.Should().Be(10.0);
|
||||||
|
result[1].Price.Should().Be(11.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToCompact_WhenEmpty_ShouldReturnEmptyList()
|
||||||
|
{
|
||||||
|
var prices = Array.Empty<NordPoolDayPrice>();
|
||||||
|
|
||||||
|
var result = prices.ToCompact();
|
||||||
|
|
||||||
|
result.Should().BeEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ToCompact_WhenNull_ShouldReturnEmptyList()
|
||||||
|
{
|
||||||
|
IEnumerable<NordPoolDayPrice>? prices = null;
|
||||||
|
|
||||||
|
var result = prices.ToCompact();
|
||||||
|
|
||||||
|
result.Should().BeEmpty();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
namespace NordPool.Models;
|
||||||
|
|
||||||
|
public static class NordPoolDayPriceExtensions
|
||||||
|
{
|
||||||
|
public static List<CompactNordPoolDayPrice> ToCompact(this IEnumerable<NordPoolDayPrice>? prices)
|
||||||
|
{
|
||||||
|
if (prices is null)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
return prices.Select(CompactNordPoolDayPrice.FromDayPrice).ToList();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user