Tests: Add tests for documents
This commit is contained in:
31
Tests/DocumentTests/DeliveryNoteTest.cs
Normal file
31
Tests/DocumentTests/DeliveryNoteTest.cs
Normal file
@ -0,0 +1,31 @@
|
||||
using Elwig.Documents;
|
||||
using Elwig.Helpers;
|
||||
|
||||
namespace Tests.DocumentTests {
|
||||
[TestFixture]
|
||||
public class DeliveryNoteTest {
|
||||
|
||||
private readonly AppDbContext Context = new();
|
||||
|
||||
[Test]
|
||||
public async Task Test_01_OneDeliveryPart() {
|
||||
var d = await Context.Deliveries.FindAsync(2020, 1);
|
||||
using var doc = new DeliveryNote(d!, Context);
|
||||
var text = await Utils.GeneratePdfText(doc);
|
||||
Console.Write(text);
|
||||
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. 20201001X001"));
|
||||
// TODO
|
||||
Assert.That(text, Contains.Substring("Ich bin der Text, der auf einem Traubenübernahmeschein steht!"));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
37
Tests/DocumentTests/Setup.cs
Normal file
37
Tests/DocumentTests/Setup.cs
Normal file
@ -0,0 +1,37 @@
|
||||
using Elwig.Helpers;
|
||||
using System.Reflection;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Elwig.Helpers.Printing;
|
||||
|
||||
namespace Tests.DocumentTests {
|
||||
[SetUpFixture]
|
||||
public class Setup {
|
||||
|
||||
private SqliteConnection? Connection;
|
||||
|
||||
[OneTimeSetUp]
|
||||
public async Task SetupDatabase() {
|
||||
Connection = await AppDbContext.ConnectAsync();
|
||||
await AppDbContext.ExecuteEmbeddedScript(Connection, Assembly.GetExecutingAssembly(), "Tests.Resources.Sql.DocumentInsert.sql");
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public async Task TeardownDatabase() {
|
||||
if (Connection == null) return;
|
||||
await AppDbContext.ExecuteEmbeddedScript(Connection, Assembly.GetExecutingAssembly(), "Tests.Resources.Sql.DocumentDelete.sql");
|
||||
await Connection.DisposeAsync();
|
||||
Connection = null;
|
||||
}
|
||||
|
||||
[OneTimeSetUp]
|
||||
public async Task SetupPrinting() {
|
||||
await Html.Init();
|
||||
await Pdf.Init();
|
||||
}
|
||||
|
||||
[OneTimeTearDown]
|
||||
public void TeardownPrinting() {
|
||||
// no teardown needed yet
|
||||
}
|
||||
}
|
||||
}
|
20
Tests/DocumentTests/Utils.cs
Normal file
20
Tests/DocumentTests/Utils.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using Elwig.Documents;
|
||||
using NReco.PdfRenderer;
|
||||
|
||||
namespace Tests.DocumentTests {
|
||||
public static class Utils {
|
||||
|
||||
private static readonly string FileName = Path.Combine(Path.GetTempPath(), "test_document.pdf");
|
||||
|
||||
public static async Task<string> GeneratePdfText(Document doc) {
|
||||
await doc.Generate();
|
||||
try {
|
||||
doc.SaveTo(FileName);
|
||||
var conv = new PdfToTextConverter { CustomArgs = "-raw " };
|
||||
return conv.GenerateText(FileName);
|
||||
} finally {
|
||||
File.Delete(FileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
5
Tests/Resources/Sql/DocumentDelete.sql
Normal file
5
Tests/Resources/Sql/DocumentDelete.sql
Normal file
@ -0,0 +1,5 @@
|
||||
-- deletes for DocumentTests
|
||||
|
||||
DELETE FROM delivery;
|
||||
DELETE FROM season;
|
||||
DELETE FROM wine_attribute;
|
20
Tests/Resources/Sql/DocumentInsert.sql
Normal file
20
Tests/Resources/Sql/DocumentInsert.sql
Normal file
@ -0,0 +1,20 @@
|
||||
-- inserts for DocumentTests
|
||||
|
||||
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
|
||||
(2020, 'EUR', 1000, 2000, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
INSERT INTO modifier (year, modid, ordering, name, abs, rel, standard, quick_select) VALUES
|
||||
(2020, 'S', 0, 'Geschädigte Trauben', NULL, -0.1, FALSE, FALSE),
|
||||
(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);
|
||||
|
||||
INSERT INTO delivery_part (year, did, dpnr, sortid, attrid, weight, kmw, qualid, hkid, kgnr, gerebelt, 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);
|
@ -4,9 +4,9 @@
|
||||
<TargetFramework>net8.0-windows</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<PreserveCompilationContext>true</PreserveCompilationContext>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -19,10 +19,11 @@
|
||||
</Target>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
|
||||
<PackageReference Include="NReco.PdfRenderer" Version="1.5.3" />
|
||||
<PackageReference Include="NUnit" Version="4.0.1" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
|
||||
<PackageReference Include="NUnit.Analyzers" Version="3.10.0">
|
||||
<PackageReference Include="NUnit.Analyzers" Version="4.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
|
Reference in New Issue
Block a user