Add shared test data builders and Qodana configuration
- Extract per-monitor *TestData helper classes and rework tests to use them - Add boiler run-time tracker abstraction (implementation pending) - Drop unused NordPool init/update-result types and stale PLAN.md - Add qodana.yaml with the inspection set to keep the analysis focused
This commit is contained in:
@@ -41,7 +41,7 @@ public class NordPoolInitTests
|
||||
_entityServiceMock.Setup(e => e.CreateEntitiesAsync(It.IsAny<string>())).Returns(Task.CompletedTask);
|
||||
_entityServiceMock.Setup(e => e.ResetEntitiesAsync()).Returns(Task.CompletedTask);
|
||||
_entityServiceMock.Setup(e => e.UpdateEntitiesAsync(It.IsAny<EntityUpdateContext>())).Returns(Task.CompletedTask);
|
||||
_priceServiceMock.Setup(p => p.UpdateCurrentPrice()).Returns(0.0);
|
||||
_priceServiceMock.Setup(p => p.GetCurrentPrice()).Returns(0.0);
|
||||
_priceServiceMock.Setup(p => p.ShouldFetchNewPrices(It.IsAny<DateOnly>())).Returns(false);
|
||||
_priceServiceMock.SetupGet(p => p.DayQuartersIndex).Returns(0);
|
||||
_priceServiceMock.SetupGet(p => p.TodayNordPoolPrice).Returns((NordPoolPrice?)null);
|
||||
@@ -88,38 +88,36 @@ public class NordPoolInitTests
|
||||
sut.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task CleanupEntitiesAsync_ShouldDelegateToEntityService()
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task InitializeAsync_ShouldRespectCleanupOnStartupSetting(bool cleanupEntitiesOnStartup)
|
||||
{
|
||||
// Arrange
|
||||
var sut = CreateSut();
|
||||
_entityServiceMock.Setup(es => es.CleanupEntitiesAsync(It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
// Act
|
||||
await sut.CleanupEntitiesAsync();
|
||||
|
||||
// Assert
|
||||
_entityServiceMock.Verify(es => es.CleanupEntitiesAsync(It.IsAny<CancellationToken>()), Times.Once);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeAsync_WhenCleanupEntitiesOnStartupIsTrue_ShouldCallEntityCleanup()
|
||||
{
|
||||
var sut = CreateSut(new NordPoolOptions { CleanupEntitiesOnStartup = true });
|
||||
var sut = CreateSut(new NordPoolOptions { CleanupEntitiesOnStartup = cleanupEntitiesOnStartup });
|
||||
|
||||
await sut.InitializeAsync();
|
||||
|
||||
_entityServiceMock.Verify(es => es.CleanupEntitiesAsync(It.IsAny<CancellationToken>()), Times.AtLeastOnce);
|
||||
// The constructor also starts the same init flow in the background, so calls may happen more than once.
|
||||
_entityServiceMock.Verify(
|
||||
es => es.CleanupEntitiesAsync(It.IsAny<CancellationToken>()),
|
||||
cleanupEntitiesOnStartup ? Times.AtLeastOnce() : Times.Never());
|
||||
_entityServiceMock.Verify(es => es.CreateEntitiesAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()), Times.AtLeastOnce);
|
||||
_entityServiceMock.Verify(es => es.ResetEntitiesAsync(It.IsAny<CancellationToken>()), Times.AtLeastOnce);
|
||||
_entityServiceMock.Verify(es => es.UpdateEntitiesAsync(It.IsAny<EntityUpdateContext>(), It.IsAny<CancellationToken>()), Times.AtLeastOnce);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task InitializeAsync_WhenCleanupEntitiesOnStartupIsFalse_ShouldNotCallEntityCleanup()
|
||||
public async Task InitializeAsync_WhenCreatingEntitiesFails_ShouldRethrow()
|
||||
{
|
||||
var sut = CreateSut(new NordPoolOptions { CleanupEntitiesOnStartup = false });
|
||||
_entityServiceMock
|
||||
.Setup(es => es.CreateEntitiesAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.ThrowsAsync(new InvalidOperationException("create failed"));
|
||||
|
||||
await sut.InitializeAsync();
|
||||
var act = () => sut.InitializeAsync();
|
||||
|
||||
_entityServiceMock.Verify(es => es.CleanupEntitiesAsync(It.IsAny<CancellationToken>()), Times.Never);
|
||||
await act.Should().ThrowAsync<InvalidOperationException>().WithMessage("create failed");
|
||||
_entityServiceMock.Verify(es => es.ResetEntitiesAsync(It.IsAny<CancellationToken>()), Times.Never);
|
||||
_entityServiceMock.Verify(es => es.UpdateEntitiesAsync(It.IsAny<EntityUpdateContext>(), It.IsAny<CancellationToken>()), Times.Never);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user