513fa1aa16
Comment/XML-doc changes only: - add summaries to ~10k test methods, fixtures, fakes and helpers (+ <param> on theories, <returns> on async Task methods, <inheritdoc/> on interface implementations the checker can resolve) - strip ~2.6k project-tracking references (WP*, P*-*, row-NN, Task N, #NN, Component-0NN) from comments, keeping the explanatory text; reword false positives in comments only - real docs on fakes implementing BCL/library interfaces (IDisposable, ILogger, IOptionsMonitor, IAsyncLifetime) - reword the last 5 src/ false positives (CWE-1236, failures-1, year-0001, M365) Only non-comment edits: four one-line nested classes split across lines so members can carry docs. Build 0 errors / 0 warnings.
78 lines
3.0 KiB
C#
78 lines
3.0 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
|
|
namespace ZB.MOM.WW.ScadaBridge.Host.Tests;
|
|
|
|
public class InboundApiKeyStoreOptionsTests
|
|
{
|
|
private static IConfiguration BuildConfig(Dictionary<string, string?> values)
|
|
{
|
|
return new ConfigurationBuilder()
|
|
.AddInMemoryCollection(values)
|
|
.Build();
|
|
}
|
|
|
|
/// <summary>Verifies that the key store provider defaults to SQLite.</summary>
|
|
[Fact]
|
|
public void Provider_DefaultsToSqlite()
|
|
{
|
|
Assert.Equal(InboundApiKeyStoreProvider.Sqlite, new InboundApiKeyStoreOptions().Provider);
|
|
|
|
var configuration = new ConfigurationBuilder().Build();
|
|
|
|
Assert.Equal(InboundApiKeyStoreProvider.Sqlite, InboundApiKeyStoreOptions.ReadProvider(configuration));
|
|
}
|
|
|
|
/// <summary>Verifies that the provider name is parsed case-insensitively.</summary>
|
|
/// <param name="value">The configured provider text.</param>
|
|
/// <param name="expected">The provider the text should resolve to.</param>
|
|
[Theory]
|
|
[InlineData("sqlserver", InboundApiKeyStoreProvider.SqlServer)]
|
|
[InlineData("SQLSERVER", InboundApiKeyStoreProvider.SqlServer)]
|
|
[InlineData("SqlServer", InboundApiKeyStoreProvider.SqlServer)]
|
|
[InlineData("sqlite", InboundApiKeyStoreProvider.Sqlite)]
|
|
public void Provider_ParsesCaseInsensitively(string value, InboundApiKeyStoreProvider expected)
|
|
{
|
|
var configuration = BuildConfig(new Dictionary<string, string?>
|
|
{
|
|
[$"{InboundApiKeyStoreOptions.SectionPath}:Provider"] = value,
|
|
});
|
|
|
|
Assert.Equal(expected, InboundApiKeyStoreOptions.ReadProvider(configuration));
|
|
}
|
|
|
|
/// <summary>Verifies that an unknown provider value is rejected.</summary>
|
|
/// <param name="value">The unsupported provider text.</param>
|
|
[Theory]
|
|
[InlineData("Postgres")]
|
|
[InlineData("7")]
|
|
public void Provider_RejectsUnknownValue(string value)
|
|
{
|
|
var configuration = BuildConfig(new Dictionary<string, string?>
|
|
{
|
|
[$"{InboundApiKeyStoreOptions.SectionPath}:Provider"] = value,
|
|
});
|
|
|
|
var ex = Assert.Throws<InvalidOperationException>(() => InboundApiKeyStoreOptions.ReadProvider(configuration));
|
|
|
|
Assert.Contains("Sqlite", ex.Message);
|
|
Assert.Contains("SqlServer", ex.Message);
|
|
}
|
|
|
|
/// <summary>Verifies that the import-from-SQLite path setting binds from configuration.</summary>
|
|
[Fact]
|
|
public void Binds_ImportFromSqlitePath()
|
|
{
|
|
var configuration = BuildConfig(new Dictionary<string, string?>
|
|
{
|
|
[$"{InboundApiKeyStoreOptions.SectionPath}:Provider"] = "SqlServer",
|
|
[$"{InboundApiKeyStoreOptions.SectionPath}:ImportFromSqlitePath"] = "/app/data/inbound-api-keys.db",
|
|
});
|
|
|
|
var options = configuration.GetSection(InboundApiKeyStoreOptions.SectionPath).Get<InboundApiKeyStoreOptions>();
|
|
|
|
Assert.NotNull(options);
|
|
Assert.Equal(InboundApiKeyStoreProvider.SqlServer, options!.Provider);
|
|
Assert.Equal("/app/data/inbound-api-keys.db", options.ImportFromSqlitePath);
|
|
}
|
|
}
|