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.
123 lines
3.7 KiB
C#
123 lines
3.7 KiB
C#
using JdeScoping.ConfigManager.Models;
|
|
|
|
namespace JdeScoping.ConfigManager.Tests.Models;
|
|
|
|
public class ConnectionStringEntryTests
|
|
{
|
|
[Fact]
|
|
public void GenerateConnectionString_SqlServer_ProducesCorrectFormat()
|
|
{
|
|
// Arrange
|
|
var entry = new ConnectionStringEntry
|
|
{
|
|
Provider = ConnectionProvider.SqlServer,
|
|
Server = "localhost\\SQLEXPRESS",
|
|
Database = "TestDb",
|
|
UserId = "sa",
|
|
Password = "secret123",
|
|
Encrypt = "True",
|
|
TrustServerCertificate = true,
|
|
ConnectionTimeout = 60,
|
|
ApplicationName = "TestApp"
|
|
};
|
|
|
|
// Act
|
|
var result = entry.GenerateConnectionString();
|
|
|
|
// Assert
|
|
result.ShouldContain("Server=localhost\\SQLEXPRESS");
|
|
result.ShouldContain("Database=TestDb");
|
|
result.ShouldContain("User Id=sa");
|
|
result.ShouldContain("Password=secret123");
|
|
result.ShouldContain("Encrypt=True");
|
|
result.ShouldContain("TrustServerCertificate=True");
|
|
result.ShouldContain("Connection Timeout=60");
|
|
result.ShouldContain("Application Name=TestApp");
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateConnectionString_SqlServer_OmitsDefaultTimeout()
|
|
{
|
|
// Arrange
|
|
var entry = new ConnectionStringEntry
|
|
{
|
|
Provider = ConnectionProvider.SqlServer,
|
|
Server = "localhost",
|
|
Database = "TestDb",
|
|
UserId = "user",
|
|
Password = "pass",
|
|
ConnectionTimeout = 30 // Default value
|
|
};
|
|
|
|
// Act
|
|
var result = entry.GenerateConnectionString();
|
|
|
|
// Assert
|
|
result.ShouldNotContain("Connection Timeout=");
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateConnectionString_Oracle_ProducesEZConnectFormat()
|
|
{
|
|
// Arrange
|
|
var entry = new ConnectionStringEntry
|
|
{
|
|
Provider = ConnectionProvider.Oracle,
|
|
Host = "oracle-server.example.com",
|
|
Port = 1522,
|
|
ServiceName = "ORCL",
|
|
UserId = "scott",
|
|
Password = "tiger"
|
|
};
|
|
|
|
// Act
|
|
var result = entry.GenerateConnectionString();
|
|
|
|
// Assert
|
|
result.ShouldContain("Data Source=//oracle-server.example.com:1522/ORCL");
|
|
result.ShouldContain("User Id=scott");
|
|
result.ShouldContain("Password=tiger");
|
|
}
|
|
|
|
[Fact]
|
|
public void GenerateConnectionString_Generic_ReturnsRawString()
|
|
{
|
|
// Arrange
|
|
var rawConnString = "Driver={ODBC Driver};Server=myserver;Database=mydb;";
|
|
var entry = new ConnectionStringEntry
|
|
{
|
|
Provider = ConnectionProvider.Generic,
|
|
RawConnectionString = rawConnString
|
|
};
|
|
|
|
// Act
|
|
var result = entry.GenerateConnectionString();
|
|
|
|
// Assert
|
|
result.ShouldBe(rawConnString);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultValues_AreCorrect()
|
|
{
|
|
// Act
|
|
var entry = new ConnectionStringEntry();
|
|
|
|
// Assert
|
|
entry.Name.ShouldBe(string.Empty);
|
|
entry.Provider.ShouldBe(ConnectionProvider.Generic);
|
|
entry.Server.ShouldBeNull();
|
|
entry.Database.ShouldBeNull();
|
|
entry.UserId.ShouldBeNull();
|
|
entry.Password.ShouldBeNull();
|
|
entry.Encrypt.ShouldBe("True");
|
|
entry.TrustServerCertificate.ShouldBeFalse();
|
|
entry.ConnectionTimeout.ShouldBe(30);
|
|
entry.ApplicationName.ShouldBeNull();
|
|
entry.Host.ShouldBeNull();
|
|
entry.Port.ShouldBe(1521);
|
|
entry.ServiceName.ShouldBeNull();
|
|
entry.RawConnectionString.ShouldBeNull();
|
|
}
|
|
}
|