7b0b9c7365
Solution + 23 src projects + 26 test projects renamed; folders, csproj, namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated. ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated. SQL roles/logins, LDAP domains, CLI command name, and CLI config dir (~/.scadalink → ~/.scadabridge) also renamed. Build green; 5 Host.Tests fail awaiting SQL login rename in next commit. Pre-existing StaleTagMonitor timing flakes unchanged. Rename script committed at tools/rename-to-scadabridge.sh.
59 lines
2.5 KiB
C#
59 lines
2.5 KiB
C#
using System.Reflection;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
|
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
|
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Tests;
|
|
|
|
public class ServiceCollectionExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void AddConfigurationDatabase_WithConnectionString_RegistersRepositoriesAndServices()
|
|
{
|
|
var services = new ServiceCollection();
|
|
|
|
services.AddConfigurationDatabase("DataSource=:memory:");
|
|
|
|
Assert.Contains(services, d => d.ServiceType == typeof(ITemplateEngineRepository));
|
|
Assert.Contains(services, d => d.ServiceType == typeof(IAuditService));
|
|
Assert.Contains(services, d => d.ServiceType == typeof(IInstanceLocator));
|
|
Assert.Contains(services, d => d.ServiceType == typeof(IAuditLogRepository));
|
|
}
|
|
|
|
// The no-arg overload is [Obsolete(error: true)], so it cannot be referenced directly
|
|
// from source — that is the compile-time guard. Invoke it via reflection to verify the
|
|
// runtime defence-in-depth behaviour.
|
|
private static MethodInfo NoArgOverload =>
|
|
typeof(ServiceCollectionExtensions).GetMethod(
|
|
nameof(ServiceCollectionExtensions.AddConfigurationDatabase),
|
|
BindingFlags.Public | BindingFlags.Static,
|
|
binder: null,
|
|
types: new[] { typeof(IServiceCollection) },
|
|
modifiers: null)!;
|
|
|
|
[Fact]
|
|
public void AddConfigurationDatabase_NoArgOverload_FailsFastWithClearMessage()
|
|
{
|
|
// Regression guard for ConfigurationDatabase-003: the parameterless overload must not
|
|
// silently register nothing. Misuse must surface immediately at wire-up time with an
|
|
// actionable message — not later as an opaque DI resolution failure.
|
|
var services = new ServiceCollection();
|
|
|
|
var invocation = Assert.Throws<TargetInvocationException>(
|
|
() => NoArgOverload.Invoke(null, new object[] { services }));
|
|
|
|
var ex = Assert.IsType<InvalidOperationException>(invocation.InnerException);
|
|
Assert.Contains("connection string", ex.Message, StringComparison.OrdinalIgnoreCase);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddConfigurationDatabase_NoArgOverload_IsMarkedObsoleteAsError()
|
|
{
|
|
// The no-op overload must be flagged so misuse is caught at compile time.
|
|
var obsolete = NoArgOverload.GetCustomAttribute<ObsoleteAttribute>();
|
|
Assert.NotNull(obsolete);
|
|
Assert.True(obsolete!.IsError);
|
|
}
|
|
}
|