50 lines
1.9 KiB
C#
50 lines
1.9 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace ScadaLink.DeploymentManager.Tests;
|
|
|
|
/// <summary>
|
|
/// DeploymentManager-008: DeploymentManagerOptions must be bound to the
|
|
/// "ScadaLink:DeploymentManager" configuration section, consistent with the
|
|
/// Options-pattern convention used by the other components.
|
|
/// </summary>
|
|
public class ServiceCollectionExtensionsTests
|
|
{
|
|
[Fact]
|
|
public void AddDeploymentManager_WithConfiguration_BindsDeploymentManagerOptions()
|
|
{
|
|
var configuration = new ConfigurationBuilder()
|
|
.AddInMemoryCollection(new Dictionary<string, string?>
|
|
{
|
|
["ScadaLink:DeploymentManager:OperationLockTimeout"] = "00:00:09",
|
|
["ScadaLink:DeploymentManager:ArtifactDeploymentTimeoutPerSite"] = "00:03:00"
|
|
})
|
|
.Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddDeploymentManager(configuration);
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
var options = provider.GetRequiredService<IOptions<DeploymentManagerOptions>>().Value;
|
|
|
|
Assert.Equal(TimeSpan.FromSeconds(9), options.OperationLockTimeout);
|
|
Assert.Equal(TimeSpan.FromMinutes(3), options.ArtifactDeploymentTimeoutPerSite);
|
|
}
|
|
|
|
[Fact]
|
|
public void AddDeploymentManager_WithConfiguration_MissingSection_UsesDefaults()
|
|
{
|
|
var configuration = new ConfigurationBuilder().Build();
|
|
|
|
var services = new ServiceCollection();
|
|
services.AddDeploymentManager(configuration);
|
|
|
|
using var provider = services.BuildServiceProvider();
|
|
var options = provider.GetRequiredService<IOptions<DeploymentManagerOptions>>().Value;
|
|
|
|
// No section present -> the option-class defaults are retained.
|
|
Assert.Equal(TimeSpan.FromSeconds(5), options.OperationLockTimeout);
|
|
}
|
|
}
|