using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace ScadaLink.ClusterInfrastructure.Tests; /// /// CI-002: Tests that /// does real work rather than silently returning success — it must register /// the so misconfiguration fails fast. /// (The companion actor-registration test was removed alongside the deleted /// `AddClusterInfrastructureActors` extension method — see ClusterInfra-014.) /// public class ServiceCollectionExtensionsTests { [Fact] public void AddClusterInfrastructure_RegistersOptionsValidator() { var services = new ServiceCollection(); services.AddClusterInfrastructure(); var validators = services .Where(d => d.ServiceType == typeof(IValidateOptions)) .ToList(); Assert.NotEmpty(validators); using var provider = services.BuildServiceProvider(); var validator = provider.GetService>(); Assert.IsType(validator); } [Fact] public void AddClusterInfrastructure_ValidatorRejectsBadOptionsAtResolution() { var services = new ServiceCollection(); services.AddClusterInfrastructure(); // A MinNrOfMembers of 2 blocks the cluster singleton after failover. services.Configure(o => { o.SeedNodes = new List { "akka.tcp://scadalink@node1:8081" }; o.MinNrOfMembers = 2; }); using var provider = services.BuildServiceProvider(); var ex = Assert.Throws( () => provider.GetRequiredService>().Value); Assert.Contains("MinNrOfMembers", ex.Message); } // ClusterInfra-014: `AddClusterInfrastructureActors_ThrowsRatherThanSilentlySucceeding` // was removed alongside the now-deleted `AddClusterInfrastructureActors` // extension method. The Akka.NET actor wiring legitimately lives in // `ScadaLink.Host` (AkkaHostedService) per the // Component-ClusterInfrastructure.md "Implementation Note — Code Placement" // section; this project no longer exposes an actor-registration extension. }