Seperate database entity from ui object (Reactive)

This commit is contained in:
eelke 2025-08-31 14:25:27 +02:00
parent 739d6bd65a
commit 747358297b
10 changed files with 176 additions and 154 deletions

View file

@ -12,20 +12,19 @@ public class ServerConfigurationMappingTests
[Fact]
public void ToDescriptor_Basic_MapsExpectedFields()
{
var cfg = new ServerConfiguration
ServerConfigurationEntity cfg = new()
{
Name = "Prod",
Host = "db.example.com",
Port = 5433,
InitialDatabase = "appdb",
DefaultSslMode = SslMode.Require,
SslMode = SslMode.Require,
User = new ServerUser { Name = "alice", Password = "secret" }
};
var extra = new Dictionary<string,string>{{"search_path","public"}};
var d = ServerConfigurationMapping.ToDescriptor(cfg, applicationName: "pgLabII", timeoutSeconds: 15, extraProperties: extra);
Assert.Equal("Prod", d.Name);
Assert.Single(d.Hosts);
Assert.Equal("db.example.com", d.Hosts[0].Host);
Assert.Equal((ushort)5433, d.Hosts[0].Port);
@ -42,7 +41,7 @@ public class ServerConfigurationMappingTests
[Fact]
public void ToDescriptor_OmitsEmptyFields()
{
var cfg = new ServerConfiguration
ServerConfigurationEntity cfg = new ()
{
Name = "Empty",
Host = "",
@ -63,7 +62,6 @@ public class ServerConfigurationMappingTests
{
var desc = new ConnectionDescriptor
{
Name = "Staging",
Hosts = new []
{
new HostEndpoint{ Host = "host1", Port = 5432 },
@ -75,13 +73,12 @@ public class ServerConfigurationMappingTests
SslMode = SslMode.VerifyFull
};
var cfg = ServerConfigurationMapping.FromDescriptor(desc);
ServerConfigurationEntity cfg = ServerConfigurationMapping.FromDescriptor(desc);
Assert.Equal("Staging", cfg.Name);
Assert.Equal("host1", cfg.Host);
Assert.Equal((ushort)5432, cfg.Port);
Assert.Equal("stagedb", cfg.InitialDatabase);
Assert.Equal(SslMode.VerifyFull, cfg.DefaultSslMode);
Assert.Equal(SslMode.VerifyFull, cfg.SslMode);
Assert.Equal("bob", cfg.User.Name);
Assert.Equal("pwd", cfg.User.Password);
}
@ -89,13 +86,13 @@ public class ServerConfigurationMappingTests
[Fact]
public void FromDescriptor_UpdatesExisting_PreservesMissing()
{
var existing = new ServerConfiguration
ServerConfigurationEntity existing = new()
{
Name = "Existing",
Host = "keep-host",
Port = 5432,
InitialDatabase = "keepdb",
DefaultSslMode = SslMode.Prefer,
SslMode = SslMode.Prefer,
User = new ServerUser { Name = "keepuser", Password = "keeppwd" }
};
@ -110,7 +107,7 @@ public class ServerConfigurationMappingTests
Assert.Equal("new-host", cfg.Host);
Assert.Equal((ushort)5432, cfg.Port); // unchanged
Assert.Equal("keepdb", cfg.InitialDatabase); // preserved
Assert.Equal(SslMode.Prefer, cfg.DefaultSslMode); // preserved
Assert.Equal(SslMode.Prefer, cfg.SslMode); // preserved
Assert.Equal("keepuser", cfg.User.Name); // preserved
Assert.Equal("keeppwd", cfg.User.Password); // preserved
}
@ -118,24 +115,23 @@ public class ServerConfigurationMappingTests
[Fact]
public void Roundtrip_Basic()
{
var cfg = new ServerConfiguration
ServerConfigurationEntity cfg = new()
{
Name = "Round",
Host = "localhost",
Port = 5432,
InitialDatabase = "postgres",
DefaultSslMode = SslMode.Allow,
SslMode = SslMode.Allow,
User = new ServerUser { Name = "me", Password = "pw" }
};
var d = ServerConfigurationMapping.ToDescriptor(cfg);
var cfg2 = ServerConfigurationMapping.FromDescriptor(d);
Assert.Equal(cfg.Name, cfg2.Name);
Assert.Equal(cfg.Host, cfg2.Host);
Assert.Equal(cfg.Port, cfg2.Port);
Assert.Equal(cfg.InitialDatabase, cfg2.InitialDatabase);
Assert.Equal(cfg.DefaultSslMode, cfg2.DefaultSslMode);
Assert.Equal(cfg.SslMode, cfg2.SslMode);
Assert.Equal(cfg.User.Name, cfg2.User.Name);
Assert.Equal(cfg.User.Password, cfg2.User.Password);
}