< Summary

Information
Class: ProjectTemplate.Infrastructure.Data.Extensions.ApplicationAuditReconciliationServiceExtensions
Assembly: ProjectTemplate.Infrastructure
File(s): /home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/Extensions/ApplicationAuditReconciliationServiceExtensions.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddApplicationAuditReconciliationCore(...)100%22100%

File(s)

/home/runner/work/NetCoreApplicationTemplate/NetCoreApplicationTemplate/src/ProjectTemplate.Infrastructure/Data/Extensions/ApplicationAuditReconciliationServiceExtensions.cs

#LineLine coverage
 1using Microsoft.Extensions.DependencyInjection;
 2using Microsoft.Extensions.DependencyInjection.Extensions;
 3using Microsoft.Extensions.Options;
 4using ProjectTemplate.Infrastructure.Data.Auditing;
 5
 6namespace ProjectTemplate.Infrastructure.Data.Extensions;
 7
 8public static class ApplicationAuditReconciliationServiceExtensions
 9{
 10    public static IServiceCollection AddApplicationAuditReconciliationCore(
 11        this IServiceCollection services,
 12        Action<ApplicationAuditReconciliationOptions>? configure = null)
 13    {
 214        ArgumentNullException.ThrowIfNull(services);
 15
 216        OptionsBuilder<ApplicationAuditReconciliationOptions> optionsBuilder = services
 217            .AddOptions<ApplicationAuditReconciliationOptions>()
 218            .Validate(options => options.Interval > TimeSpan.Zero,
 219                "The audit reconciliation interval must be greater than zero.")
 220            .Validate(options => options.MaximumCycleRetryDelay >= options.Interval,
 221                "The maximum audit reconciliation cycle retry delay must not be less than the interval.")
 222            .Validate(options => options.CompletionGracePeriod >= TimeSpan.Zero,
 223                "The completion grace period must not be negative.")
 224            .Validate(options => options.StalePendingThreshold > TimeSpan.Zero,
 225                "The stale pending threshold must be greater than zero.")
 226            .Validate(options => options.StaleRetryReadyThreshold > TimeSpan.Zero,
 227                "The stale retry-ready threshold must be greater than zero.")
 228            .Validate(options => options.MaximumBatchesPerRun is > 0 and <= 10_000,
 229                "Maximum batches per reconciliation run must be between 1 and 10000.")
 230            .Validate(options => options.MaximumMalformedRecordsPerRun is > 0 and <= 10_000,
 231                "Maximum malformed audit records per reconciliation run must be between 1 and 10000.")
 232            .Validate(options => options.HealthWarningFindingCount >= 0,
 233                "The warning finding threshold must not be negative.")
 234            .Validate(options => options.HealthUnhealthyFindingCount >= options.HealthWarningFindingCount,
 235                "The unhealthy finding threshold must not be less than the warning threshold.")
 236            .Validate(options => options.HealthStaleRunThreshold is null ||
 237                    options.HealthStaleRunThreshold > options.Interval,
 238                "The health stale-run threshold must be greater than the reconciliation interval.")
 239            .ValidateOnStart();
 40
 241        if (configure is not null)
 42        {
 143            optionsBuilder.Configure(configure);
 44        }
 45
 246        services.TryAddSingleton(TimeProvider.System);
 247        services.TryAddSingleton<ApplicationAuditReconciliationMetrics>();
 248        services.TryAddScoped<ApplicationAuditReconciler>();
 249        services.TryAddScoped<IApplicationAuditReconciler>(serviceProvider =>
 250            serviceProvider.GetRequiredService<ApplicationAuditReconciler>());
 251        return services;
 52    }
 53}