AccountingNext/Schaad.Accounting.Tests/ElectricityHalfYearTestShould.cs
Claudio Schaad ca4a67f20a Remove Akonto and Saldo from the electricity bills
Drop the advance payment (AdvanceChf) and the computed Balance from
ElectricityBill, the Strom list, the edit dialog and the help image.

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

79 lines
2.4 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;
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);
}
}
[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 };
}