using JdeScoping.ConfigManager.Core.Models; using JdeScoping.ConfigManager.Ui.ViewModels.Forms; namespace JdeScoping.ConfigManager.Ui.Tests.ViewModels.Forms; public class AuthFormViewModelTests { [Fact] public void Constructor_InitializesFromModel() { // Arrange var model = new AuthSection { CookieName = ".TestApp.Auth", CookieExpirationMinutes = 120 }; // Act var sut = new AuthFormViewModel(model, () => { }); // Assert sut.CookieName.ShouldBe(".TestApp.Auth"); sut.CookieExpirationMinutes.ShouldBe(120); } [Fact] public void PropertyChange_UpdatesModelAndInvokesOnChanged() { // Arrange var model = new AuthSection(); var changedInvoked = false; var sut = new AuthFormViewModel(model, () => changedInvoked = true); // Act sut.CookieName = ".Custom.Cookie"; // Assert model.CookieName.ShouldBe(".Custom.Cookie"); changedInvoked.ShouldBeTrue(); } [Fact] public void CookieExpirationMinutes_UpdatesModelAndInvokesOnChanged() { // Arrange var model = new AuthSection { CookieExpirationMinutes = 480 }; var changedInvoked = false; var sut = new AuthFormViewModel(model, () => changedInvoked = true); // Act sut.CookieExpirationMinutes = 60; // Assert model.CookieExpirationMinutes.ShouldBe(60); changedInvoked.ShouldBeTrue(); } [Fact] public void PropertyChange_RaisesPropertyChanged() { // Arrange var model = new AuthSection(); var sut = new AuthFormViewModel(model, () => { }); var propertyChangedRaised = false; sut.PropertyChanged += (s, e) => { if (e.PropertyName == nameof(AuthFormViewModel.CookieName)) propertyChangedRaised = true; }; // Act sut.CookieName = ".New.Cookie"; // Assert propertyChangedRaised.ShouldBeTrue(); } [Fact] public void Constructor_ThrowsOnNullModel() { // Act & Assert Should.Throw(() => new AuthFormViewModel(null!, () => { })); } [Fact] public void Constructor_ThrowsOnNullCallback() { // Act & Assert Should.Throw(() => new AuthFormViewModel(new AuthSection(), null!)); } }