AccountingNext/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs
Claudio Schaad df52237420 Show the Strom charts per half-year
Each bill's values are spread evenly over the months of its period and
summed per calendar half-year, so a yearly July-June bill contributes
half to each of its two halves. Half-years without a bill appear as gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 19:28:29 +01:00

81 lines
2.5 KiB
C#

using Schaad.Accounting.Models;
using Shouldly;
namespace Schaad.Accounting.Tests;
public class ElectricityHalfYearTestShould
{
[Fact]
public void SplitYearlyBillIntoTwoHalvesWhenPeriodRunsJulyToJune()
{
var bill = Bill(new DateOnly(2023, 7, 1), new DateOnly(2024, 6, 30));
bill.GridKwh = 3000m;
bill.PvKwh = 2000m;
bill.GridChf = 900m;
bill.PvChf = 400m;
bill.SideCostsChf = 100m;
bill.AdvanceChf = 1200m;
var halves = ElectricityHalfYear.FromBills([bill]);
halves.Count.ShouldBe(2);
halves[0].From.ShouldBe(new DateOnly(2023, 7, 1));
halves[1].From.ShouldBe(new DateOnly(2024, 1, 1));
foreach (var half in halves)
{
half.Bill.GridKwh.ShouldBe(1500m);
half.Bill.PvKwh.ShouldBe(1000m);
half.Bill.GridChf.ShouldBe(450m);
half.Bill.PvChf.ShouldBe(200m);
half.Bill.SideCostsChf.ShouldBe(50m);
half.Bill.AdvanceChf.ShouldBe(600m);
}
}
[Fact]
public void KeepPricePerKwhOfTheBillWhenSplittingIt()
{
var bill = Bill(new DateOnly(2023, 7, 1), new DateOnly(2024, 6, 30));
bill.GridKwh = 3000m;
bill.GridChf = 900m;
var halves = ElectricityHalfYear.FromBills([bill]);
halves.ShouldAllBe(h => h.Bill.GridChfPerKwh == 0.3m);
}
[Fact]
public void AddUpBillsWhenTheyShareAHalfYear()
{
var first = Bill(new DateOnly(2024, 1, 1), new DateOnly(2024, 3, 31));
first.GridKwh = 100m;
var second = Bill(new DateOnly(2024, 4, 1), new DateOnly(2024, 6, 30));
second.GridKwh = 200m;
var halves = ElectricityHalfYear.FromBills([first, second]);
halves.Count.ShouldBe(1);
halves[0].Bill.GridKwh.ShouldBe(300m);
}
[Fact]
public void IncludeEmptyHalfYearWhenNoBillCoversIt()
{
var first = Bill(new DateOnly(2022, 7, 1), new DateOnly(2023, 6, 30));
var later = Bill(new DateOnly(2024, 7, 1), new DateOnly(2025, 6, 30));
var halves = ElectricityHalfYear.FromBills([later, first]);
halves.Select(h => h.Label).ShouldBe(["H2 22", "H1 23", "H2 23", "H1 24", "H2 24", "H1 25"]);
halves[2].Bill.ShouldBeNull();
halves[3].Bill.ShouldBeNull();
}
[Fact]
public void ReturnEmptyListWhenThereAreNoBills()
{
ElectricityHalfYear.FromBills([]).ShouldBeEmpty();
}
private static ElectricityBill Bill(DateOnly from, DateOnly to) => new() { PeriodFrom = from, PeriodTo = to };
}