feat(configmanager): add LdapFormViewModel
Implement LdapFormViewModel for editing LDAP configuration section with properties for ServerUrlsText, GroupDn, SearchBase, ConnectionTimeoutSeconds, UseFakeAuth, and AdminBypassUsersText. Array properties use newline-separated text with StringSplitOptions.RemoveEmptyEntries | TrimEntries for splitting.
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
using JdeScoping.ConfigManager.Models;
|
||||
using JdeScoping.ConfigManager.ViewModels.Forms;
|
||||
|
||||
namespace JdeScoping.ConfigManager.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!));
|
||||
}
|
||||
}
|
||||
+118
@@ -0,0 +1,118 @@
|
||||
using JdeScoping.ConfigManager.Models;
|
||||
using JdeScoping.ConfigManager.ViewModels.Forms;
|
||||
|
||||
namespace JdeScoping.ConfigManager.Tests.ViewModels.Forms;
|
||||
|
||||
public class ExcelExportFormViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_InitializesFromModel()
|
||||
{
|
||||
// Arrange
|
||||
var model = new ExcelExportSection
|
||||
{
|
||||
CriteriaSheetPassword = "criteriaPass123",
|
||||
DataSheetPassword = "dataPass456",
|
||||
MaxRowsPerSheet = 500000,
|
||||
DefaultDateFormat = "MM/dd/yyyy",
|
||||
DebugWriteToFile = true,
|
||||
DebugOutputDirectory = "/tmp/debug",
|
||||
TimezoneId = "America/New_York",
|
||||
TimezoneAbbreviation = "ET"
|
||||
};
|
||||
|
||||
// Act
|
||||
var sut = new ExcelExportFormViewModel(model, () => { });
|
||||
|
||||
// Assert
|
||||
sut.CriteriaSheetPassword.ShouldBe("criteriaPass123");
|
||||
sut.DataSheetPassword.ShouldBe("dataPass456");
|
||||
sut.MaxRowsPerSheet.ShouldBe(500000);
|
||||
sut.DefaultDateFormat.ShouldBe("MM/dd/yyyy");
|
||||
sut.DebugWriteToFile.ShouldBeTrue();
|
||||
sut.DebugOutputDirectory.ShouldBe("/tmp/debug");
|
||||
sut.TimezoneId.ShouldBe("America/New_York");
|
||||
sut.TimezoneAbbreviation.ShouldBe("ET");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PropertyChange_UpdatesModel()
|
||||
{
|
||||
// Arrange
|
||||
var model = new ExcelExportSection { MaxRowsPerSheet = 1000000 };
|
||||
var sut = new ExcelExportFormViewModel(model, () => { });
|
||||
|
||||
// Act
|
||||
sut.MaxRowsPerSheet = 750000;
|
||||
|
||||
// Assert
|
||||
model.MaxRowsPerSheet.ShouldBe(750000);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PropertyChange_InvokesOnChanged()
|
||||
{
|
||||
// Arrange
|
||||
var model = new ExcelExportSection();
|
||||
var changedInvoked = false;
|
||||
var sut = new ExcelExportFormViewModel(model, () => changedInvoked = true);
|
||||
|
||||
// Act
|
||||
sut.TimezoneId = "Europe/London";
|
||||
|
||||
// Assert
|
||||
changedInvoked.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void PropertyChange_RaisesPropertyChanged()
|
||||
{
|
||||
// Arrange
|
||||
var model = new ExcelExportSection();
|
||||
var sut = new ExcelExportFormViewModel(model, () => { });
|
||||
var propertyChangedRaised = false;
|
||||
sut.PropertyChanged += (s, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(ExcelExportFormViewModel.DefaultDateFormat))
|
||||
propertyChangedRaised = true;
|
||||
};
|
||||
|
||||
// Act
|
||||
sut.DefaultDateFormat = "dd-MMM-yyyy";
|
||||
|
||||
// Assert
|
||||
propertyChangedRaised.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void SameValueAssignment_DoesNotInvokeOnChanged()
|
||||
{
|
||||
// Arrange
|
||||
var model = new ExcelExportSection { DebugWriteToFile = true };
|
||||
var changedInvoked = false;
|
||||
var sut = new ExcelExportFormViewModel(model, () => changedInvoked = true);
|
||||
|
||||
// Act
|
||||
sut.DebugWriteToFile = true; // Same value
|
||||
|
||||
// Assert
|
||||
changedInvoked.ShouldBeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_ThrowsOnNullModel()
|
||||
{
|
||||
// Act & Assert
|
||||
Should.Throw<ArgumentNullException>(() => new ExcelExportFormViewModel(null!, () => { }));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_ThrowsOnNullOnChanged()
|
||||
{
|
||||
// Arrange
|
||||
var model = new ExcelExportSection();
|
||||
|
||||
// Act & Assert
|
||||
Should.Throw<ArgumentNullException>(() => new ExcelExportFormViewModel(model, null!));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using JdeScoping.ConfigManager.Models;
|
||||
using JdeScoping.ConfigManager.ViewModels.Forms;
|
||||
|
||||
namespace JdeScoping.ConfigManager.Tests.ViewModels.Forms;
|
||||
|
||||
public class LdapFormViewModelTests
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_InitializesFromModel()
|
||||
{
|
||||
// Arrange
|
||||
var model = new LdapSection
|
||||
{
|
||||
ServerUrls = ["ldap://server1.local", "ldap://server2.local"],
|
||||
GroupDn = "CN=Admins,DC=corp",
|
||||
SearchBase = "DC=corp,DC=local",
|
||||
UseFakeAuth = true
|
||||
};
|
||||
|
||||
// Act
|
||||
var sut = new LdapFormViewModel(model, () => { });
|
||||
|
||||
// Assert
|
||||
sut.ServerUrlsText.ShouldBe("ldap://server1.local\nldap://server2.local");
|
||||
sut.GroupDn.ShouldBe("CN=Admins,DC=corp");
|
||||
sut.SearchBase.ShouldBe("DC=corp,DC=local");
|
||||
sut.UseFakeAuth.ShouldBeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServerUrlsText_SplitsIntoArray()
|
||||
{
|
||||
// Arrange
|
||||
var model = new LdapSection();
|
||||
var sut = new LdapFormViewModel(model, () => { });
|
||||
|
||||
// Act
|
||||
sut.ServerUrlsText = "ldap://a.local\nldap://b.local\nldap://c.local";
|
||||
|
||||
// Assert
|
||||
model.ServerUrls.Length.ShouldBe(3);
|
||||
model.ServerUrls[0].ShouldBe("ldap://a.local");
|
||||
model.ServerUrls[2].ShouldBe("ldap://c.local");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AdminBypassUsersText_SplitsIntoArray()
|
||||
{
|
||||
// Arrange
|
||||
var model = new LdapSection();
|
||||
var sut = new LdapFormViewModel(model, () => { });
|
||||
|
||||
// Act
|
||||
sut.AdminBypassUsersText = "admin\nservice_account";
|
||||
|
||||
// Assert
|
||||
model.AdminBypassUsers.Length.ShouldBe(2);
|
||||
model.AdminBypassUsers[0].ShouldBe("admin");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user