Add shared test data builders and Qodana configuration
- Extract per-monitor *TestData helper classes and rework tests to use them - Add boiler run-time tracker abstraction (implementation pending) - Drop unused NordPool init/update-result types and stale PLAN.md - Add qodana.yaml with the inspection set to keep the analysis focused
This commit is contained in:
@@ -115,14 +115,20 @@ public class CompactNordPoolDayPriceTests
|
||||
json.Should().Be($"[{TestStartEpoch},{TestEndEpoch},null]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_ShouldRoundTrip()
|
||||
[Theory]
|
||||
[InlineData(17.91)]
|
||||
[InlineData(-12.34)]
|
||||
[InlineData(0.0)]
|
||||
[InlineData(0.001)]
|
||||
[InlineData(17.9159)]
|
||||
[InlineData(null)]
|
||||
public void JsonDeserialization_ShouldRoundTripPrice(double? price)
|
||||
{
|
||||
var original = new CompactNordPoolDayPrice
|
||||
{
|
||||
Start = TestStartEpoch,
|
||||
End = TestEndEpoch,
|
||||
Price = 17.91
|
||||
Price = price
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(original);
|
||||
@@ -155,28 +161,33 @@ public class CompactNordPoolDayPriceTests
|
||||
act.Should().Throw<ArgumentNullException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_EmptyArray_ShouldThrowJsonException()
|
||||
{
|
||||
var act = () => JsonSerializer.Deserialize<CompactNordPoolDayPrice>("[]");
|
||||
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}"]
|
||||
];
|
||||
|
||||
act.Should().Throw<JsonException>();
|
||||
[Theory]
|
||||
[MemberData(nameof(InvalidJsonPayloads))]
|
||||
public void JsonDeserialization_WithInvalidPayload_ShouldThrowJsonException(string scenario, string json)
|
||||
{
|
||||
var act = () => JsonSerializer.Deserialize<CompactNordPoolDayPrice>(json);
|
||||
|
||||
act.Should().Throw<JsonException>($"scenario: {scenario}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_TooFewElements_ShouldThrowJsonException()
|
||||
public void JsonSerialization_EmptyList_ShouldProduceEmptyArray()
|
||||
{
|
||||
var act = () => JsonSerializer.Deserialize<CompactNordPoolDayPrice>("[1,2]");
|
||||
var json = JsonSerializer.Serialize(new List<CompactNordPoolDayPrice>());
|
||||
|
||||
act.Should().Throw<JsonException>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonDeserialization_InvalidTokenType_ShouldThrowJsonException()
|
||||
{
|
||||
var act = () => JsonSerializer.Deserialize<CompactNordPoolDayPrice>("[\"abc\",2,3]");
|
||||
|
||||
act.Should().Throw<JsonException>();
|
||||
json.Should().Be("[]");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -216,23 +227,53 @@ public class CompactNordPoolDayPriceTests
|
||||
result.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCompact_WithGeneratedDay_ShouldPreserveOrderAndCount()
|
||||
{
|
||||
var prices = NordPoolTestData.CreateIntervals(96, i => 4.93 + i * 0.22);
|
||||
|
||||
var result = prices.ToCompact();
|
||||
|
||||
result.Should().HaveCount(96);
|
||||
result.Should().BeInAscendingOrder(p => p.Start);
|
||||
result[0].Start.Should().Be(new DateTimeOffset(NordPoolTestData.DayStart).ToUnixTimeSeconds());
|
||||
result[95].Start.Should().Be(new DateTimeOffset(NordPoolTestData.DayStart.AddMinutes(95 * MinutesPerInterval)).ToUnixTimeSeconds());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void JsonSerialization_WithGeneratedDay_ShouldRoundTripAllEntries()
|
||||
{
|
||||
var compact = NordPoolTestData.CreateGeneratedDay().ToCompact();
|
||||
|
||||
var json = JsonSerializer.Serialize(compact);
|
||||
var roundTripped = JsonSerializer.Deserialize<List<CompactNordPoolDayPrice>>(json);
|
||||
|
||||
roundTripped.Should().NotBeNull();
|
||||
roundTripped!.Should().HaveCount(compact.Count);
|
||||
roundTripped.Should().BeEquivalentTo(compact);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ToCompact_ShouldPreserveNullPriceAndNullTimestamps()
|
||||
{
|
||||
var prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = null, End = null, Price = null }
|
||||
};
|
||||
|
||||
var result = prices.ToCompact();
|
||||
|
||||
result.Should().ContainSingle();
|
||||
result[0].Start.Should().Be(0L);
|
||||
result[0].End.Should().Be(0L);
|
||||
result[0].Price.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SerializedSize_WithMaxEntries_ShouldBeUnderHaAttributeLimit()
|
||||
{
|
||||
const int haAttributeByteLimitBytes = 16_384;
|
||||
var dayStart = new DateTime(2026, 3, 31, 0, 0, 0, DateTimeKind.Utc);
|
||||
var prices = new List<NordPoolDayPrice>();
|
||||
|
||||
for (var i = 0; i < MaxExpectedPriceEntries; i++)
|
||||
{
|
||||
var start = dayStart.AddMinutes(i * MinutesPerInterval);
|
||||
prices.Add(new NordPoolDayPrice
|
||||
{
|
||||
Start = start,
|
||||
End = start.AddMinutes(MinutesPerInterval),
|
||||
Price = 4.93 + i * 0.22
|
||||
});
|
||||
}
|
||||
var prices = NordPoolTestData.CreateIntervals(MaxExpectedPriceEntries, i => 4.93 + i * 0.22);
|
||||
|
||||
var compactPrices = prices.ToCompact();
|
||||
var attributePayload = new
|
||||
|
||||
Reference in New Issue
Block a user