feat: Teilnehmerlisten in Lerngruppen importieren

This commit is contained in:
2026-08-18 00:44:07 +02:00
parent cdac335ad1
commit 99efa3a0fe
11 changed files with 489 additions and 79 deletions
@@ -0,0 +1,59 @@
using System.Text;
using LehrerApp.Core.Importing;
using LehrerApp.Core.Models;
using Xunit;
namespace LehrerApp.Tests;
public sealed class LessonStudentListCsvImportHandlerTests
{
[Fact]
public async Task Parse_UebernimmtTeilnehmerUndOptionaleKontaktdaten()
{
var handler = new LessonStudentListCsvImportHandler();
var result = await handler.ParseAsync(File(LessonList()));
Assert.True(result.IsValid);
var student = Assert.Single(result.Items);
Assert.Equal("Max", student.FirstName);
Assert.Equal("Beispiel", student.LastName);
Assert.Equal("10c", student.GroupName);
Assert.Equal(Gender.M, student.Gender);
Assert.Equal("max@example.invalid", student.Contact?.Email);
Assert.Equal("0151 123", student.Contact?.MobilePhone);
Assert.Equal("0123 456", student.Contact?.Phone);
Assert.Equal("Zeile 2", student.SourceReference);
}
[Fact]
public async Task Detect_UnterscheidetTeilnehmerlisteVonStammdatenliste()
{
var handler = new LessonStudentListCsvImportHandler();
var detection = await handler.DetectAsync(File(LessonList()));
Assert.True(detection.IsMatch);
Assert.Equal(100, detection.Confidence);
}
[Fact]
public async Task MarksExport_WirdErkanntUndErklaertFehlendeTeilnehmerdaten()
{
var handler = new MarksPerLessonCsvImportHandler();
const string header = "Datum\tName\tKlasse\tFach\tPrüfungsart\tNote\tBemerkung\tBenutzer\tSchlüssel (extern)\tGesamtnote\n";
var detection = await handler.DetectAsync(File(header));
var result = await handler.ParseAsync(File(header));
Assert.True(detection.IsMatch);
Assert.False(result.IsValid);
Assert.Empty(result.Items);
Assert.Contains(result.Messages, message => message.Code == "marks-per-lesson.no-participants");
}
private static ImportFile File(string text) => new("export.csv", Encoding.UTF8.GetBytes(text));
private static string LessonList() => string.Join('\n',
"Langname\tVorname\tKlasse\tGeschlecht\tEintrittsdatum\tAustrittsdatum\tE-Mail Adresse\tMobiltelefon\tTelefonnummer",
"Beispiel\tMax\t10c\tm\t01.08.2025\t\tmax@example.invalid\t0151 123\t0123 456") + "\n";
}