Apply code formatting cleanup across monitor projects

- Reindent appsettings.json and the MSBuild project files
- Collapse single-statement guard blocks and tidy using and member order
- Normalize XML doc indentation and file endings
- Reorder BatteryMonitor test-data helpers and move the exclusion tests into
  their own region
- Carry the same formatting through the boiler config, control, entity and
  test files
This commit is contained in:
2026-11-30 11:52:06 +02:00
parent cf8c9434c8
commit 24729ee267
165 changed files with 2513 additions and 2470 deletions
@@ -30,14 +30,14 @@ public class NordPoolPriceServiceTests
#region GetTimeQuarterIndex
[Theory]
[InlineData(0, 0, 8)] // UTC 00:00 = CEST 02:00
[InlineData(1, 0, 12)] // UTC 01:00 = CEST 03:00
[InlineData(6, 0, 32)] // UTC 06:00 = CEST 08:00
[InlineData(12, 0, 56)] // UTC 12:00 = CEST 14:00
[InlineData(22, 0, 0)] // UTC 22:00 = CEST 00:00 (next day start)
[InlineData(22, 15, 1)] // UTC 22:15 = CEST 00:15
[InlineData(22, 30, 2)] // UTC 22:30 = CEST 00:30
[InlineData(22, 45, 3)] // UTC 22:45 = CEST 00:45
[InlineData(0, 0, 8)] // UTC 00:00 = CEST 02:00
[InlineData(1, 0, 12)] // UTC 01:00 = CEST 03:00
[InlineData(6, 0, 32)] // UTC 06:00 = CEST 08:00
[InlineData(12, 0, 56)] // UTC 12:00 = CEST 14:00
[InlineData(22, 0, 0)] // UTC 22:00 = CEST 00:00 (next day start)
[InlineData(22, 15, 1)] // UTC 22:15 = CEST 00:15
[InlineData(22, 30, 2)] // UTC 22:30 = CEST 00:30
[InlineData(22, 45, 3)] // UTC 22:45 = CEST 00:45
public void GetTimeQuarterIndex_ShouldReturnCorrectIndex(int hour, int minute, int expectedIndex)
{
// Arrange — 2026-03-31 is in CEST (UTC+2)
@@ -51,11 +51,11 @@ public class NordPoolPriceServiceTests
}
[Theory]
[InlineData(0, 15, 9)] // UTC 00:15 = CEST 02:15
[InlineData(1, 30, 14)] // UTC 01:30 = CEST 03:30
[InlineData(12, 0, 56)] // UTC 12:00 = CEST 14:00
[InlineData(22, 0, 0)] // UTC 22:00 = CEST 00:00
[InlineData(22, 59, 3)] // UTC 22:59 = CEST 00:59
[InlineData(0, 15, 9)] // UTC 00:15 = CEST 02:15
[InlineData(1, 30, 14)] // UTC 01:30 = CEST 03:30
[InlineData(12, 0, 56)] // UTC 12:00 = CEST 14:00
[InlineData(22, 0, 0)] // UTC 22:00 = CEST 00:00
[InlineData(22, 59, 3)] // UTC 22:59 = CEST 00:59
public void GetTimeQuarterIndex_ShouldHandleAllHoursCorrectly(int hour, int minute, int expectedIndex)
{
// Arrange — 2026-03-31 is in CEST (UTC+2)
@@ -115,13 +115,11 @@ public class NordPoolPriceServiceTests
// Arrange & Act — iterate over a full UTC day; CET conversion produces 96 unique quarter indices
var indices = new HashSet<int>();
for (var hour = 0; hour < 24; hour++)
for (var minute = 0; minute < 60; minute += 15)
{
for (var minute = 0; minute < 60; minute += 15)
{
var date = new DateTime(2026, 3, 31, hour, minute, 0, DateTimeKind.Utc);
var index = NordPoolPriceService.GetTimeQuarterIndex(date);
indices.Add(index);
}
var date = new DateTime(2026, 3, 31, hour, minute, 0, DateTimeKind.Utc);
var index = NordPoolPriceService.GetTimeQuarterIndex(date);
indices.Add(index);
}
// Assert
@@ -131,9 +129,10 @@ public class NordPoolPriceServiceTests
}
[Theory]
[InlineData(2026, 1, 15, 8, 0, 36)] // CET winter (UTC+1): UTC 08:00 = CET 09:00 -> index 36
[InlineData(2026, 7, 15, 8, 0, 40)] // CEST summer (UTC+2): UTC 08:00 = CEST 10:00 -> index 40
public void GetTimeQuarterIndex_ShouldHandleDaylightSavingTimeCorrectly(int year, int month, int day, int hour, int minute, int expectedIndex)
[InlineData(2026, 1, 15, 8, 0, 36)] // CET winter (UTC+1): UTC 08:00 = CET 09:00 -> index 36
[InlineData(2026, 7, 15, 8, 0, 40)] // CEST summer (UTC+2): UTC 08:00 = CEST 10:00 -> index 40
public void GetTimeQuarterIndex_ShouldHandleDaylightSavingTimeCorrectly(int year, int month, int day, int hour,
int minute, int expectedIndex)
{
// Arrange
var testDate = new DateTime(year, month, day, hour, minute, 0, DateTimeKind.Utc);
@@ -233,7 +232,14 @@ public class NordPoolPriceServiceTests
// Arrange
var dto = new NordPoolPriceResultDto
{
Prices = [new NordPoolDayPriceDto { Start = DateTime.UtcNow.ToString("o"), End = DateTime.UtcNow.AddHours(1).ToString("o"), Price = 100.0 }]
Prices =
[
new NordPoolDayPriceDto
{
Start = DateTime.UtcNow.ToString("o"), End = DateTime.UtcNow.AddHours(1).ToString("o"),
Price = 100.0
}
]
};
var jsonString = JsonSerializer.Serialize(dto);
@@ -243,7 +249,11 @@ public class NordPoolPriceServiceTests
{
Prices = new List<NordPoolDayPrice>
{
new() { Start = DateTime.Parse(dto.Prices[0].Start!, CultureInfo.InvariantCulture), End = DateTime.Parse(dto.Prices[0].End!, CultureInfo.InvariantCulture), Price = 100.0 }
new()
{
Start = DateTime.Parse(dto.Prices[0].Start!, CultureInfo.InvariantCulture),
End = DateTime.Parse(dto.Prices[0].End!, CultureInfo.InvariantCulture), Price = 100.0
}
}
};
@@ -265,7 +275,14 @@ public class NordPoolPriceServiceTests
// Arrange
var dto = new NordPoolPriceResultDto
{
Prices = [new NordPoolDayPriceDto { Start = DateTime.UtcNow.ToString("o"), End = DateTime.UtcNow.AddHours(1).ToString("o"), Price = 100.0 }]
Prices =
[
new NordPoolDayPriceDto
{
Start = DateTime.UtcNow.ToString("o"), End = DateTime.UtcNow.AddHours(1).ToString("o"),
Price = 100.0
}
]
};
var jsonString = JsonSerializer.Serialize(dto);
@@ -456,14 +473,12 @@ public class NordPoolPriceServiceTests
var prices = new List<NordPoolDayPrice>();
for (var i = 0; i < 96; i++)
{
prices.Add(new NordPoolDayPrice
{
Start = now.AddMinutes(i * 15),
End = now.AddMinutes((i + 1) * 15),
Price = 5.0 + i * 0.22
});
}
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
@@ -667,32 +682,37 @@ public class NordPoolPriceServiceTests
#region ShouldFetchNewPrices
private static NordPoolPrice CreatePrices(params double?[] values) => new()
private static NordPoolPrice CreatePrices(params double?[] values)
{
Prices = [.. values.Select(price => new NordPoolDayPrice { Price = price })]
};
return new NordPoolPrice
{
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). xUnit cannot serialize
/// <see cref="NordPoolPrice"/> rows, so the matrix runs inside a single test.
/// 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). xUnit cannot serialize
/// <see cref="NordPoolPrice" /> rows, so the matrix runs inside a single test.
/// </summary>
[Fact]
public void ShouldFetchNewPrices_ShouldMatchScenario()
{
var today = DateOnly.FromDateTime(DateTime.Now);
(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)
];
(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)
{
@@ -779,7 +799,7 @@ public class NordPoolPriceServiceTests
}
/// <summary>
/// Rows are not serializable as theory data, so the three unusable payloads are exercised in one test.
/// Rows are not serializable as theory data, so the three unusable payloads are exercised in one test.
/// </summary>
[Fact]
public void RollOverPrices_WithoutUsableTomorrowPrices_ShouldResetTodayToEmptyPrice()
@@ -789,7 +809,7 @@ public class NordPoolPriceServiceTests
foreach (var tomorrow in unusablePrices)
{
// Arrange
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = [new() { Price = 12.50 }] };
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = [new NordPoolDayPrice { Price = 12.50 }] };
_sut.TomorrowNordPoolPrice = tomorrow;
_sut.DayQuartersIndex = 42;
var today = new DateOnly(2026, 4, 1);
@@ -849,4 +869,4 @@ public class NordPoolPriceServiceTests
}
#endregion
}
}