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,4 +1,6 @@
|
||||
using System.Globalization;
|
||||
#region
|
||||
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using AutoMapper;
|
||||
using FluentAssertions;
|
||||
@@ -8,6 +10,8 @@ using NordPool.Models;
|
||||
using NordPool.Models.Dtos;
|
||||
using NordPoolManager;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Manager.Tests;
|
||||
|
||||
public class NordPoolPriceServiceTests
|
||||
@@ -110,12 +114,15 @@ 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)
|
||||
{
|
||||
var date = new DateTime(2026, 3, 31, hour, minute, 0, DateTimeKind.Utc);
|
||||
var index = NordPoolPriceService.GetTimeQuarterIndex(date);
|
||||
indices.Add(index);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
// Assert
|
||||
@@ -127,8 +134,12 @@ 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)
|
||||
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);
|
||||
@@ -245,7 +256,7 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new()
|
||||
new NordPoolDayPrice
|
||||
{
|
||||
Start = DateTime.Parse(dto.Prices[0].Start!, CultureInfo.InvariantCulture),
|
||||
End = DateTime.Parse(dto.Prices[0].End!, CultureInfo.InvariantCulture), Price = 100.0
|
||||
@@ -254,7 +265,7 @@ public class NordPoolPriceServiceTests
|
||||
};
|
||||
|
||||
_mapperMock.Setup(m => m.Map<NordPoolPriceResultDto, NordPoolPrice>(It.IsAny<NordPoolPriceResultDto>()))
|
||||
.Returns(expectedPrice);
|
||||
.Returns(expectedPrice);
|
||||
|
||||
// Act
|
||||
var result = _sut.ParseNordPoolResult(jsonElement);
|
||||
@@ -285,7 +296,7 @@ public class NordPoolPriceServiceTests
|
||||
var jsonElement = JsonSerializer.Deserialize<JsonElement>(jsonString);
|
||||
|
||||
_mapperMock.Setup(m => m.Map<NordPoolPriceResultDto, NordPoolPrice>(It.IsAny<NordPoolPriceResultDto>()))
|
||||
.Returns((NordPoolPrice)null!);
|
||||
.Returns((NordPoolPrice)null!);
|
||||
|
||||
// Act
|
||||
var result = _sut.ParseNordPoolResult(jsonElement);
|
||||
@@ -301,7 +312,7 @@ public class NordPoolPriceServiceTests
|
||||
var jsonElement = JsonSerializer.Deserialize<JsonElement>("{}");
|
||||
|
||||
_mapperMock.Setup(m => m.Map<NordPoolPriceResultDto, NordPoolPrice>(It.IsAny<NordPoolPriceResultDto>()))
|
||||
.Returns(new NordPoolPrice());
|
||||
.Returns(new NordPoolPrice());
|
||||
|
||||
// Act
|
||||
var result = _sut.ParseNordPoolResult(jsonElement);
|
||||
@@ -322,9 +333,9 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 },
|
||||
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = 148.0 },
|
||||
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 215.0 }
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 },
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = 148.0 },
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 215.0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -347,9 +358,9 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 },
|
||||
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = null },
|
||||
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 215.0 }
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 },
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = null },
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 215.0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -388,7 +399,7 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = startTime, End = endTime, Price = 81.0 }
|
||||
new NordPoolDayPrice { Start = startTime, End = endTime, Price = 81.0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -424,8 +435,8 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = null },
|
||||
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = null }
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = null },
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = null }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -445,7 +456,7 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 }
|
||||
new NordPoolDayPrice { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 81.0 }
|
||||
}
|
||||
};
|
||||
|
||||
@@ -469,12 +480,14 @@ 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 };
|
||||
|
||||
@@ -532,8 +545,11 @@ public class NordPoolPriceServiceTests
|
||||
var expectedIndex = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
|
||||
|
||||
var prices = new List<NordPoolDayPrice>();
|
||||
|
||||
for (var i = 0; i < 96; i++)
|
||||
{
|
||||
prices.Add(new NordPoolDayPrice { Price = 4.0 + i * 0.23 });
|
||||
}
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.DayQuartersIndex = expectedIndex;
|
||||
@@ -552,8 +568,11 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
// Arrange
|
||||
var prices = new List<NordPoolDayPrice>();
|
||||
|
||||
for (var i = 0; i < 96; i++)
|
||||
{
|
||||
prices.Add(new NordPoolDayPrice { Price = null });
|
||||
}
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.CurrentPrice = 17.91;
|
||||
@@ -572,8 +591,11 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
// Arrange
|
||||
var prices = new List<NordPoolDayPrice>();
|
||||
|
||||
for (var i = 0; i < 96; i++)
|
||||
{
|
||||
prices.Add(new NordPoolDayPrice { Price = 5.0 + i * 0.22 });
|
||||
}
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.DayQuartersIndex = -1;
|
||||
@@ -595,9 +617,10 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
// Arrange — negative and zero spot prices are valid NordPool scenarios
|
||||
var index = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
|
||||
|
||||
var prices = NordPoolTestData.CreateIntervals(
|
||||
NordPoolConsts.MaxDailyIntervals,
|
||||
i => i == index ? expectedPrice : 10.0);
|
||||
NordPoolConsts.MaxDailyIntervals,
|
||||
i => i == index ? expectedPrice : 10.0);
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.CurrentPrice = 17.91;
|
||||
@@ -616,9 +639,10 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
// Arrange — fewer prices than the current quarter index (e.g. partial day payload)
|
||||
var index = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
|
||||
|
||||
var prices = Enumerable.Range(0, index)
|
||||
.Select(i => new NordPoolDayPrice { Price = 10.0 + i })
|
||||
.ToList();
|
||||
.Select(i => new NordPoolDayPrice { Price = 10.0 + i })
|
||||
.ToList();
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.CurrentPrice = 17.91;
|
||||
@@ -637,9 +661,10 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
// Arrange
|
||||
var index = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
|
||||
|
||||
var prices = Enumerable.Range(0, NordPoolConsts.MaxDailyIntervals)
|
||||
.Select(_ => new NordPoolDayPrice { Price = 99.0 })
|
||||
.ToList();
|
||||
.Select(_ => new NordPoolDayPrice { Price = 99.0 })
|
||||
.ToList();
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.DayQuartersIndex = index;
|
||||
@@ -658,9 +683,10 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
// Arrange
|
||||
var index = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
|
||||
|
||||
var prices = Enumerable.Range(0, NordPoolConsts.MaxDailyIntervals)
|
||||
.Select(i => new NordPoolDayPrice { Price = i == index ? null : 10.0 })
|
||||
.ToList();
|
||||
.Select(i => new NordPoolDayPrice { Price = i == index ? null : 10.0 })
|
||||
.ToList();
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
||||
_sut.CurrentPrice = 17.91;
|
||||
@@ -687,6 +713,7 @@ public class NordPoolPriceServiceTests
|
||||
Task<NordPoolPrice> Fetch(DateOnly date)
|
||||
{
|
||||
requestedDates.Add(date);
|
||||
|
||||
return Task.FromResult(CreatePrices(1.5));
|
||||
}
|
||||
|
||||
@@ -718,10 +745,11 @@ public class NordPoolPriceServiceTests
|
||||
|
||||
// Act
|
||||
await _sut.FetchPricesAsync(_ =>
|
||||
{
|
||||
delegateCalled = true;
|
||||
return Task.FromResult(CreatePrices(3.0));
|
||||
});
|
||||
{
|
||||
delegateCalled = true;
|
||||
|
||||
return Task.FromResult(CreatePrices(3.0));
|
||||
});
|
||||
|
||||
// Assert
|
||||
delegateCalled.Should().BeFalse();
|
||||
@@ -761,7 +789,7 @@ public class NordPoolPriceServiceTests
|
||||
("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),
|
||||
CreatePrices((double?)null), false),
|
||||
("all price payloads are null", today, null, null, true)
|
||||
];
|
||||
|
||||
@@ -786,10 +814,12 @@ public class NordPoolPriceServiceTests
|
||||
// Arrange — tomorrow's prices are not published before 13:00, so cached data is acceptable until then
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
_sut.LastFetchedDate = today;
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
|
||||
Prices = new List<NordPoolDayPrice> { new NordPoolDayPrice { Price = 12.50 } }
|
||||
};
|
||||
|
||||
_sut.TomorrowNordPoolPrice = new NordPoolPrice { Prices = null };
|
||||
|
||||
// Act
|
||||
@@ -805,10 +835,12 @@ public class NordPoolPriceServiceTests
|
||||
// Arrange
|
||||
var today = DateOnly.FromDateTime(DateTime.Now);
|
||||
_sut.LastFetchedDate = today;
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
|
||||
Prices = new List<NordPoolDayPrice> { new NordPoolDayPrice { Price = 12.50 } }
|
||||
};
|
||||
|
||||
_sut.TomorrowNordPoolPrice = new NordPoolPrice { Prices = new List<NordPoolDayPrice>() };
|
||||
|
||||
// Act
|
||||
@@ -828,13 +860,14 @@ public class NordPoolPriceServiceTests
|
||||
// Arrange
|
||||
var tomorrow = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 18.71 } }
|
||||
Prices = new List<NordPoolDayPrice> { new NordPoolDayPrice { Price = 18.71 } }
|
||||
};
|
||||
|
||||
_sut.TodayNordPoolPrice = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
|
||||
Prices = new List<NordPoolDayPrice> { new NordPoolDayPrice { Price = 12.50 } }
|
||||
};
|
||||
|
||||
_sut.TomorrowNordPoolPrice = tomorrow;
|
||||
_sut.DayQuartersIndex = 48;
|
||||
var today = new DateOnly(2026, 4, 1);
|
||||
@@ -855,7 +888,7 @@ public class NordPoolPriceServiceTests
|
||||
[Fact]
|
||||
public void RollOverPrices_WithoutUsableTomorrowPrices_ShouldResetTodayToEmptyPrice()
|
||||
{
|
||||
NordPoolPrice?[] unusablePrices = [null, new() { Prices = null }, new() { Prices = [] }];
|
||||
NordPoolPrice?[] unusablePrices = [null, new NordPoolPrice { Prices = null }, new NordPoolPrice { Prices = [] }];
|
||||
|
||||
foreach (var tomorrow in unusablePrices)
|
||||
{
|
||||
@@ -900,11 +933,12 @@ public class NordPoolPriceServiceTests
|
||||
// Arrange
|
||||
var previousToday = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 12.50 } }
|
||||
Prices = new List<NordPoolDayPrice> { new NordPoolDayPrice { Price = 12.50 } }
|
||||
};
|
||||
|
||||
var tomorrow = new NordPoolPrice
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice> { new() { Price = 18.71 } }
|
||||
Prices = new List<NordPoolDayPrice> { new NordPoolDayPrice { Price = 18.71 } }
|
||||
};
|
||||
|
||||
_sut.TodayNordPoolPrice = previousToday;
|
||||
|
||||
Reference in New Issue
Block a user