db663cc82d
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.
183 lines
5.1 KiB
C#
183 lines
5.1 KiB
C#
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("-");
|
|
}
|
|
}
|