Billing: Add functionality to collapse curves
This commit is contained in:
@ -1,10 +1,13 @@
|
||||
using Elwig.Helpers;
|
||||
using Elwig.Helpers.Billing;
|
||||
using Elwig.Models.Entities;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Tests.HelperTests {
|
||||
[TestFixture]
|
||||
public class BillingDataTest {
|
||||
|
||||
private static readonly JsonSerializerOptions JsonOpts = new() { WriteIndented = true };
|
||||
private static readonly string[] AttributeVariants = ["GV", "GVD", "GVK", "GVS", "GVZ", "WR", "WRS", "ZW", "ZWS", "ZWZ"];
|
||||
|
||||
[OneTimeSetUp]
|
||||
@ -41,7 +44,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_01_Flatrate() {
|
||||
public void TestRead_01_Flatrate() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -57,7 +60,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_02_Simple() {
|
||||
public void TestRead_02_Simple() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -92,7 +95,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_03_GreaterThanAndLessThan() {
|
||||
public void TestRead_03_GreaterThanAndLessThan() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -131,7 +134,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_04_VariantsAndAttributes() {
|
||||
public void TestRead_04_VariantsAndAttributes() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -161,7 +164,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_05_QualityLevel() {
|
||||
public void TestRead_05_QualityLevel() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -192,7 +195,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_06_ModeOeAndKmw() {
|
||||
public void TestRead_06_ModeOeAndKmw() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -234,7 +237,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_07_MultipleCurves() {
|
||||
public void TestRead_07_MultipleCurves() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
@ -303,7 +306,7 @@ namespace Tests.HelperTests {
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test_08_WgMaster() {
|
||||
public void TestRead_08_WgMaster() {
|
||||
var data = PaymentBillingData.FromJson("""
|
||||
{
|
||||
"mode": "wgmaster",
|
||||
@ -345,5 +348,162 @@ namespace Tests.HelperTests {
|
||||
TestCalcOe(data, "GVK", 115, 0.065m);
|
||||
});
|
||||
}
|
||||
|
||||
private static List<ContractSelection> GetSelection(IEnumerable<string> attVars) {
|
||||
return attVars.Select(s => {
|
||||
var sortid = s[..2];
|
||||
var attrid = s.Length > 2 ? s[2..] : null;
|
||||
return new ContractSelection(
|
||||
new WineVar(sortid, sortid),
|
||||
attrid == null ? null : new WineAttr(attrid, attrid)
|
||||
);
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_01_Empty() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(1, 4, BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m
|
||||
}, null)
|
||||
];
|
||||
var updated = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(updated.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": 0,
|
||||
"curves": []
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_02_Flatrate() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m
|
||||
}, null), GetSelection(["GV"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": 0.5,
|
||||
"curves": []
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_03_SingleCurve() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[83] = 1.0m
|
||||
}, null), GetSelection(["GV"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": "curve:1",
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"83oe": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_04_Simple() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GV", "ZW"])),
|
||||
new GraphEntry(10, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"WR/": 0.75,
|
||||
"default": "curve:1"
|
||||
},
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"84oe": 1
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestWrite_05_Attribute() {
|
||||
List<GraphEntry> entries = [
|
||||
new GraphEntry(0, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.5m,
|
||||
[84] = 1.0m
|
||||
}, null), GetSelection(["GVB", "ZWB"])),
|
||||
new GraphEntry(2, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.75m,
|
||||
}, null), GetSelection(["WR", "BL", "RR", "FV"])),
|
||||
new GraphEntry(4, 4, new BillingData.Curve(BillingData.CurveMode.Oe, new() {
|
||||
[73] = 0.65m,
|
||||
[84] = 1.2m
|
||||
}, null), GetSelection(["BP", "SA"]))
|
||||
];
|
||||
var data = BillingData.FromGraphEntries(entries);
|
||||
Assert.That(data.ToJsonString(JsonOpts), Is.EqualTo("""
|
||||
{
|
||||
"mode": "elwig",
|
||||
"version": 1,
|
||||
"payment": {
|
||||
"BP/": "curve:2",
|
||||
"SA/": "curve:2",
|
||||
"default": 0.75,
|
||||
"/B": "curve:1"
|
||||
},
|
||||
"curves": [
|
||||
{
|
||||
"id": 1,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.5,
|
||||
"84oe": 1
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"mode": "oe",
|
||||
"data": {
|
||||
"73oe": 0.65,
|
||||
"84oe": 1.2
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
"""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user