feat(configmanager): add ConnectionStrings editor with test connection support

Adds a new ConnectionStrings section to ConfigManager allowing users to manage
database connection strings with provider selection, connection testing, and
visual feedback for connection state.
This commit is contained in:
Joseph Doherty
2026-01-22 11:12:08 -05:00
parent 9bf0c29add
commit db663cc82d
20 changed files with 2508 additions and 2 deletions
@@ -0,0 +1,182 @@
using JdeScoping.ConfigManager.Models;
using JdeScoping.ConfigManager.ViewModels.Forms;
namespace JdeScoping.ConfigManager.Tests.ViewModels.Forms;
public class ConnectionStringEntryViewModelTests
{
[Fact]
public void Constructor_InitializesFromModel()
{
// Arrange
var model = new ConnectionStringEntry
{
Name = "TestConnection",
Provider = ConnectionProvider.SqlServer,
Server = "localhost",
Database = "TestDb",
UserId = "testuser",
Password = "testpass",
Encrypt = "Strict",
TrustServerCertificate = true,
ConnectionTimeout = 45,
ApplicationName = "TestApp"
};
// Act
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Assert
sut.Name.ShouldBe("TestConnection");
sut.Provider.ShouldBe(ConnectionProvider.SqlServer);
sut.Server.ShouldBe("localhost");
sut.Database.ShouldBe("TestDb");
sut.UserId.ShouldBe("testuser");
sut.Password.ShouldBe("testpass");
sut.Encrypt.ShouldBe("Strict");
sut.TrustServerCertificate.ShouldBeTrue();
sut.ConnectionTimeout.ShouldBe(45);
sut.ApplicationName.ShouldBe("TestApp");
}
[Fact]
public void Constructor_ThrowsOnNullModel()
{
// Act & Assert
Should.Throw<ArgumentNullException>(() => new ConnectionStringEntryViewModel(null!, () => { }));
}
[Fact]
public void Constructor_ThrowsOnNullOnChanged()
{
// Arrange
var model = new ConnectionStringEntry();
// Act & Assert
Should.Throw<ArgumentNullException>(() => new ConnectionStringEntryViewModel(model, null!));
}
[Fact]
public void PropertyChange_UpdatesModel()
{
// Arrange
var model = new ConnectionStringEntry();
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Act
sut.Name = "UpdatedName";
sut.Server = "newserver";
sut.Database = "newdb";
// Assert
model.Name.ShouldBe("UpdatedName");
model.Server.ShouldBe("newserver");
model.Database.ShouldBe("newdb");
}
[Fact]
public void PropertyChange_InvokesOnChanged()
{
// Arrange
var model = new ConnectionStringEntry();
var changedInvoked = false;
var sut = new ConnectionStringEntryViewModel(model, () => changedInvoked = true);
// Act
sut.Name = "NewName";
// Assert
changedInvoked.ShouldBeTrue();
}
[Fact]
public void TogglePasswordVisibility_TogglesIsPasswordVisible()
{
// Arrange
var model = new ConnectionStringEntry();
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Assert initial state
sut.IsPasswordVisible.ShouldBeFalse();
// Act - first toggle
sut.TogglePasswordVisibilityCommand.Execute(null);
// Assert
sut.IsPasswordVisible.ShouldBeTrue();
// Act - second toggle
sut.TogglePasswordVisibilityCommand.Execute(null);
// Assert
sut.IsPasswordVisible.ShouldBeFalse();
}
[Fact]
public void ProviderDisplay_ReturnsCorrectString()
{
// Arrange
var model = new ConnectionStringEntry { Provider = ConnectionProvider.SqlServer };
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Assert
sut.ProviderDisplay.ShouldBe("SqlServer");
// Act
sut.Provider = ConnectionProvider.Oracle;
// Assert
sut.ProviderDisplay.ShouldBe("Oracle");
// Act
sut.Provider = ConnectionProvider.Generic;
// Assert
sut.ProviderDisplay.ShouldBe("Generic");
}
[Fact]
public void ServerDisplay_ReturnsServerForSqlServer()
{
// Arrange
var model = new ConnectionStringEntry
{
Provider = ConnectionProvider.SqlServer,
Server = "sql-server-host"
};
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Assert
sut.ServerDisplay.ShouldBe("sql-server-host");
}
[Fact]
public void ServerDisplay_ReturnsHostForOracle()
{
// Arrange
var model = new ConnectionStringEntry
{
Provider = ConnectionProvider.Oracle,
Host = "oracle-host"
};
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Assert
sut.ServerDisplay.ShouldBe("oracle-host");
}
[Fact]
public void ServerDisplay_ReturnsDashForGeneric()
{
// Arrange
var model = new ConnectionStringEntry
{
Provider = ConnectionProvider.Generic,
RawConnectionString = "some connection string"
};
var sut = new ConnectionStringEntryViewModel(model, () => { });
// Assert
sut.ServerDisplay.ShouldBe("-");
}
}