The price-per-kWh line only showed the blended total; add GridChfPerKwh and PvChfPerKwh (null when there was no draw/consumption of that kind, so the chart shows a gap instead of a misleading 0) and plot Netz, PV and Total as separate lines. Also fixes the y-axis: ticks used a fixed 0-decimal formatter, so CHF/kWh values (well under 1) all rounded to "0". charts.js now takes an optional data.axisDecimals (defaults to 0, so the Analyse page is unaffected); the Strom page passes 2 for its CHF/kWh chart. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
104 lines
2.6 KiB
C#
104 lines
2.6 KiB
C#
using Schaad.Accounting.Models;
|
|
using Shouldly;
|
|
|
|
namespace Schaad.Accounting.Tests;
|
|
|
|
public class ElectricityBillTestShould
|
|
{
|
|
[Fact]
|
|
public void AddGridAndPvWhenCalculatingTotalKwh()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 3419.432m, PvKwh = 1936.328m };
|
|
|
|
bill.TotalKwh.ShouldBe(5355.76m);
|
|
}
|
|
|
|
[Fact]
|
|
public void DividePvByTotalWhenCalculatingPvShare()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 600m, PvKwh = 400m };
|
|
|
|
bill.PvShare.ShouldBe(0.4m);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnZeroPvShareWhenThereIsNoConsumption()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 0m, PvKwh = 0m };
|
|
|
|
bill.PvShare.ShouldBe(0m);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddGridPvAndSideCostsWhenCalculatingTotalChf()
|
|
{
|
|
var bill = new ElectricityBill { GridChf = 1009.55m, PvChf = 544.10m, SideCostsChf = 134.30m };
|
|
|
|
bill.TotalChf.ShouldBe(1687.95m);
|
|
}
|
|
|
|
[Fact]
|
|
public void CalculateBalanceWhenAdvanceIsSubtractedFromTotal()
|
|
{
|
|
var bill = new ElectricityBill
|
|
{
|
|
GridKwh = 3419.432m,
|
|
PvKwh = 1936.328m,
|
|
GridChf = 1009.55m,
|
|
PvChf = 544.10m,
|
|
SideCostsChf = 134.30m,
|
|
AdvanceChf = 1212.00m
|
|
};
|
|
|
|
bill.TotalChf.ShouldBe(1687.95m);
|
|
bill.Balance.ShouldBe(475.95m);
|
|
}
|
|
|
|
[Fact]
|
|
public void DivideTotalChfByTotalKwhWhenCalculatingChfPerKwh()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 600m, PvKwh = 400m, GridChf = 60m, PvChf = 40m };
|
|
|
|
bill.ChfPerKwh.ShouldBe(0.1m);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnZeroChfPerKwhWhenThereIsNoConsumption()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 0m, PvKwh = 0m, GridChf = 0m, PvChf = 0m, SideCostsChf = 50m };
|
|
|
|
bill.ChfPerKwh.ShouldBe(0m);
|
|
}
|
|
|
|
[Fact]
|
|
public void DivideGridChfByGridKwhWhenCalculatingGridChfPerKwh()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 600m, GridChf = 180m };
|
|
|
|
bill.GridChfPerKwh.ShouldBe(0.3m);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnNullGridChfPerKwhWhenThereWasNoGridDraw()
|
|
{
|
|
var bill = new ElectricityBill { GridKwh = 0m, GridChf = 0m };
|
|
|
|
bill.GridChfPerKwh.ShouldBeNull();
|
|
}
|
|
|
|
[Fact]
|
|
public void DividePvChfByPvKwhWhenCalculatingPvChfPerKwh()
|
|
{
|
|
var bill = new ElectricityBill { PvKwh = 400m, PvChf = 100m };
|
|
|
|
bill.PvChfPerKwh.ShouldBe(0.25m);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReturnNullPvChfPerKwhWhenThereWasNoPvConsumption()
|
|
{
|
|
var bill = new ElectricityBill { PvKwh = 0m, PvChf = 0m };
|
|
|
|
bill.PvChfPerKwh.ShouldBeNull();
|
|
}
|
|
}
|