feat(controlplane): ServiceLevelCalculator + ControlPlane.Tests harness
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Akka.TestKit.Xunit2;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using ZB.MOM.WW.OtOpcUa.Configuration;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.ControlPlane.Tests.Harness;
|
||||
|
||||
/// <summary>
|
||||
/// Akka TestKit fixture for ControlPlane actor tests. Provides:
|
||||
/// - A test ActorSystem (xunit2 TestKit) wired with PubSub/Cluster extensions.
|
||||
/// - A fresh in-memory <see cref="OtOpcUaConfigDbContext"/> per harness instance.
|
||||
/// - An <see cref="IDbContextFactory{TContext}"/> the actors can hold.
|
||||
///
|
||||
/// One harness per test fact — InMemory provider gives strong isolation when the database
|
||||
/// name is unique (random Guid).
|
||||
/// </summary>
|
||||
public abstract class ControlPlaneActorTestBase : TestKit
|
||||
{
|
||||
protected static string AkkaTestHocon => @"
|
||||
akka {
|
||||
loglevel = ""WARNING""
|
||||
actor {
|
||||
provider = ""Akka.Cluster.ClusterActorRefProvider, Akka.Cluster""
|
||||
}
|
||||
remote.dot-netty.tcp {
|
||||
hostname = ""127.0.0.1""
|
||||
port = 0
|
||||
}
|
||||
cluster {
|
||||
seed-nodes = []
|
||||
roles = [""admin""]
|
||||
min-nr-of-members = 1
|
||||
run-coordinated-shutdown-when-down = off
|
||||
}
|
||||
}";
|
||||
|
||||
protected ControlPlaneActorTestBase() : base(AkkaTestHocon) { }
|
||||
|
||||
protected static IDbContextFactory<OtOpcUaConfigDbContext> NewInMemoryDbFactory(string? dbName = null)
|
||||
{
|
||||
dbName ??= Guid.NewGuid().ToString("N");
|
||||
return new InMemoryConfigDbFactory(dbName);
|
||||
}
|
||||
|
||||
private sealed class InMemoryConfigDbFactory(string dbName) : IDbContextFactory<OtOpcUaConfigDbContext>
|
||||
{
|
||||
public OtOpcUaConfigDbContext CreateDbContext()
|
||||
{
|
||||
var opts = new DbContextOptionsBuilder<OtOpcUaConfigDbContext>()
|
||||
.UseInMemoryDatabase(dbName)
|
||||
.Options;
|
||||
return new OtOpcUaConfigDbContext(opts);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user