Add invoice model and validation rules

This commit is contained in:
admin committed 2026-09-07 12:04:28 +02:00
commit 7128a93461
8 files changed
+588

No files matched your search

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\ImportAssist.Core\ImportAssist.Core.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+24
View File
@@ -0,0 +1,24 @@
using ImportAssist.Core;
InvoiceRow[] rows =
[
new("INV-001", "C-100", "125.50", "EUR"),
new("INV-002", "", "89.00", "EUR"),
new("INV-003", "C-300", "abc", "EUR"),
new("INV-004", "C-400", "-10.00", "EUR"),
new("", "", "0", "EUR")
];
foreach (var row in rows)
{
var errors = InvoiceValidator.Validate(row);
var invoiceId = string.IsNullOrWhiteSpace(row.InvoiceId)
? "(ohne Rechnungsnummer)"
: row.InvoiceId;
Console.WriteLine(
errors.Count == 0
? $"{invoiceId}: Gültig"
: $"{invoiceId}: {string.Join("; ", errors)}");
}
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>
+7
View File
@@ -0,0 +1,7 @@
namespace ImportAssist.Core;
public sealed record InvoiceRow(
string InvoiceId,
string CustomerId,
string Amount,
string Currency);
+40
View File
@@ -0,0 +1,40 @@
using System.Globalization;
namespace ImportAssist.Core;
public static class InvoiceValidator
{
public static IReadOnlyList<string> Validate(InvoiceRow row)
{
var errors = new List<string>();
if (string.IsNullOrWhiteSpace(row.InvoiceId))
{
errors.Add("Rechnungsnummer fehlt.");
}
if (string.IsNullOrWhiteSpace(row.CustomerId))
{
errors.Add("Kundennummer fehlt.");
}
var allowedStyles =
NumberStyles.AllowLeadingSign |
NumberStyles.AllowDecimalPoint;
if (!decimal.TryParse(
row.Amount,
allowedStyles,
CultureInfo.InvariantCulture,
out var amount))
{
errors.Add("Betrag ist keine gültige Zahl.");
}
else if (amount <= 0)
{
errors.Add("Betrag muss größer als null sein.");
}
return errors;
}
}