53 lines
2.0 KiB
C#
53 lines
2.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Http;
|
|
using NSubstitute;
|
|
using ScadaLink.Commons.Interfaces.Repositories;
|
|
|
|
namespace ScadaLink.ExternalSystemGateway.Tests;
|
|
|
|
/// <summary>
|
|
/// ExternalSystemGateway-013: configuration options must actually influence the
|
|
/// registered HTTP client — an operator setting them must not be silently ignored.
|
|
/// </summary>
|
|
public class ServiceWiringTests
|
|
{
|
|
[Fact]
|
|
public void MaxConcurrentConnectionsPerSystem_IsAppliedToTheNamedHttpClientPrimaryHandler()
|
|
{
|
|
var config = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ScadaLink:ExternalSystemGateway:MaxConcurrentConnectionsPerSystem"] = "4",
|
|
})
|
|
.Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddLogging();
|
|
services.AddSingleton<IConfiguration>(config);
|
|
services.AddSingleton(Substitute.For<IExternalSystemRepository>());
|
|
services.AddExternalSystemGateway();
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
|
|
// Resolve the per-system named client's message-handler chain and walk to the
|
|
// primary handler — the option must be reflected in MaxConnectionsPerServer.
|
|
var handlerFactory = provider.GetRequiredService<IHttpMessageHandlerFactory>();
|
|
var handler = handlerFactory.CreateHandler("ExternalSystem_AnySystem");
|
|
|
|
var primary = FindPrimaryHandler(handler);
|
|
var sockets = Assert.IsType<SocketsHttpHandler>(primary);
|
|
Assert.Equal(4, sockets.MaxConnectionsPerServer);
|
|
}
|
|
|
|
private static HttpMessageHandler FindPrimaryHandler(HttpMessageHandler handler)
|
|
{
|
|
var current = handler;
|
|
while (current is DelegatingHandler delegating && delegating.InnerHandler != null)
|
|
{
|
|
current = delegating.InnerHandler;
|
|
}
|
|
return current;
|
|
}
|
|
}
|