655 lines
18 KiB
C#
655 lines
18 KiB
C#
using System.Text.Json;
|
|
using AutoMapper;
|
|
using FluentAssertions;
|
|
using HomeAssistantGenerated;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using NetDaemon.HassModel;
|
|
using NordPool.Models;
|
|
using NordPool.Models.Dtos;
|
|
using NordPoolManager;
|
|
|
|
namespace NordPool.Manager.Tests;
|
|
|
|
public class NordPoolPriceServiceTests
|
|
{
|
|
private readonly Mock<IMapper> _mapperMock;
|
|
private readonly NordPoolPriceService _sut;
|
|
|
|
public NordPoolPriceServiceTests()
|
|
{
|
|
_mapperMock = new Mock<IMapper>();
|
|
var haContextMock = new Mock<IHaContext>();
|
|
var loggerMock = new Mock<ILogger<NordPoolPriceService>>();
|
|
|
|
var services = new Services(haContextMock.Object);
|
|
_sut = new NordPoolPriceService(services, _mapperMock.Object, loggerMock.Object);
|
|
}
|
|
|
|
#region GetTimeQuarterIndex
|
|
|
|
[Theory]
|
|
[InlineData(0, 0, 4)]
|
|
[InlineData(1, 0, 8)]
|
|
[InlineData(6, 0, 28)]
|
|
[InlineData(12, 0, 52)]
|
|
[InlineData(23, 0, 0)]
|
|
[InlineData(23, 15, 1)]
|
|
[InlineData(23, 30, 2)]
|
|
[InlineData(23, 45, 3)]
|
|
public void GetTimeQuarterIndex_ShouldReturnCorrectIndex(int hour, int minute, int expectedIndex)
|
|
{
|
|
// Arrange
|
|
var testDate = new DateTime(2026, 2, 3, hour, minute, 0, DateTimeKind.Utc);
|
|
|
|
// Act
|
|
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
|
|
|
|
// Assert
|
|
result.Should().Be(expectedIndex);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(0, 15, 5)]
|
|
[InlineData(1, 30, 10)]
|
|
[InlineData(12, 0, 52)]
|
|
[InlineData(23, 0, 0)]
|
|
[InlineData(23, 59, 3)]
|
|
public void GetTimeQuarterIndex_ShouldHandleAllHoursCorrectly(int hour, int minute, int expectedIndex)
|
|
{
|
|
// Arrange
|
|
var testDate = new DateTime(2026, 2, 3, hour, minute, 0, DateTimeKind.Utc);
|
|
|
|
// Act
|
|
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
|
|
|
|
// Assert
|
|
result.Should().Be(expectedIndex);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetTimeQuarterIndex_AtExactMidnight_ShouldReturnIndex4()
|
|
{
|
|
// Arrange
|
|
var testDate = new DateTime(2026, 2, 3, 0, 0, 0, DateTimeKind.Utc);
|
|
|
|
// Act
|
|
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
|
|
|
|
// Assert
|
|
result.Should().Be(4);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetTimeQuarterIndex_AtEndOfDay_ShouldReturnIndex95()
|
|
{
|
|
// Arrange
|
|
var testDate = new DateTime(2026, 2, 3, 22, 45, 0, DateTimeKind.Utc);
|
|
|
|
// Act
|
|
var result = NordPoolPriceService.GetTimeQuarterIndex(testDate);
|
|
|
|
// Assert
|
|
result.Should().Be(95);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetTimeQuarterIndex_WithSeconds_ShouldIgnoreSeconds()
|
|
{
|
|
// Arrange
|
|
var withoutSeconds = new DateTime(2026, 2, 3, 12, 0, 0, DateTimeKind.Utc);
|
|
var withSeconds = new DateTime(2026, 2, 3, 12, 0, 59, DateTimeKind.Utc);
|
|
|
|
// Act
|
|
var result1 = NordPoolPriceService.GetTimeQuarterIndex(withoutSeconds);
|
|
var result2 = NordPoolPriceService.GetTimeQuarterIndex(withSeconds);
|
|
|
|
// Assert
|
|
result1.Should().Be(result2);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetTimeQuarterIndex_ShouldReturn96UniqueQuartersPerDay()
|
|
{
|
|
// Arrange & Act
|
|
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, 2, 3, hour, minute, 0, DateTimeKind.Utc);
|
|
var index = NordPoolPriceService.GetTimeQuarterIndex(date);
|
|
indices.Add(index);
|
|
}
|
|
}
|
|
|
|
// Assert
|
|
indices.Should().HaveCount(96);
|
|
indices.Min().Should().Be(0);
|
|
indices.Max().Should().Be(95);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region PriceCorrection
|
|
|
|
[Theory]
|
|
[InlineData(100.0, 12.1)]
|
|
[InlineData(50.0, 6.05)]
|
|
[InlineData(200.0, 24.2)]
|
|
[InlineData(0.0, 0.0)]
|
|
[InlineData(123.456, 14.94)]
|
|
public void PriceCorrection_ShouldCalculateCorrectPrice(double mwPrice, double expectedCentsPrice)
|
|
{
|
|
// Act
|
|
var result = NordPoolPriceService.PriceCorrection(mwPrice);
|
|
|
|
// Assert
|
|
result.Should().BeApproximately(expectedCentsPrice, 0.01);
|
|
}
|
|
|
|
[Fact]
|
|
public void PriceCorrection_ShouldApplyVatAndConversion()
|
|
{
|
|
// Act
|
|
var result = NordPoolPriceService.PriceCorrection(1000.0);
|
|
|
|
// Assert
|
|
result.Should().Be(121.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void PriceCorrection_WithNegativePrice_ShouldCalculateCorrectly()
|
|
{
|
|
// Act
|
|
var result = NordPoolPriceService.PriceCorrection(-100.0);
|
|
|
|
// Assert
|
|
result.Should().BeApproximately(-12.1, 0.01);
|
|
}
|
|
|
|
[Fact]
|
|
public void PriceCorrection_WithVerySmallPrice_ShouldRoundCorrectly()
|
|
{
|
|
// Act
|
|
var result = NordPoolPriceService.PriceCorrection(0.001);
|
|
|
|
// Assert
|
|
result.Should().Be(0.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void PriceCorrection_WithVeryLargePrice_ShouldCalculateCorrectly()
|
|
{
|
|
// Act
|
|
var result = NordPoolPriceService.PriceCorrection(10000.0);
|
|
|
|
// Assert
|
|
result.Should().BeApproximately(1210.0, 0.01);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ParseNordPoolResult
|
|
|
|
[Fact]
|
|
public void ParseNordPoolResult_WithNullElement_ShouldReturnEmptyNordPoolPrice()
|
|
{
|
|
// Act
|
|
var result = _sut.ParseNordPoolResult(null);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseNordPoolResult_WithValidElement_ShouldMapCorrectly()
|
|
{
|
|
// Arrange
|
|
var dto = new NordPoolPriceResultDto
|
|
{
|
|
Prices = [new NordPoolDayPriceDto { Start = DateTime.UtcNow.ToString("o"), End = DateTime.UtcNow.AddHours(1).ToString("o"), Price = 100.0 }]
|
|
};
|
|
|
|
var jsonString = JsonSerializer.Serialize(dto);
|
|
var jsonElement = JsonSerializer.Deserialize<JsonElement>(jsonString);
|
|
|
|
var expectedPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice>
|
|
{
|
|
new() { Start = DateTime.Parse(dto.Prices[0].Start!), End = DateTime.Parse(dto.Prices[0].End!), Price = 100.0 }
|
|
}
|
|
};
|
|
|
|
_mapperMock.Setup(m => m.Map<NordPoolPriceResultDto, NordPoolPrice>(It.IsAny<NordPoolPriceResultDto>()))
|
|
.Returns(expectedPrice);
|
|
|
|
// Act
|
|
var result = _sut.ParseNordPoolResult(jsonElement);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().NotBeNull();
|
|
result.Prices.Should().HaveCount(1);
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseNordPoolResult_WhenMapperReturnsNull_ShouldReturnNull()
|
|
{
|
|
// Arrange
|
|
var dto = new NordPoolPriceResultDto
|
|
{
|
|
Prices = [new NordPoolDayPriceDto { Start = DateTime.UtcNow.ToString("o"), End = DateTime.UtcNow.AddHours(1).ToString("o"), Price = 100.0 }]
|
|
};
|
|
|
|
var jsonString = JsonSerializer.Serialize(dto);
|
|
var jsonElement = JsonSerializer.Deserialize<JsonElement>(jsonString);
|
|
|
|
_mapperMock.Setup(m => m.Map<NordPoolPriceResultDto, NordPoolPrice>(It.IsAny<NordPoolPriceResultDto>()))
|
|
.Returns((NordPoolPrice)null!);
|
|
|
|
// Act
|
|
var result = _sut.ParseNordPoolResult(jsonElement);
|
|
|
|
// Assert
|
|
result.Should().BeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void ParseNordPoolResult_WithEmptyJsonObject_ShouldReturnEmptyNordPoolPrice()
|
|
{
|
|
// Arrange
|
|
var jsonElement = JsonSerializer.Deserialize<JsonElement>("{}");
|
|
|
|
_mapperMock.Setup(m => m.Map<NordPoolPriceResultDto, NordPoolPrice>(It.IsAny<NordPoolPriceResultDto>()))
|
|
.Returns(new NordPoolPrice());
|
|
|
|
// Act
|
|
var result = _sut.ParseNordPoolResult(jsonElement);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region AdjustedNordPoolPrice
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_ShouldApplyPriceCorrectionToAllPrices()
|
|
{
|
|
// Arrange
|
|
var inputPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice>
|
|
{
|
|
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 100.0 },
|
|
new() { Start = DateTime.UtcNow.AddHours(1), End = DateTime.UtcNow.AddHours(2), Price = 200.0 },
|
|
new() { Start = DateTime.UtcNow.AddHours(2), End = DateTime.UtcNow.AddHours(3), Price = 150.0 }
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().HaveCount(3);
|
|
result.Prices![0].Price.Should().BeApproximately(12.1, 0.01);
|
|
result.Prices![1].Price.Should().BeApproximately(24.2, 0.01);
|
|
result.Prices![2].Price.Should().BeApproximately(18.15, 0.01);
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_WithNullPriceValue_ShouldSkipThatPrice()
|
|
{
|
|
// Arrange
|
|
var inputPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice>
|
|
{
|
|
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 100.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 = 150.0 }
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().HaveCount(2);
|
|
result.Prices.Should().NotContain(p => p.Price == null);
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_WithNullPricesList_ShouldReturnEmptyPricesList()
|
|
{
|
|
// Arrange
|
|
var inputPrice = new NordPoolPrice { Prices = null };
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().NotBeNull();
|
|
result.Prices.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_ShouldPreserveDateTimes()
|
|
{
|
|
// Arrange
|
|
var startTime = new DateTime(2026, 2, 3, 10, 0, 0, DateTimeKind.Utc);
|
|
var endTime = new DateTime(2026, 2, 3, 11, 0, 0, DateTimeKind.Utc);
|
|
|
|
var inputPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice>
|
|
{
|
|
new() { Start = startTime, End = endTime, Price = 100.0 }
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices![0].Start.Should().Be(startTime);
|
|
result.Prices![0].End.Should().Be(endTime);
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_WithEmptyPricesList_ShouldReturnEmptyPricesList()
|
|
{
|
|
// Arrange
|
|
var inputPrice = new NordPoolPrice { Prices = new List<NordPoolDayPrice>() };
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().NotBeNull();
|
|
result.Prices.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_WithAllNullPrices_ShouldReturnEmptyPricesList()
|
|
{
|
|
// Arrange
|
|
var inputPrice = new NordPoolPrice
|
|
{
|
|
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 }
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
result.Should().NotBeNull();
|
|
result.Prices.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public void AdjustedNordPoolPrice_ShouldNotModifyOriginalInput()
|
|
{
|
|
// Arrange
|
|
var inputPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice>
|
|
{
|
|
new() { Start = DateTime.UtcNow, End = DateTime.UtcNow.AddHours(1), Price = 100.0 }
|
|
}
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.AdjustedNordPoolPrice(inputPrice);
|
|
|
|
// Assert
|
|
inputPrice.Prices[0].Price.Should().Be(100.0);
|
|
result.Prices.Should().NotBeSameAs(inputPrice.Prices);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region UpdateCurrentPrice
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WithValidPriceAtIndex_ShouldReturnCorrectPrice()
|
|
{
|
|
// Arrange
|
|
var now = DateTime.UtcNow;
|
|
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 = 10.0 + i
|
|
});
|
|
}
|
|
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
|
|
|
// Act
|
|
var result = _sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
result.Should().BeGreaterThan(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WhenNordPoolPriceIsNull_ShouldReturnZero()
|
|
{
|
|
// Act
|
|
var result = _sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
result.Should().Be(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WhenPricesListIsEmpty_ShouldReturnZero()
|
|
{
|
|
// Arrange
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = new List<NordPoolDayPrice>() };
|
|
|
|
// Act
|
|
var result = _sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
result.Should().Be(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WhenPricesListIsNull_ShouldReturnZero()
|
|
{
|
|
// Arrange
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = null };
|
|
|
|
// Act
|
|
var result = _sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
result.Should().Be(0);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WhenSameQuarterIndex_ShouldReturnCachedPrice()
|
|
{
|
|
// Arrange
|
|
var expectedIndex = NordPoolPriceService.GetTimeQuarterIndex(DateTime.UtcNow);
|
|
|
|
var prices = new List<NordPoolDayPrice>();
|
|
for (var i = 0; i < 96; i++)
|
|
prices.Add(new NordPoolDayPrice { Price = 42.0 + i });
|
|
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
|
_sut.DayQuartersIndex = expectedIndex;
|
|
_sut.CurrentPrice = 99.99;
|
|
|
|
// Act
|
|
var result = _sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
result.Should().Be(99.99);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WhenPriceAtIndexIsNull_ShouldReturnPreviousCurrentPrice()
|
|
{
|
|
// 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 = 55.0;
|
|
_sut.DayQuartersIndex = -1;
|
|
|
|
// Act
|
|
var result = _sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
result.Should().Be(55.0);
|
|
}
|
|
|
|
[Fact]
|
|
public void UpdateCurrentPrice_WhenNewQuarterIndex_ShouldUpdateDayQuartersIndex()
|
|
{
|
|
// Arrange
|
|
var prices = new List<NordPoolDayPrice>();
|
|
for (var i = 0; i < 96; i++)
|
|
prices.Add(new NordPoolDayPrice { Price = 10.0 + i });
|
|
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = prices };
|
|
_sut.DayQuartersIndex = -1;
|
|
|
|
// Act
|
|
_sut.UpdateCurrentPrice();
|
|
|
|
// Assert
|
|
_sut.DayQuartersIndex.Should().BeGreaterThanOrEqualTo(0);
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region ShouldFetchNewPrices
|
|
|
|
[Fact]
|
|
public void ShouldFetchNewPrices_WhenNoLastFetchedDate_ShouldReturnTrue()
|
|
{
|
|
// Act
|
|
var result = _sut.ShouldFetchNewPrices(DateOnly.FromDateTime(DateTime.Now));
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldFetchNewPrices_WhenLastFetchedDateIsYesterday_ShouldReturnTrue()
|
|
{
|
|
// Arrange
|
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
|
_sut.LastFetchedDate = today.AddDays(-1);
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.ShouldFetchNewPrices(today);
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldFetchNewPrices_WhenTodayPricesAreNull_ShouldReturnTrue()
|
|
{
|
|
// Arrange
|
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
|
_sut.LastFetchedDate = today;
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = null };
|
|
_sut.TomorrowNordPoolPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.ShouldFetchNewPrices(today);
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldFetchNewPrices_WhenTodayPricesAreEmpty_ShouldReturnTrue()
|
|
{
|
|
// Arrange
|
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
|
_sut.LastFetchedDate = today;
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice { Prices = new List<NordPoolDayPrice>() };
|
|
_sut.TomorrowNordPoolPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.ShouldFetchNewPrices(today);
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldFetchNewPrices_WhenAllPricesAvailable_ShouldReturnFalse()
|
|
{
|
|
// Arrange
|
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
|
_sut.LastFetchedDate = today;
|
|
_sut.TodayNordPoolPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice> { new() { Price = 10.0 } }
|
|
};
|
|
_sut.TomorrowNordPoolPrice = new NordPoolPrice
|
|
{
|
|
Prices = new List<NordPoolDayPrice> { new() { Price = 20.0 } }
|
|
};
|
|
|
|
// Act
|
|
var result = _sut.ShouldFetchNewPrices(today);
|
|
|
|
// Assert
|
|
result.Should().BeFalse();
|
|
}
|
|
|
|
[Fact]
|
|
public void ShouldFetchNewPrices_WhenNordPoolPriceIsNull_ShouldReturnTrue()
|
|
{
|
|
// Arrange
|
|
var today = DateOnly.FromDateTime(DateTime.Now);
|
|
_sut.LastFetchedDate = today;
|
|
|
|
// Act
|
|
var result = _sut.ShouldFetchNewPrices(today);
|
|
|
|
// Assert
|
|
result.Should().BeTrue();
|
|
}
|
|
|
|
#endregion
|
|
}
|