feat: add student master data import
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using LehrerApp.Core.Importing;
|
||||
using LehrerApp.Core.Models;
|
||||
using LehrerApp.Core.Services;
|
||||
using LehrerApp.Desktop.ViewModels.Students;
|
||||
using Xunit;
|
||||
|
||||
namespace LehrerApp.Desktop.Tests;
|
||||
|
||||
public sealed class StudentImportDialogViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task Vorschau_ZeigtZusammenfassungUndImportiertNeueSchueler()
|
||||
{
|
||||
var stored = new List<Student>();
|
||||
var service = Service(stored,
|
||||
[
|
||||
new ImportedStudent
|
||||
{
|
||||
FirstName = "Max",
|
||||
LastName = "Beispiel",
|
||||
Gender = Gender.M,
|
||||
},
|
||||
]);
|
||||
var preview = await service.AnalyzeAsync(File());
|
||||
var vm = new StudentImportDialogViewModel(service, preview, "students.csv");
|
||||
|
||||
Assert.Contains("1 erkannt", vm.Summary);
|
||||
Assert.Equal(1, vm.NewStudents);
|
||||
Assert.True(vm.IsReadyWithoutConflicts);
|
||||
|
||||
Assert.True(await vm.TryApplyAsync());
|
||||
Assert.Equal(1, vm.Result?.CreatedStudents);
|
||||
Assert.Single(stored);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Konflikt_VerwendetDieSichereStandardoptionUeberspringen()
|
||||
{
|
||||
var stored = new List<Student>
|
||||
{
|
||||
new() { FirstName = "Max", LastName = "Beispiel" },
|
||||
};
|
||||
var service = Service(stored,
|
||||
[
|
||||
new ImportedStudent { FirstName = "Max", LastName = "Beispiel" },
|
||||
]);
|
||||
var preview = await service.AnalyzeAsync(File());
|
||||
var vm = new StudentImportDialogViewModel(service, preview, "students.csv");
|
||||
|
||||
var conflict = Assert.Single(vm.Conflicts);
|
||||
Assert.Equal("skip", conflict.SelectedOption.Id);
|
||||
Assert.Equal("skip", Assert.Single(vm.BuildDecisions()).SelectedOptionId);
|
||||
|
||||
Assert.True(await vm.TryApplyAsync());
|
||||
Assert.Equal(1, vm.Result?.SkippedStudents);
|
||||
Assert.Single(stored);
|
||||
}
|
||||
|
||||
private static StudentImportService Service(
|
||||
List<Student> stored,
|
||||
IReadOnlyList<ImportedStudent> imported) => new(
|
||||
[new FakeImportHandler(imported)],
|
||||
new FakeStudents(stored),
|
||||
new FakeGroups([]),
|
||||
new FakeMemberships([]),
|
||||
new SchoolYearService());
|
||||
|
||||
private static ImportFile File() => new("students.csv", "test"u8.ToArray());
|
||||
|
||||
private sealed class FakeImportHandler(IReadOnlyList<ImportedStudent> imported)
|
||||
: IImportHandler<ImportedStudent>
|
||||
{
|
||||
public ImportFormatId FormatId { get; } = new("test.students");
|
||||
public string DisplayName => "Testformat";
|
||||
public IReadOnlyCollection<string> SupportedExtensions { get; } = [".csv"];
|
||||
|
||||
public ValueTask<ImportDetection> DetectAsync(
|
||||
ImportFile file,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
ValueTask.FromResult(ImportDetection.Match(100));
|
||||
|
||||
public ValueTask<ImportParseResult<ImportedStudent>> ParseAsync(
|
||||
ImportFile file,
|
||||
CancellationToken cancellationToken = default) =>
|
||||
ValueTask.FromResult(new ImportParseResult<ImportedStudent>(imported));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user