< Summary - Kestrun — Combined Coverage

Information
Class: Kestrun.Middleware.KestrunLocalizationMiddlewareExtensions
Assembly: Kestrun
File(s): /home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Middleware/KestrunLocalizationMiddlewareExtensions.cs
Tag: Kestrun/Kestrun@ca54e35c77799b76774b3805b6f075cdbc0c5fbe
Line coverage
56%
Covered lines: 13
Uncovered lines: 10
Coverable lines: 23
Total lines: 63
Line coverage: 56.5%
Branch coverage
57%
Covered branches: 8
Total branches: 14
Branch coverage: 57.1%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 01/24/2026 - 19:35:59 Line coverage: 56.5% (13/23) Branch coverage: 57.1% (8/14) Total lines: 63 Tag: Kestrun/Kestrun@f59dcba478ea75f69584d696e5f1fb1cfa40aa51 01/24/2026 - 19:35:59 Line coverage: 56.5% (13/23) Branch coverage: 57.1% (8/14) Total lines: 63 Tag: Kestrun/Kestrun@f59dcba478ea75f69584d696e5f1fb1cfa40aa51

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
UseKestrunLocalization(...)57.14%301456.52%

File(s)

/home/runner/work/Kestrun/Kestrun/src/CSharp/Kestrun/Middleware/KestrunLocalizationMiddlewareExtensions.cs

#LineLine coverage
 1using System.Globalization;
 2using Kestrun.Hosting;
 3using Kestrun.Localization;
 4
 5namespace Kestrun.Middleware;
 6
 7/// <summary>
 8/// Extension methods for adding Kestrun localization middleware.
 9/// </summary>
 10public static class KestrunLocalizationMiddlewareExtensions
 11{
 12    /// <summary>
 13    /// Adds Kestrun localization middleware to the pipeline.
 14    /// </summary>
 15    /// <param name="app">The application builder.</param>
 16    /// <param name="options">The localization options.</param>
 17    /// <returns>The application builder.</returns>
 18    public static IApplicationBuilder UseKestrunLocalization(
 19        this IApplicationBuilder app,
 20        KestrunLocalizationOptions options)
 21    {
 822        ArgumentNullException.ThrowIfNull(app);
 823        ArgumentNullException.ThrowIfNull(options);
 24
 825        var services = app.ApplicationServices;
 826        var env = services.GetService<IHostEnvironment>();
 827        var contentRoot = env?.ContentRootPath ?? Directory.GetCurrentDirectory();
 28
 829        KestrunHost? host = null;
 30        try
 31        {
 832            host = services.GetService<KestrunHost>();
 833        }
 034        catch
 35        {
 36            // Ignore any errors when host isn't available in this context.
 037        }
 38
 839        var logger = host?.Logger ?? Serilog.Log.Logger;
 840        var store = new KestrunLocalizationStore(options, contentRoot, logger);
 41
 42        // Set the default thread culture if specified in options.
 843        if (options.SetDefaultThreadCulture && !string.IsNullOrWhiteSpace(options.DefaultCulture))
 44        {
 45            try
 46            {
 047                var ci = CultureInfo.GetCultureInfo(options.DefaultCulture);
 048                CultureInfo.DefaultThreadCurrentCulture = ci;
 049                CultureInfo.DefaultThreadCurrentUICulture = ci;
 050                logger.Information("Default thread culture set to {Culture}", ci.Name);
 051            }
 052            catch (CultureNotFoundException)
 53            {
 054                logger.Warning("The specified default culture '{Culture}' is not valid.", options.DefaultCulture);
 055            }
 56        }
 57
 58        // If a KestrunHost is available via DI, capture the store on the host so tools
 59        // and PowerShell helpers can inspect runtime-loaded cultures.
 860        _ = (host?.LocalizationStore = store);
 861        return app.UseMiddleware<KestrunRequestCultureMiddleware>(store, options);
 62    }
 63}