61 lines
2.4 KiB
C#
61 lines
2.4 KiB
C#
using LehrerApp.Desktop.ViewModels.ClassTeacher;
|
|
using LehrerApp.Core.Models;
|
|
using Xunit;
|
|
|
|
namespace LehrerApp.Desktop.Tests;
|
|
|
|
public sealed class UntisNameMatchingTests
|
|
{
|
|
[Theory]
|
|
[InlineData("Ben Schmidt", "Schmidt Ben")]
|
|
[InlineData("Ada Müller", "MÜLLER ADA")]
|
|
[InlineData("Max Mustermann", "mustermann max")]
|
|
[InlineData("Gerste, Amelia", "Gerste Amelia")]
|
|
[InlineData("Müller-Ada", "Ada Müller")]
|
|
public void NamesMatch_IstReihenfolgeUndGrossKleinschreibungUnabhaengig(string a, string b) =>
|
|
Assert.True(UntisNameMatching.NamesMatch(a, b));
|
|
|
|
[Theory]
|
|
[InlineData("Ben Schmidt", "Ben Müller")]
|
|
[InlineData(null, "Ben Schmidt")]
|
|
[InlineData("Ben Schmidt", "")]
|
|
public void NamesMatch_LehntUnterschiedlicheOderFehlendeNamenAb(string? a, string b) =>
|
|
Assert.False(UntisNameMatching.NamesMatch(a, b));
|
|
|
|
// Regression: Student.FullName liefert "Nachname, Vorname" (mit Komma), während WebUntis
|
|
// denselben Namen je nach Bericht ohne Komma und in wechselnder Reihenfolge liefert.
|
|
[Fact]
|
|
public void NamesMatch_KommaGetrennterAnzeigename_PasstZumUntisNamenOhneKomma()
|
|
{
|
|
Assert.True(UntisNameMatching.NamesMatch("Gerste, Amelia", "Gerste Amelia"));
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildClassNameIndex_VerwendetDieselbeInstanzWieDieAuswahlliste()
|
|
{
|
|
var candidate = new Student { FirstName = "Amelia", LastName = "Gerste" };
|
|
var repositoryCopy = new Student
|
|
{
|
|
Id = candidate.Id, FirstName = candidate.FirstName, LastName = candidate.LastName,
|
|
};
|
|
|
|
var index = UntisNameMatching.BuildClassNameIndex([candidate], [repositoryCopy]);
|
|
|
|
Assert.Same(candidate, index[UntisNameMatching.NameKey("Gerste Amelia")]);
|
|
}
|
|
|
|
[Fact]
|
|
public void BuildClassNameIndex_GleicheNamenInVerschiedenenKlassenBleibenEindeutig()
|
|
{
|
|
var classStudent = new Student { FirstName = "Amelia", LastName = "Gerste" };
|
|
var otherStudent = new Student { FirstName = "Amelia", LastName = "Gerste" };
|
|
var candidates = new[] { classStudent, otherStudent };
|
|
|
|
Assert.Empty(UntisNameMatching.BuildNameIndex(candidates));
|
|
var index = UntisNameMatching.BuildClassNameIndex(candidates,
|
|
[new Student { Id = classStudent.Id, FirstName = "Amelia", LastName = "Gerste" }]);
|
|
|
|
Assert.Same(classStudent, index[UntisNameMatching.NameKey("Gerste Amelia")]);
|
|
}
|
|
}
|