1fc7792cd1
Rename ConfigManager to ConfigManager.Ui to match the Core/CLI/UI project structure, and split the monolithic test project into Core.Tests, Cli.Tests, and Ui.Tests to align with the source project organization.
92 lines
2.5 KiB
C#
92 lines
2.5 KiB
C#
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<ArgumentNullException>(() => new AuthFormViewModel(null!, () => { }));
|
|
}
|
|
|
|
[Fact]
|
|
public void Constructor_ThrowsOnNullCallback()
|
|
{
|
|
// Act & Assert
|
|
Should.Throw<ArgumentNullException>(() => new AuthFormViewModel(new AuthSection(), null!));
|
|
}
|
|
}
|