33 lines
1.3 KiB
C#
33 lines
1.3 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.DataConnectionLayer.Tests;
|
|
|
|
public class GlobalOptionsValidationTests
|
|
{
|
|
[Theory]
|
|
[InlineData("ScadaBridge:OpcUa:ApplicationName")]
|
|
[InlineData("ScadaBridge:MxGateway:ClientNamePrefix")]
|
|
public void StartupRejectsBlankIdentity(string key)
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().AddInMemoryCollection(
|
|
new Dictionary<string, string?> { [key] = " " }).Build());
|
|
services.AddDataConnectionLayer();
|
|
using var provider = services.BuildServiceProvider();
|
|
var exception = Assert.Throws<OptionsValidationException>(() => provider.GetRequiredService<IStartupValidator>().Validate());
|
|
Assert.Contains(key, exception.Message);
|
|
}
|
|
|
|
[Fact]
|
|
public void DefaultsValidateAtStartup()
|
|
{
|
|
var services = new ServiceCollection();
|
|
services.AddSingleton<IConfiguration>(new ConfigurationBuilder().Build());
|
|
services.AddDataConnectionLayer();
|
|
using var provider = services.BuildServiceProvider();
|
|
provider.GetRequiredService<IStartupValidator>().Validate();
|
|
}
|
|
}
|