using Microsoft.Extensions.Configuration;
using Shouldly;
using Xunit;
namespace ZB.MOM.WW.OtOpcUa.Runtime.Tests.Historian;
/// #603: the single "is this node's LocalDb replicated" predicate shared by table registration and the alarm drain gate.
public sealed class LocalDbReplicationPolicyTests
{
private static IConfiguration Config(params (string Key, string? Value)[] pairs) =>
new ConfigurationBuilder()
.AddInMemoryCollection(pairs.Select(p => new KeyValuePair(p.Key, p.Value)))
.Build();
/// PeerAddress OR ApiKey counts; the listen port alone and blank values do not.
[Theory]
[InlineData("LocalDb:Replication:PeerAddress", "http://peer:9001", true)]
[InlineData("LocalDb:Replication:ApiKey", "k", true)]
[InlineData("LocalDb:SyncListenPort", "9001", false)]
[InlineData("LocalDb:Replication:ApiKey", " ", false)]
public void IsConfigured_follows_the_PeerAddress_or_ApiKey_rule(string key, string value, bool expected)
{
LocalDbReplicationPolicy.IsConfigured(Config((key, value))).ShouldBe(expected);
}
/// No replication keys at all is an unpaired node.
[Fact]
public void IsConfigured_is_false_for_an_empty_configuration()
{
LocalDbReplicationPolicy.IsConfigured(Config()).ShouldBeFalse();
}
}