AccountingNext/Schaad.Accounting.Tests/SettingsServiceTestShould.cs
Claudio Schaad 7d7bd6073c Add "Strom" page for the yearly NeoVac electricity bill
A new page (/electricity) to record one electricity bill per billing
period (1 July-30 June) with a grid, add/edit dialog, and two Chart.js
charts (kWh split grid/PV per period, CHF/kWh as a line).

- ElectricityBill (Common): Grid/PV kWh and CHF, side costs, advance
  payment; computed TotalKwh, PvShare, TotalChf, Balance, ChfPerKwh.
- Stored once per mandator at {DataPath}/{mandator}/electricity.json
  instead of per year, since the billing period doesn't align with
  calendar years (new ISettingsService.GetMandatorPath(),
  BaseRepository gets a directory-aware SaveAsync overload).
- electricity.json is also editable through the JSON editor
  (RawDataRepository).
- charts.js: stackedBar/line charts can now show a unit other than
  CHF (defaults to CHF, so the Analyse page is unaffected).
- The add/edit dialog links to an annotated example (SVG, placeholder
  data) showing which value on the real NeoVac bill goes into which
  field; opens in its own dialog since the main dialog has a fixed
  height.
- Tests for the computed properties and the new repositories.

Also bumps the TargetFramework to net10.0 and updates the local
DataPath in appsettings.Development.json.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-10-25 20:30:40 +01:00

69 lines
2.3 KiB
C#

using Schaad.Accounting.Datasets;
using Schaad.Accounting.Services;
using Shouldly;
namespace Schaad.Accounting.Tests;
public class SettingsServiceTestShould : IDisposable
{
private readonly string dataPath;
private readonly SettingsService sut;
public SettingsServiceTestShould()
{
dataPath = Path.Combine(Path.GetTempPath(), "AccountingNext-tests-" + Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(dataPath);
sut = new SettingsService(new SettingsDataset { DataPath = dataPath, DefaultMandator = "Mandator" });
sut.SetYear(2025);
}
public void Dispose()
{
if (Directory.Exists(dataPath))
{
Directory.Delete(dataPath, recursive: true);
}
}
[Fact]
public void ReturnMandatorYearFolderWhenGettingDbPath()
{
sut.GetDbPath().ShouldBe(Path.Combine(dataPath, "Mandator", "2025"));
sut.GetLastYearDbPath().ShouldBe(Path.Combine(dataPath, "Mandator", "2024"));
}
[Fact]
public void ReturnMandatorFolderWithoutYearWhenGettingMandatorPath()
{
sut.GetMandatorPath().ShouldBe(Path.Combine(dataPath, "Mandator"));
}
[Fact]
public void ReturnFoldersBelowRootUploadsWhenGettingUploadPaths()
{
sut.GetUploadPath().ShouldBe(Path.Combine(dataPath, "uploads", "Mandator", "2025"));
sut.GetCreditCardStatementPath().ShouldBe(Path.Combine(dataPath, "uploads", "Mandator", "2025", "creditCard"));
}
[Fact]
public void ReturnZipBelowRootBackupWhenGettingBackupFilePath()
{
var path = sut.GetBackupFilePath();
Path.GetDirectoryName(path).ShouldBe(Path.Combine(dataPath, "backup", "Mandator", "2025"));
Path.GetExtension(path).ShouldBe(".zip");
}
[Fact]
public void ListOnlyMandatorsWithThatYearWhenGettingMandators()
{
Directory.CreateDirectory(Path.Combine(dataPath, "Mandator", "2025"));
Directory.CreateDirectory(Path.Combine(dataPath, "Other", "2025"));
Directory.CreateDirectory(Path.Combine(dataPath, "OnlyOlder", "2023"));
Directory.CreateDirectory(Path.Combine(dataPath, "uploads", "2025"));
Directory.CreateDirectory(Path.Combine(dataPath, "backup", "2025"));
sut.GetMandators(2025).OrderBy(m => m).ShouldBe(["Mandator", "Other"]);
}
}