Add regression tests for invoice validation and CSV parsing
This commit is contained in:
1 parent
b9104e0632
commit
b3be368594
4 files changed
+146
No files matched your search
@@ -0,0 +1,55 @@
|
||||
using ImportAssist.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace ImportAssist.Core.Tests;
|
||||
|
||||
public sealed class InvoiceCsvParserTests
|
||||
{
|
||||
private const string Header =
|
||||
"InvoiceId;CustomerId;Amount;Currency";
|
||||
|
||||
[Fact]
|
||||
public void Parse_PreservesEmptyFieldsAndRawAmount()
|
||||
{
|
||||
var csv = $"{Header}\nINV-001;;abc;EUR";
|
||||
|
||||
var rows = InvoiceCsvParser.Parse(csv);
|
||||
|
||||
var row = Assert.Single(rows);
|
||||
|
||||
Assert.Equal(
|
||||
new InvoiceRow("INV-001", "", "abc", "EUR"),
|
||||
row);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("")]
|
||||
[InlineData("InvoiceId;Amount")]
|
||||
public void Parse_RejectsMissingOrIncorrectHeader(string csv)
|
||||
{
|
||||
var exception = Assert.Throws<FormatException>(
|
||||
() => InvoiceCsvParser.Parse(csv));
|
||||
|
||||
Assert.Equal(
|
||||
"Die Datei ist leer oder die Kopfzeile stimmt nicht.",
|
||||
exception.Message);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("INV-002;C-200;89.00")]
|
||||
[InlineData("INV-002;C-200;89.00;EUR;extra")]
|
||||
[InlineData("INV-002;\"C-200\";89.00;EUR")]
|
||||
public void Parse_RejectsMalformedRowWithCorrectLineNumber(
|
||||
string malformedRow)
|
||||
{
|
||||
var csv =
|
||||
$"{Header}\nINV-001;C-100;125.50;EUR\n{malformedRow}";
|
||||
|
||||
var exception = Assert.Throws<FormatException>(
|
||||
() => InvoiceCsvParser.Parse(csv));
|
||||
|
||||
Assert.Equal(
|
||||
"Zeile 3: Erwartet werden vier Spalten ohne Anführungszeichen.",
|
||||
exception.Message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user