Apply code formatting cleanup across the monitor projects
- Wrap using directives in `#region` blocks across the Battery, Boiler and NordPool sources and tests - Expand single-statement guards and loops into braced blocks - Realign wrapped method arguments, chained calls and continuations - Replace target-typed `new()` with explicit generic construction and empty string literals with `string.Empty` - Flatten the boiler config expression and reindent the remaining touched files
This commit is contained in:
@@ -1,21 +1,25 @@
|
||||
#region
|
||||
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using FluentAssertions;
|
||||
using NordPool.Models;
|
||||
using static NordPool.Models.NordPoolConsts;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Manager.Tests;
|
||||
|
||||
public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
private const int IntervalDurationSeconds = MinutesPerInterval * 60;
|
||||
|
||||
private static readonly DateTime TestStart = new(2026, 3, 31, 10, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime TestStart = new DateTime(2026, 3, 31, 10, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime TestEnd = TestStart.AddMinutes(MinutesPerInterval);
|
||||
private static readonly long TestStartEpoch = new DateTimeOffset(TestStart).ToUnixTimeSeconds();
|
||||
private static readonly long TestEndEpoch = new DateTimeOffset(TestEnd).ToUnixTimeSeconds();
|
||||
|
||||
public static TheoryData<string, string> InvalidJsonPayloads => new()
|
||||
public static TheoryData<string, string> InvalidJsonPayloads => new TheoryData<string, string>
|
||||
{
|
||||
{ "empty array", "[]" },
|
||||
{ "too few elements", "[1,2]" },
|
||||
@@ -157,8 +161,8 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
var prices = new List<CompactNordPoolDayPrice>
|
||||
{
|
||||
new() { Start = TestStartEpoch, End = TestEndEpoch, Price = 12.50 },
|
||||
new() { Start = TestEndEpoch, End = TestEndEpoch + IntervalDurationSeconds, Price = 13.26 }
|
||||
new CompactNordPoolDayPrice { Start = TestStartEpoch, End = TestEndEpoch, Price = 12.50 },
|
||||
new CompactNordPoolDayPrice { Start = TestEndEpoch, End = TestEndEpoch + IntervalDurationSeconds, Price = 13.26 }
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(prices);
|
||||
@@ -198,8 +202,8 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
var prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = TestStart, End = TestEnd, Price = 12.50 },
|
||||
new() { Start = TestEnd, End = TestEnd.AddMinutes(MinutesPerInterval), Price = 13.26 }
|
||||
new NordPoolDayPrice { Start = TestStart, End = TestEnd, Price = 12.50 },
|
||||
new NordPoolDayPrice { Start = TestEnd, End = TestEnd.AddMinutes(MinutesPerInterval), Price = 13.26 }
|
||||
};
|
||||
|
||||
var result = prices.ToCompact();
|
||||
@@ -240,8 +244,11 @@ public class CompactNordPoolDayPriceTests
|
||||
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());
|
||||
|
||||
result[95]
|
||||
.Start.Should()
|
||||
.Be(new DateTimeOffset(NordPoolTestData.DayStart.AddMinutes(95 * MinutesPerInterval))
|
||||
.ToUnixTimeSeconds());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -262,7 +269,7 @@ public class CompactNordPoolDayPriceTests
|
||||
{
|
||||
var prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = null, End = null, Price = null }
|
||||
new NordPoolDayPrice { Start = null, End = null, Price = null }
|
||||
};
|
||||
|
||||
var result = prices.ToCompact();
|
||||
@@ -280,6 +287,7 @@ public class CompactNordPoolDayPriceTests
|
||||
var prices = NordPoolTestData.CreateIntervals(MaxExpectedPriceEntries, i => 4.93 + i * 0.22);
|
||||
|
||||
var compactPrices = prices.ToCompact();
|
||||
|
||||
var attributePayload = new
|
||||
{
|
||||
prices = compactPrices,
|
||||
@@ -287,10 +295,12 @@ public class CompactNordPoolDayPriceTests
|
||||
friendly_name = "NordPool today and tomorrow prices",
|
||||
last_updated = DateTime.UtcNow.ToString("O")
|
||||
};
|
||||
|
||||
var json = JsonSerializer.Serialize(attributePayload);
|
||||
var byteCount = Encoding.UTF8.GetByteCount(json);
|
||||
|
||||
byteCount.Should().BeLessThan(haAttributeByteLimitBytes,
|
||||
$"serialized attribute payload is {byteCount} bytes, exceeding HA's {haAttributeByteLimitBytes}-byte limit");
|
||||
byteCount.Should()
|
||||
.BeLessThan(haAttributeByteLimitBytes,
|
||||
$"serialized attribute payload is {byteCount} bytes, exceeding HA's {haAttributeByteLimitBytes}-byte limit");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user