Tests: Add DeliveryJournalTest

This commit is contained in:
2024-03-30 10:59:42 +01:00
parent b8851fb241
commit 5c3cf41d3d
4 changed files with 204 additions and 7 deletions

View File

@ -0,0 +1,47 @@
using Elwig.Documents;
using Elwig.Helpers;
using Elwig.Models.Dtos;
namespace Tests.DocumentTests {
[TestFixture]
public class DeliveryJournalTest {
[Test]
public async Task Test_01_AllDeliveries2020() {
using var ctx = new AppDbContext();
var data = await DeliveryJournalData.FromQuery(ctx.Deliveries.Where(d => d.Year == 2020).SelectMany(d => d.Parts), ["Saison 2020"]);
using var doc = new DeliveryJournal("Saison 2020", data);
var text = await Utils.GeneratePdfText(doc, true);
Assert.Multiple(() => {
Assert.That(text, Contains.Substring("Lieferjournal"));
Assert.That(text, Contains.Substring("Saison 2020"));
Assert.That(text, Contains.Substring("""
20201001X001 1 01.10.2020 09:03 101 MUSTERMANN Max Grüner Veltliner 73 15,0 3 219
20201001X002 1 01.10.2020 09:35 102 WEINBAUER Wernhardt Grüner Veltliner 86 17,5 2 987
20201001X002 2 01.10.2020 09:35 102 WEINBAUER Wernhardt Grüner Veltliner 87 17,7 1 873
20201001X003 1 01.10.2020 10:24 101 MUSTERMANN Max Grüner Veltliner 75 15,4 2 561
20201001X003 2 01.10.2020 10:24 101 MUSTERMANN Max Grüner Veltliner 87 17,6 3 129
20201001X003 3 01.10.2020 10:24 101 MUSTERMANN Max Grüner Veltliner 79 16,1 1 280
20201001X004 1 01.10.2020 11:13 102 WEINBAUER Wernhardt Grüner Veltliner 82 16,7 4 002
20201001X004 2 01.10.2020 11:13 102 WEINBAUER Wernhardt Grüner Veltliner 75 15,3 481
20201001X005 1 01.10.2020 12:45 101 MUSTERMANN Max Welschriesling 84 17,0 3 192
20201001X005 2 01.10.2020 12:45 101 MUSTERMANN Max Welschriesling 84 17,1 2 190
20201001X006 1 01.10.2020 13:18 102 WEINBAUER Wernhardt Grüner Veltliner 74 15,2 1 732
20201002X001 1 02.10.2020 09:13 103 MUSTERBAUER Matthäus Grüner Veltliner 80 16,3 3 198
20201002X001 2 02.10.2020 09:13 103 MUSTERBAUER Matthäus Grüner Veltliner 75 15,4 2 134
20201002X002 1 02.10.2020 09:28 103 MUSTERBAUER Matthäus Grüner Veltliner 78 16,0 2 901
20201002X002 2 02.10.2020 09:28 103 MUSTERBAUER Matthäus Grüner Veltliner 85 17,3 3 321
20201002X003 1 02.10.2020 10:11 103 MUSTERBAUER Matthäus Welschriesling 85 17,2 3 998
20201003X001 1 03.10.2020 14:13 104 WINZER Waltraud Zweigelt 73 15,0 1 212
20201003X001 2 03.10.2020 14:13 104 WINZER Waltraud Zweigelt 74 15,2 2 471
20201003X001 3 03.10.2020 14:13 104 WINZER Waltraud Zweigelt 77 15,7 842
20201003X002 1 03.10.2020 14:39 104 WINZER Waltraud Zweigelt 84 17,0 3 578
20201003X002 2 03.10.2020 14:39 104 WINZER Waltraud Zweigelt 85 17,2 3 862
20201003X003 1 03.10.2020 15:15 104 WINZER Waltraud Blauer Portugieser 89 18,0 2 410
20201003X003 2 03.10.2020 15:15 104 WINZER Waltraud Blauer Portugieser 89 18,1 2 313
Gesamt: (Teil-)Lieferungen: 12 (23) 82 16,6 58 886
"""));
});
}
}
}

View File

@ -21,8 +21,124 @@ namespace Tests.DocumentTests {
Assert.That(text, Contains.Substring("pauschaliert"));
Assert.That(text, Contains.Substring($"Wolkersdorf, am {DateTime.Now:dd.MM.yyyy}"));
Assert.That(text, Contains.Substring("Traubenübernahmeschein Nr. 20201001X001"));
// TODO
Assert.That(text, Contains.Substring("Ich bin der Text, der auf einem Traubenübernahmeschein steht!"));
Assert.That(text, Contains.Substring("""
1 Grüner Veltliner Qualitätswein 73 15,0 3 219
Herkunft: Österreich / Weinland / Niederösterreich
/ Matzner Hügel / Hohenruppersdorf / KG Hohenruppersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
});
}
[Test]
public async Task Test_02_TwoDeliveryParts() {
using var ctx = new AppDbContext();
var d = await ctx.Deliveries.FindAsync(2020, 4);
using var doc = new DeliveryNote(d!, ctx);
var text = await Utils.GeneratePdfText(doc);
Assert.Multiple(() => {
Assert.That(text, Contains.Substring("""
W&B Weinbauer GesbR
WEINBAUER Wernhardt
Winzerstraße 2
2223 Hohenruppersdorf
"""));
Assert.That(text, Contains.Substring("4725836")); // Betriebsnummer
Assert.That(text, Contains.Substring("pauschaliert"));
Assert.That(text, Contains.Substring($"Wolkersdorf, am {DateTime.Now:dd.MM.yyyy}"));
Assert.That(text, Contains.Substring("Traubenübernahmeschein Nr. 20201001X004"));
Assert.That(text, Contains.Substring("Ich bin der Text, der auf einem Traubenübernahmeschein steht!"));
Console.WriteLine(text);
Assert.That(text, Contains.Substring("""
1 Grüner Veltliner Qualitätswein 82 16,7 4 002
Herkunft: Österreich / Weinland / Niederösterreich
/ Matzner Hügel / Hohenruppersdorf / KG Hohenruppersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("""
2 Grüner Veltliner Qualitätswein 75 15,3 481
Herkunft: Österreich / Weinland / Niederösterreich
/ Matzner Hügel / Hohenruppersdorf / KG Hohenruppersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("Gesamt: 81 16,5 4 483"));
});
}
[Test]
public async Task Test_03_DeliveryPartsWithAttribute() {
using var ctx = new AppDbContext();
var d = await ctx.Deliveries.FindAsync(2020, 3);
using var doc = new DeliveryNote(d!, ctx);
var text = await Utils.GeneratePdfText(doc);
Assert.Multiple(() => {
Assert.That(text, Contains.Substring("""
MUSTERMANN Max
Winzerstraße 1
2223 Hohenruppersdorf
"""));
Assert.That(text, Contains.Substring("1472583")); // Betriebsnummer
Assert.That(text, Contains.Substring("pauschaliert"));
Assert.That(text, Contains.Substring($"Wolkersdorf, am {DateTime.Now:dd.MM.yyyy}"));
Assert.That(text, Contains.Substring("Traubenübernahmeschein Nr. 20201001X003"));
Assert.That(text, Contains.Substring("Ich bin der Text, der auf einem Traubenübernahmeschein steht!"));
Console.WriteLine(text);
Assert.That(text, Contains.Substring("""
1 Grüner Veltliner Qualitätswein 75 15,4 2 561
Herkunft: Österreich / Weinland / Niederösterreich
/ Matzner Hügel / Hohenruppersdorf / KG Hohenruppersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("""
2 Grüner Veltliner Kabinett Kabinett 87 17,6 3 129
Herkunft: Österreich / Weinland / Niederösterreich
/ Matzner Hügel / Hohenruppersdorf / KG Hohenruppersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("""
3 Grüner Veltliner Qualitätswein 79 16,1 1 280
Herkunft: Österreich / Weinland / Niederösterreich
/ Matzner Hügel / Hohenruppersdorf / KG Hohenruppersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("Gesamt: 81 16,5 6 970"));
});
}
[Test]
public async Task Test_04_DeliveryPartsWithCultivation() {
using var ctx = new AppDbContext();
var d = await ctx.Deliveries.FindAsync(2020, 7);
using var doc = new DeliveryNote(d!, ctx);
var text = await Utils.GeneratePdfText(doc);
Assert.Multiple(() => {
Assert.That(text, Contains.Substring("""
MUSTERBAUER Matthäus
Brünner Straße 10
2120 Wolkersdorf im Weinviertel
"""));
Assert.That(text, Contains.Substring("7258369")); // Betriebsnummer
Assert.That(text, Contains.Substring("pauschaliert"));
Assert.That(text, Contains.Substring($"Wolkersdorf, am {DateTime.Now:dd.MM.yyyy}"));
Assert.That(text, Contains.Substring("Traubenübernahmeschein Nr. 20201002X001"));
Assert.That(text, Contains.Substring("Ich bin der Text, der auf einem Traubenübernahmeschein steht!"));
Console.WriteLine(text);
Assert.That(text, Contains.Substring("""
1 Grüner Veltliner Qualitätswein 80 16,3 3 198
Bewirtschaftung: Bio (AT-BIO-302)
Herkunft: Österreich / Weinland / Niederösterreich
/ Wolkersdorfer Hochleithen / Wolkersdorf im Weinviertel / KG Wolkersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("""
2 Grüner Veltliner Qualitätswein 75 15,4 2 134
Bewirtschaftung: Bio (AT-BIO-302)
Herkunft: Österreich / Weinland / Niederösterreich
/ Wolkersdorfer Hochleithen / Wolkersdorf im Weinviertel / KG Wolkersdorf
Waage: ?, ID: ? (netto/gerebelt gewogen)
"""));
Assert.That(text, Contains.Substring("Gesamt: 78 15,9 5 332"));
});
}
}

View File

@ -3,3 +3,4 @@
DELETE FROM delivery;
DELETE FROM season;
DELETE FROM wine_attribute;
DELETE FROM wine_cultivation;

View File

@ -1,7 +1,9 @@
-- inserts for DocumentTests
INSERT INTO wine_cultivation (cultid, name, description) VALUES
('B', 'Bio', 'AT-BIO-302');
INSERT INTO wine_attribute (attrid, name, active, max_kg_per_ha, strict, fill_lower) VALUES
('B', 'Bio', TRUE, NULL, FALSE, 0),
('K', 'Kabinett', TRUE, NULL, FALSE, 0);
INSERT INTO season (year, currency, min_kg_per_bs, max_kg_per_bs, penalty_per_kg, penalty_amount, penalty_none, start_date, end_date) VALUES
@ -12,9 +14,40 @@ INSERT INTO modifier (year, modid, ordering, name, abs, rel, standard, quick_sel
(2020, 'A', 0, 'Keine Voranmeldung', -1000, NULL, FALSE, FALSE);
INSERT INTO delivery (mgnr, year, did, date, time, zwstid, lnr) VALUES
(101, 2020, 1, '2020-10-01', NULL, 'X', 1),
(101, 2020, 2, '2020-10-01', NULL, 'X', 2),
(101, 2020, 3, '2020-10-01', NULL, 'X', 3);
(101, 2020, 1, '2020-10-01', '09:03:12', 'X', 1),
(102, 2020, 2, '2020-10-01', '09:35:56', 'X', 2),
(101, 2020, 3, '2020-10-01', '10:24:09', 'X', 3),
(102, 2020, 4, '2020-10-01', '11:13:52', 'X', 4),
(101, 2020, 5, '2020-10-01', '12:45:29', 'X', 5),
(102, 2020, 6, '2020-10-01', '13:18:43', 'X', 6),
(103, 2020, 7, '2020-10-02', '09:13:43', 'X', 1),
(103, 2020, 8, '2020-10-02', '09:28:02', 'X', 2),
(103, 2020, 9, '2020-10-02', '10:11:13', 'X', 3),
(104, 2020, 10, '2020-10-03', '14:13:32', 'X', 1),
(104, 2020, 11, '2020-10-03', '14:39:22', 'X', 2),
(104, 2020, 12, '2020-10-03', '15:15:41', 'X', 3);
INSERT INTO delivery_part (year, did, dpnr, sortid, attrid, weight, kmw, qualid, hkid, kgnr, net_weight, manual_weighing, spl_check, scale_id, weighing_id, weighing_reason) VALUES
(2020, 1, 1, 'GV', NULL, 4000, 17, 'KAB', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL);
INSERT INTO delivery_part (year, did, dpnr, sortid, attrid, cultid, weight, kmw, qualid, hkid, kgnr, net_weight, manual_weighing, spl_check, scale_id, weighing_id, weighing_reason) VALUES
(2020, 1, 1, 'GV', NULL, NULL, 3219, 15.0, 'QUW', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 2, 1, 'GV', 'K', NULL, 2987, 17.5, 'KAB', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 2, 2, 'GV', 'K', NULL, 1873, 17.7, 'KAB', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 3, 1, 'GV', NULL, NULL, 2561, 15.4, 'QUW', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 3, 2, 'GV', 'K', NULL, 3129, 17.6, 'KAB', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 3, 3, 'GV', NULL, NULL, 1280, 16.1, 'QUW', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 4, 1, 'GV', NULL, NULL, 4002, 16.7, 'QUW', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 4, 2, 'GV', NULL, NULL, 481, 15.3, 'QUW', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 5, 1, 'WR', NULL, NULL, 3192, 17.0, 'KAB', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 5, 2, 'WR', NULL, NULL, 2190, 17.1, 'KAB', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 6, 1, 'GV', NULL, 'B', 1732, 15.2, 'QUW', 'WLNO', 06109, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 7, 1, 'GV', NULL, 'B', 3198, 16.3, 'QUW', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 7, 2, 'GV', NULL, 'B', 2134, 15.4, 'QUW', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 8, 1, 'GV', NULL, 'B', 2901, 16.0, 'QUW', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 8, 2, 'GV', NULL, 'B', 3321, 17.3, 'KAB', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 9, 1, 'WR', NULL, 'B', 3998, 17.2, 'KAB', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 10, 1, 'ZW', NULL, NULL, 1212, 15.0, 'QUW', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 10, 2, 'ZW', NULL, NULL, 2471, 15.2, 'QUW', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 10, 3, 'ZW', NULL, NULL, 842, 15.7, 'QUW', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 11, 1, 'ZW', NULL, NULL, 3578, 17.0, 'KAB', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 11, 2, 'ZW', NULL, NULL, 3862, 17.2, 'KAB', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 12, 1, 'BP', NULL, NULL, 2410, 18.0, 'KAB', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL),
(2020, 12, 2, 'BP', NULL, NULL, 2313, 18.1, 'KAB', 'WLNO', 15224, TRUE, FALSE, FALSE, NULL, NULL, NULL);