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,3 +1,5 @@
|
||||
#region
|
||||
|
||||
using System.Reactive.Concurrency;
|
||||
using BoilerMonitor.Models;
|
||||
using FluentAssertions;
|
||||
@@ -11,6 +13,8 @@ using NordPoolManager;
|
||||
using NordPoolManager.Interface;
|
||||
using NordPoolManager.Models;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace NordPool.Manager.Tests;
|
||||
|
||||
public class NordPoolInitTests
|
||||
@@ -39,14 +43,18 @@ public class NordPoolInitTests
|
||||
_services = new Services(_haContextMock.Object);
|
||||
|
||||
_priceServiceMock
|
||||
.Setup(p => p.FetchPricesAsync(It.IsAny<Func<DateOnly, Task<NordPoolPrice>>>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
.Setup(p => p.FetchPricesAsync(It.IsAny<Func<DateOnly, Task<NordPoolPrice>>>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
_entityServiceMock.Setup(e => e.CleanupEntitiesAsync(It.IsAny<CancellationToken>()))
|
||||
.Returns(Task.CompletedTask);
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
_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);
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
_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);
|
||||
@@ -54,36 +62,39 @@ public class NordPoolInitTests
|
||||
_priceServiceMock.SetupGet(p => p.TomorrowNordPoolPrice).Returns((NordPoolPrice?)null);
|
||||
_priceServiceMock.SetupGet(p => p.CurrentPrice).Returns(0.0);
|
||||
_priceServiceMock.SetupGet(p => p.LastUpdatedDate).Returns((DateTime?)null);
|
||||
|
||||
_cheapestIntervalsFinderMock
|
||||
.Setup(c => c.IsCurrentIntervalCheap(It.IsAny<IReadOnlyList<CheapestIntervalResult>>(),
|
||||
It.IsAny<DateTime>()))
|
||||
.Returns(false);
|
||||
_boilerConfigProviderMock.Setup(b => b.GetCurrentConfiguration()).Returns(new BoilerConfig
|
||||
{
|
||||
IntervalCount = 4,
|
||||
PriceCap = double.MaxValue,
|
||||
Deadline = DateTime.Today.AddDays(1),
|
||||
SkipPriceCap = false
|
||||
});
|
||||
.Setup(c => c.IsCurrentIntervalCheap(It.IsAny<IReadOnlyList<CheapestIntervalResult>>(),
|
||||
It.IsAny<DateTime>()))
|
||||
.Returns(false);
|
||||
|
||||
_boilerConfigProviderMock.Setup(b => b.GetCurrentConfiguration())
|
||||
.Returns(new BoilerConfig
|
||||
{
|
||||
IntervalCount = 4,
|
||||
PriceCap = double.MaxValue,
|
||||
Deadline = DateTime.Today.AddDays(1),
|
||||
SkipPriceCap = false
|
||||
});
|
||||
}
|
||||
|
||||
private NordPoolInit CreateSut(NordPoolOptions? nordPoolOptions = null)
|
||||
{
|
||||
var options = Options.Create(
|
||||
nordPoolOptions ?? new NordPoolOptions { CleanupEntitiesOnStartup = false });
|
||||
nordPoolOptions ?? new NordPoolOptions { CleanupEntitiesOnStartup = false });
|
||||
|
||||
return new NordPoolInit(
|
||||
_entities,
|
||||
_services,
|
||||
_haContextMock.Object,
|
||||
_loggerMock.Object,
|
||||
_priceServiceMock.Object,
|
||||
_entityServiceMock.Object,
|
||||
_schedulerMock.Object,
|
||||
_cheapestIntervalsFinderMock.Object,
|
||||
_boilerConfigProviderMock.Object,
|
||||
options,
|
||||
TimeProvider.System);
|
||||
_entities,
|
||||
_services,
|
||||
_haContextMock.Object,
|
||||
_loggerMock.Object,
|
||||
_priceServiceMock.Object,
|
||||
_entityServiceMock.Object,
|
||||
_schedulerMock.Object,
|
||||
_cheapestIntervalsFinderMock.Object,
|
||||
_boilerConfigProviderMock.Object,
|
||||
options,
|
||||
TimeProvider.System);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -107,29 +118,34 @@ public class NordPoolInitTests
|
||||
|
||||
// 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());
|
||||
es => es.CleanupEntitiesAsync(It.IsAny<CancellationToken>()),
|
||||
cleanupEntitiesOnStartup ? Times.AtLeastOnce() : Times.Never());
|
||||
|
||||
_entityServiceMock.Verify(es => es.CreateEntitiesAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()),
|
||||
Times.AtLeastOnce);
|
||||
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);
|
||||
es => es.UpdateEntitiesAsync(It.IsAny<EntityUpdateContext>(), It.IsAny<CancellationToken>()),
|
||||
Times.AtLeastOnce);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
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"));
|
||||
.Setup(es => es.CreateEntitiesAsync(It.IsAny<string>(), It.IsAny<CancellationToken>()))
|
||||
.ThrowsAsync(new InvalidOperationException("create failed"));
|
||||
|
||||
var act = sut.InitializeAsync;
|
||||
|
||||
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);
|
||||
es => es.UpdateEntitiesAsync(It.IsAny<EntityUpdateContext>(), It.IsAny<CancellationToken>()), Times.Never);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user