Files
VolcanicCore/tests/VolcanicCore.Tests/ProgramEnvParsingTests.cs

41 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Hosting;
namespace VolcanicCore.Tests;
public class ProgramEnvParsingTests
{
private sealed class BadIntFactory : WebFactory
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.UseSetting(nameof(VolcanicCore.Api.AppSettings.ExecutionRetentionDays), "not-a-number");
}
}
private sealed class BadKeyFactory : WebFactory
{
protected override void ConfigureWebHost(IWebHostBuilder builder)
{
base.ConfigureWebHost(builder);
builder.UseSetting(nameof(VolcanicCore.Api.AppSettings.EncryptionKeyBase64), "!!!not-base64!!!");
}
}
[Fact]
public void Bad_integer_env_fails_fast_with_named_error()
{
using var f = new BadIntFactory();
var ex = Assert.Throws<InvalidOperationException>(() => f.CreateClient());
Assert.Contains("EXECUTION_RETENTION_DAYS", ex.Message);
}
[Fact]
public void Bad_encryption_key_fails_fast_with_named_error()
{
using var f = new BadKeyFactory();
var ex = Assert.Throws<InvalidOperationException>(() => f.CreateClient());
Assert.Contains("ENCRYPTION_KEY", ex.Message);
}
}