Fix culture-sensitive parsing, log swallowing and closure capture
- DateTimeTypeConverter parses with the invariant culture instead of the ambient one (NordPool timestamps arrive as ISO-8601) - Shower last-shower-time state is formatted with the invariant culture - PresenceServiceTests no longer captures the loop variable in a Moq setup - CheapestIntervalsFinderTests compare prices with a tolerance instead of floating-point equality - MqttRecreateApp logs the unit_of_measurement read failure instead of silently swallowing every exception - LightMonitorOptions moves to LightMonitor.Models so the namespace matches the project and file location
This commit is contained in:
@@ -15,6 +15,8 @@ public class CheapestIntervalsFinderTests
|
||||
|
||||
private CheapestIntervalsFinder CreateSut() => new(_loggerMock.Object);
|
||||
|
||||
private static bool IsPrice(double actual, double expected) => Math.Abs(actual - expected) < 0.000_001;
|
||||
|
||||
private static NordPoolPrice CreatePricesForDay(DateTime dayStart, int intervalCount = NordPoolConsts.MaxDailyIntervals)
|
||||
{
|
||||
return new NordPoolPrice
|
||||
@@ -129,8 +131,8 @@ public class CheapestIntervalsFinderTests
|
||||
var result = sut.FindCheapestIntervals(prices, 4, double.MaxValue, DeadlineEndOfDay);
|
||||
|
||||
// Assert
|
||||
result.Single(r => r.Price == 4.93).Rank.Should().Be(1);
|
||||
result.Single(r => r.Price == 8.96).Rank.Should().Be(2);
|
||||
result.Single(r => IsPrice(r.Price, 4.93)).Rank.Should().Be(1);
|
||||
result.Single(r => IsPrice(r.Price, 8.96)).Rank.Should().Be(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -219,8 +221,8 @@ public class CheapestIntervalsFinderTests
|
||||
// Assert — results are chronological, ranks still follow price order
|
||||
result.Should().HaveCount(2);
|
||||
result.Select(r => r.Price).Should().ContainInOrder(-2.10, -7.40);
|
||||
result.Single(r => r.Price == -7.40).Rank.Should().Be(1);
|
||||
result.Single(r => r.Price == -2.10).Rank.Should().Be(2);
|
||||
result.Single(r => IsPrice(r.Price, -7.40)).Rank.Should().Be(1);
|
||||
result.Single(r => IsPrice(r.Price, -2.10)).Rank.Should().Be(2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using AutoMapper;
|
||||
using FluentAssertions;
|
||||
@@ -242,7 +243,7 @@ public class NordPoolPriceServiceTests
|
||||
{
|
||||
Prices = new List<NordPoolDayPrice>
|
||||
{
|
||||
new() { Start = DateTime.Parse(dto.Prices[0].Start!), End = DateTime.Parse(dto.Prices[0].End!), 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 }
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user