Files
LehrerApp/LehrerApp.Desktop.Tests/AppLockViewModelTests.cs
T
adminandClaude Sonnet 5 48d07a2b99 Datensicherheit: Backup, Verschlüsselung, App-Sperre (Kapitel 13.3)
Automatisches rollierendes Backup der Datenbank beim Start mit
Wiederherstellung über die Einstellungen, versionierte Schema-Migration,
optionale Passwort-Verschlüsselung der LiteDB-Datei und eine App-Sperre
nach Inaktivität mit eigenem Passwort.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-13 13:07:36 +02:00

47 lines
1.5 KiB
C#

using LehrerApp.Core.Services;
using LehrerApp.Desktop.ViewModels;
using Xunit;
namespace LehrerApp.Desktop.Tests;
public sealed class AppLockViewModelTests
{
[Fact]
public void Unlock_KorrektesPasswort_HebtDieSperreAuf()
{
using var temp = new TempAppData();
var appLock = new AppLockService(temp.Path);
appLock.SetPassword("geheim123");
var vm = new AppLockViewModel(appLock) { IsLocked = true, PasswordAttempt = "geheim123" };
vm.UnlockCommand.Execute(null);
Assert.False(vm.IsLocked);
Assert.Equal("", vm.UnlockError);
}
[Fact]
public void Unlock_FalschesPasswort_BleibtGesperrtUndZeigtFehler()
{
using var temp = new TempAppData();
var appLock = new AppLockService(temp.Path);
appLock.SetPassword("geheim123");
var vm = new AppLockViewModel(appLock) { IsLocked = true, PasswordAttempt = "falsch" };
vm.UnlockCommand.Execute(null);
Assert.True(vm.IsLocked);
Assert.NotEqual("", vm.UnlockError);
Assert.Equal("", vm.PasswordAttempt);
}
private sealed class TempAppData : IDisposable
{
public string Path { get; } = System.IO.Path.Combine(
System.IO.Path.GetTempPath(), $"lehrerapp-applockvm-tests-{Guid.NewGuid():N}");
public TempAppData() => Directory.CreateDirectory(Path);
public void Dispose() { if (Directory.Exists(Path)) Directory.Delete(Path, recursive: true); }
}
}