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,6 +1,10 @@
|
||||
#region
|
||||
|
||||
using FluentAssertions;
|
||||
using PowerMonitorManager.Models;
|
||||
|
||||
#endregion
|
||||
|
||||
namespace PowerMonitor.Manager.Tests;
|
||||
|
||||
public class CostAccumulatorTests
|
||||
@@ -27,11 +31,14 @@ public class CostAccumulatorTests
|
||||
|
||||
// Act
|
||||
var tasks = Enumerable.Range(0, threadCount)
|
||||
.Select(_ => Task.Run(() =>
|
||||
{
|
||||
for (var i = 0; i < callsPerThread; i++) sut.AddCost(incrementPerCall, now.AddSeconds(1));
|
||||
}))
|
||||
.ToArray();
|
||||
.Select(_ => Task.Run(() =>
|
||||
{
|
||||
for (var i = 0; i < callsPerThread; i++)
|
||||
{
|
||||
sut.AddCost(incrementPerCall, now.AddSeconds(1));
|
||||
}
|
||||
}))
|
||||
.ToArray();
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
|
||||
@@ -47,11 +54,7 @@ public class CostAccumulatorTests
|
||||
{
|
||||
return window switch
|
||||
{
|
||||
CostWindow.FifteenMinutes => snapshot.Cost15Min,
|
||||
CostWindow.Hour => snapshot.Cost1Hour,
|
||||
CostWindow.Day => snapshot.CostDaily,
|
||||
CostWindow.Month => snapshot.CostMonthly,
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(window))
|
||||
CostWindow.FifteenMinutes => snapshot.Cost15Min, CostWindow.Hour => snapshot.Cost1Hour, CostWindow.Day => snapshot.CostDaily, CostWindow.Month => snapshot.CostMonthly, _ => throw new ArgumentOutOfRangeException(nameof(window))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,12 +119,16 @@ public class CostAccumulatorTests
|
||||
// Arrange
|
||||
var now = PowerMonitorTestData.FixedNow;
|
||||
var sut = new CostAccumulator(now);
|
||||
|
||||
var increments = PowerMonitorTestData.CreatePowerSampleSeries(50)
|
||||
.Select(watts => watts / 100_000.0)
|
||||
.ToArray();
|
||||
.Select(watts => watts / 100_000.0)
|
||||
.ToArray();
|
||||
|
||||
// Act
|
||||
foreach (var increment in increments) sut.AddCost(increment, now.AddSeconds(1));
|
||||
foreach (var increment in increments)
|
||||
{
|
||||
sut.AddCost(increment, now.AddSeconds(1));
|
||||
}
|
||||
|
||||
// Assert
|
||||
var expected = increments.Sum();
|
||||
@@ -191,7 +198,7 @@ public class CostAccumulatorTests
|
||||
|
||||
#region Window rollovers
|
||||
|
||||
public static TheoryData<string, CostWindow, DateTime, DateTime, double, double> WindowRolloverCases => new()
|
||||
public static TheoryData<string, CostWindow, DateTime, DateTime, double, double> WindowRolloverCases => new TheoryData<string, CostWindow, DateTime, DateTime, double, double>
|
||||
{
|
||||
{
|
||||
"15 minute slot ends", CostWindow.FifteenMinutes, new DateTime(2026, 3, 17, 10, 14, 0),
|
||||
@@ -323,7 +330,7 @@ public class CostAccumulatorTests
|
||||
|
||||
#region Window boundary detection (static methods)
|
||||
|
||||
public static TheoryData<string, DateTime, DateTime, bool> FifteenMinuteBoundaryCases => new()
|
||||
public static TheoryData<string, DateTime, DateTime, bool> FifteenMinuteBoundaryCases => new TheoryData<string, DateTime, DateTime, bool>
|
||||
{
|
||||
{ "same slot, first second", new DateTime(2026, 3, 17, 10, 0, 0), new DateTime(2026, 3, 17, 10, 0, 0), false },
|
||||
{ "same slot, last second", new DateTime(2026, 3, 17, 10, 0, 0), new DateTime(2026, 3, 17, 10, 14, 59), false },
|
||||
@@ -344,7 +351,7 @@ public class CostAccumulatorTests
|
||||
CostAccumulator.IsNew15MinWindow(now, lastReset).Should().Be(expected, $"scenario: {scenario}");
|
||||
}
|
||||
|
||||
public static TheoryData<string, DateTime, DateTime, bool> HourBoundaryCases => new()
|
||||
public static TheoryData<string, DateTime, DateTime, bool> HourBoundaryCases => new TheoryData<string, DateTime, DateTime, bool>
|
||||
{
|
||||
{ "same hour, same minute", new DateTime(2026, 3, 17, 10, 0, 0), new DateTime(2026, 3, 17, 10, 0, 0), false },
|
||||
{
|
||||
@@ -366,7 +373,7 @@ public class CostAccumulatorTests
|
||||
CostAccumulator.IsNewHourWindow(now, lastReset).Should().Be(expected, $"scenario: {scenario}");
|
||||
}
|
||||
|
||||
public static TheoryData<string, DateTime, DateTime, bool> DayBoundaryCases => new()
|
||||
public static TheoryData<string, DateTime, DateTime, bool> DayBoundaryCases => new TheoryData<string, DateTime, DateTime, bool>
|
||||
{
|
||||
{ "same timestamp", new DateTime(2026, 3, 17, 0, 0, 0), new DateTime(2026, 3, 17, 0, 0, 0), false },
|
||||
{ "same day, last second", new DateTime(2026, 3, 17, 0, 0, 0), new DateTime(2026, 3, 17, 23, 59, 59), false },
|
||||
@@ -385,7 +392,7 @@ public class CostAccumulatorTests
|
||||
CostAccumulator.IsNewDayWindow(now, lastReset).Should().Be(expected, $"scenario: {scenario}");
|
||||
}
|
||||
|
||||
public static TheoryData<string, DateTime, DateTime, bool> MonthBoundaryCases => new()
|
||||
public static TheoryData<string, DateTime, DateTime, bool> MonthBoundaryCases => new TheoryData<string, DateTime, DateTime, bool>
|
||||
{
|
||||
{ "same month, first day", new DateTime(2026, 3, 1, 0, 0, 0), new DateTime(2026, 3, 1, 0, 0, 0), false },
|
||||
{ "same month, last day", new DateTime(2026, 3, 1, 0, 0, 0), new DateTime(2026, 3, 31, 23, 59, 59), false },
|
||||
|
||||
Reference in New Issue
Block a user