AccountingNext/Schaad.Accounting.Tests/WaterHeatingBillRepositoryTestShould.cs
Claudio Schaad 53e4854bc2 Add "Wasser & Heizung" page for the NeoVac water and heating bills
NeoVac only reports per-mille shares of the property; the own costs in CHF
come from the property manager's statement. The new page stores both in
water-heating.json (per mandator) and calculates the CHF parts: water base
and consumption costs by their per-mille share, consumption split by m³
into warm and cold water, and the warm water part of the heating costs
(the rest is room heating). Charts for water (m³), heat (MWh) and the
stacked costs; the dialog has a guide image showing where each value is
on the bills. The Wasser page stays for bills with the CHF values entered
directly.

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

93 lines
3.2 KiB
C#

using Microsoft.Extensions.Logging.Abstractions;
using NSubstitute;
using Schaad.Accounting.Interfaces;
using Schaad.Accounting.Models;
using Schaad.Accounting.Repositories;
using Shouldly;
namespace Schaad.Accounting.Tests;
public class WaterHeatingBillRepositoryTestShould : IDisposable
{
private readonly string mandatorDir;
private readonly ISettingsService settingsService;
private readonly WaterHeatingBillRepository sut;
public WaterHeatingBillRepositoryTestShould()
{
mandatorDir = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(mandatorDir);
settingsService = Substitute.For<ISettingsService>();
settingsService.GetMandatorPath().Returns(mandatorDir);
sut = new WaterHeatingBillRepository(settingsService, new RepositoryCache(), NullLogger<WaterHeatingBillRepository>.Instance);
}
public void Dispose()
{
if (Directory.Exists(mandatorDir))
{
Directory.Delete(mandatorDir, recursive: true);
}
}
[Fact]
public async Task ReturnEmptyListWhenFileDoesNotExistYet()
{
(await sut.GetWaterHeatingBillListAsync()).ShouldBeEmpty();
}
[Fact]
public async Task AssignNewIdWhenSavingBillWithoutId()
{
var bill = new WaterHeatingBill
{
PeriodFrom = new DateOnly(2023, 7, 1),
PeriodTo = new DateOnly(2024, 6, 30),
WarmWaterM3 = 12.345m,
ColdWaterM3 = 30.5m,
WaterCostsChf = 304.30m,
HeatingCostsChf = 451.65m
};
await sut.SaveWaterHeatingBillAsync(bill);
var stored = (await sut.GetWaterHeatingBillListAsync()).Single();
stored.Id.ShouldNotBeNullOrEmpty();
stored.TotalM3.ShouldBe(42.845m);
stored.TotalChf.ShouldBe(755.95m);
}
[Fact]
public async Task UpdateInPlaceWhenSavingBillWithExistingId()
{
await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 10m });
var id = (await sut.GetWaterHeatingBillListAsync()).Single().Id;
await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { Id = id, PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30), WarmWaterM3 = 13m });
var bills = await sut.GetWaterHeatingBillListAsync();
bills.Count.ShouldBe(1);
bills[0].WarmWaterM3.ShouldBe(13m);
}
[Fact]
public async Task RemoveBillWhenDeletingById()
{
await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) });
var id = (await sut.GetWaterHeatingBillListAsync()).Single().Id;
await sut.DeleteWaterHeatingBillAsync(id);
(await sut.GetWaterHeatingBillListAsync()).ShouldBeEmpty();
}
[Fact]
public async Task StoreFileDirectlyInMandatorFolderWithoutYearSubfolder()
{
await sut.SaveWaterHeatingBillAsync(new WaterHeatingBill { PeriodFrom = new DateOnly(2023, 7, 1), PeriodTo = new DateOnly(2024, 6, 30) });
File.Exists(Path.Combine(mandatorDir, "water-heating.json")).ShouldBeTrue();
}
}