mirror of
https://github.com/Sea-Haven-Industries/shoc-backend.git
synced 2026-09-30 06:03:12 +00:00
73 lines
2.5 KiB
C#
73 lines
2.5 KiB
C#
|
|
using Microsoft.Extensions.Configuration;
|
||
|
|
using Microsoft.Extensions.DependencyInjection;
|
||
|
|
using Microsoft.Extensions.Options;
|
||
|
|
using SeaHaven.Services.Configuration;
|
||
|
|
using SeaHaven.Services.DependencyInjection;
|
||
|
|
using Xunit;
|
||
|
|
|
||
|
|
namespace SeaHaven.Services.Tests;
|
||
|
|
|
||
|
|
public sealed class WorkOrderReconciliationOptionsTests
|
||
|
|
{
|
||
|
|
[Fact]
|
||
|
|
public void Enabled_reconciliation_rejects_a_lease_shorter_than_worst_case_request_budget()
|
||
|
|
{
|
||
|
|
var values = new Dictionary<string, string?>
|
||
|
|
{
|
||
|
|
["WorkOrderReconciliation:Enabled"] = "true",
|
||
|
|
["WorkOrderReconciliation:RequestTimeoutSeconds"] = "30",
|
||
|
|
["WorkOrderReconciliation:MaxRetries"] = "3",
|
||
|
|
["WorkOrderReconciliation:RetryBaseDelayMilliseconds"] = "100",
|
||
|
|
["WorkOrderReconciliation:LeaseSeconds"] = "120"
|
||
|
|
};
|
||
|
|
|
||
|
|
using var provider = BuildProvider(values);
|
||
|
|
|
||
|
|
Assert.Throws<OptionsValidationException>(() => provider
|
||
|
|
.GetRequiredService<IOptions<WorkOrderReconciliationOptions>>().Value);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Disabled_reconciliation_does_not_require_a_request_budget_lease()
|
||
|
|
{
|
||
|
|
var values = new Dictionary<string, string?>
|
||
|
|
{
|
||
|
|
["WorkOrderReconciliation:Enabled"] = "false",
|
||
|
|
["WorkOrderReconciliation:LeaseSeconds"] = "1"
|
||
|
|
};
|
||
|
|
|
||
|
|
using var provider = BuildProvider(values);
|
||
|
|
|
||
|
|
Assert.False(provider
|
||
|
|
.GetRequiredService<IOptions<WorkOrderReconciliationOptions>>().Value.Enabled);
|
||
|
|
}
|
||
|
|
|
||
|
|
[Fact]
|
||
|
|
public void Enabled_reconciliation_rejects_a_lease_equal_to_the_request_budget()
|
||
|
|
{
|
||
|
|
var values = new Dictionary<string, string?>
|
||
|
|
{
|
||
|
|
["WorkOrderReconciliation:Enabled"] = "true",
|
||
|
|
["WorkOrderReconciliation:RequestTimeoutSeconds"] = "30",
|
||
|
|
["WorkOrderReconciliation:MaxRetries"] = "0",
|
||
|
|
["WorkOrderReconciliation:RetryBaseDelayMilliseconds"] = "0",
|
||
|
|
["WorkOrderReconciliation:LeaseSeconds"] = "30"
|
||
|
|
};
|
||
|
|
|
||
|
|
using var provider = BuildProvider(values);
|
||
|
|
|
||
|
|
Assert.Throws<OptionsValidationException>(() => provider
|
||
|
|
.GetRequiredService<IOptions<WorkOrderReconciliationOptions>>().Value);
|
||
|
|
}
|
||
|
|
|
||
|
|
private static ServiceProvider BuildProvider(IDictionary<string, string?> values)
|
||
|
|
{
|
||
|
|
var configuration = new ConfigurationBuilder()
|
||
|
|
.AddInMemoryCollection(values)
|
||
|
|
.Build();
|
||
|
|
var services = new ServiceCollection();
|
||
|
|
services.AddBusinessServices(configuration);
|
||
|
|
return services.BuildServiceProvider();
|
||
|
|
}
|
||
|
|
}
|