AccountingNext/Schaad.Accounting.Tests/WaterHeatingBillChecksTestShould.cs
Claudio Schaad a58f08e82a Wasser & Heizung: plausibility checks in the bill dialog
The dialog shows a "Kontrolle" section (WaterHeatingBillChecks): the NeoVac
per-mille shares against the optional ones of the property manager,
optional meter readings continuing from the previous bill, the property
totals implied by the own share, and the prices per unit compared with
the previous bill (flagged above ±25 %).

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

151 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Schaad.Accounting.Models;
using Shouldly;
namespace Schaad.Accounting.Tests;
public class WaterHeatingBillChecksTestShould
{
// Values of the 2024/25 bill: NeoVac per-mille shares and the own share from the property manager.
private static WaterHeatingBill Bill()
{
var bill = new WaterHeatingBill
{
Id = "b2025",
PeriodFrom = new DateOnly(2024, 7, 1),
PeriodTo = new DateOnly(2025, 6, 30),
WarmWaterM3 = 16.399m,
ColdWaterM3 = 51.464m,
HeatingMwh = 2.458m,
WaterBasePermille = 19.52m,
WaterConsumptionPermille = 68.50m,
HeatingPermille = 62.82m,
WarmWaterHeatingPermille = 12.66m,
WaterCostsChf = 304.30m,
HeatingCostsChf = 451.65m
};
bill.CalculateCosts();
return bill;
}
[Fact]
public void PassWhenNeoVacPermilleMatchesPropertyManager()
{
var bill = Bill();
bill.ManagerWaterPermille = 88.02m;
bill.ManagerHeatingPermille = 62.82m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text.StartsWith("Wasser: NeoVac 19.52 + 68.50 = 88.02 ‰"));
checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text.StartsWith("Heizung: NeoVac 62.82 ‰"));
}
[Fact]
public void WarnWhenNeoVacPermilleDiffersFromPropertyManager()
{
var bill = Bill();
bill.ManagerWaterPermille = 88.20m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Wasser: NeoVac"));
}
[Fact]
public void LeaveOutPermilleChecksWhenPropertyManagerValuesAreMissing()
{
var checks = WaterHeatingBillChecks.Check(Bill(), null);
checks.ShouldNotContain(c => c.Text.StartsWith("Wasser: NeoVac") || c.Text.StartsWith("Heizung: NeoVac"));
}
[Fact]
public void WarnWhenWarmWaterHeatingPermilleIsAboveHeatingPermille()
{
var bill = Bill();
bill.WarmWaterHeatingPermille = 70m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung WW 70.00 ‰"));
}
[Fact]
public void PassWhenMeterContinuesFromPreviousBill()
{
var previous = Bill();
previous.WarmWaterMeter = 134.151m;
var bill = Bill();
bill.WarmWaterMeter = 150.550m;
var checks = WaterHeatingBillChecks.Check(bill, previous);
checks.ShouldContain(new BillCheck(BillCheckResult.Ok, "Zähler Warmwasser: 134.151 (Vorperiode) + 16.399 = 150.550"));
}
[Fact]
public void WarnWhenMeterDoesNotContinueFromPreviousBill()
{
var previous = Bill();
previous.ColdWaterMeter = 333.273m;
var bill = Bill();
bill.ColdWaterMeter = 384.740m;
var checks = WaterHeatingBillChecks.Check(bill, previous);
checks.ShouldContain(new BillCheck(BillCheckResult.Warning, "Zähler Kaltwasser: 333.273 (Vorperiode) + 51.464 = 384.737, Stand neu ist 384.740"));
}
[Fact]
public void ShowOldMeterReadingWhenThereIsNoPreviousReading()
{
var bill = Bill();
bill.HeatingMeter = 21.575m;
var checks = WaterHeatingBillChecks.Check(bill, null);
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Zähler Wärme: Stand alt = 21.575 − 2.458 = 19.117"));
}
[Fact]
public void ShowPropertyCostsDerivedFromOwnShare()
{
var checks = WaterHeatingBillChecks.Check(Bill(), null);
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Liegenschaft: Wasserkosten 3'457.17 CHF, Heizkosten 7'189.59 CHF"));
}
[Fact]
public void ShowPricesPerUnitWhenThereIsNoPreviousBill()
{
var checks = WaterHeatingBillChecks.Check(Bill(), null);
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Wasser: 3.49 CHF/m³"));
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Heizung Warmwasser: 5.55 CHF/m³"));
checks.ShouldContain(new BillCheck(BillCheckResult.Info, "Heizung Räume: 146.72 CHF/MWh"));
}
[Fact]
public void WarnWhenPriceChangesMoreThanAllowedAgainstPreviousBill()
{
var previous = Bill();
previous.HeatingCostsChf = 300m;
previous.CalculateCosts();
var checks = WaterHeatingBillChecks.Check(Bill(), previous);
checks.ShouldContain(c => c.Result == BillCheckResult.Warning && c.Text.StartsWith("Heizung Räume: 146.72 CHF/MWh (Vorperiode"));
checks.ShouldContain(c => c.Result == BillCheckResult.Ok && c.Text == "Wasser: 3.49 CHF/m³ (Vorperiode 3.49, 0%)");
}
[Fact]
public void PickBillThatEndedLastBeforeThisOneAsPrevious()
{
var bill = Bill();
var older = new WaterHeatingBill { Id = "a", PeriodFrom = new DateOnly(2022, 7, 1), PeriodTo = new DateOnly(2023, 6, 30) };
var last = new WaterHeatingBill { Id = "b", PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) };
var later = new WaterHeatingBill { Id = "c", PeriodFrom = new DateOnly(2025, 7, 1), PeriodTo = new DateOnly(2026, 6, 30) };
WaterHeatingBillChecks.PreviousOf([later, older, bill, last], bill).ShouldBeSameAs(last);
}
}