< Summary

Class:Itinero.Instructions.IRouteAndBaseInstructionsExtensions
Assembly:Itinero.Instructions
File(s):/home/runner/work/routing2/routing2/src/Itinero.Instructions/IRouteAndBaseInstructionsExtensions.cs
Covered lines:6
Uncovered lines:24
Coverable lines:30
Total lines:63
Line coverage:20% (6 of 30)
Covered branches:1
Total branches:6
Branch coverage:16.6% (1 of 6)
Tag:224_14471318300

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
ForLanguage(...)50%275%
ForLanguage(...)0%40%

File(s)

/home/runner/work/routing2/routing2/src/Itinero.Instructions/IRouteAndBaseInstructionsExtensions.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4
 5namespace Itinero.Instructions;
 6
 7/// <summary>
 8/// Extensions on top of a generated route and base instructions object.
 9/// </summary>
 10// ReSharper disable once InconsistentNaming
 11public static class IRouteAndBaseInstructionsExtensions
 12{
 13    /// <summary>
 14    /// Generates text for all the base instructions for the given language code.
 15    /// </summary>
 16    /// <param name="routeAndBaseInstructions">The route and base instructions.</param>
 17    /// <param name="languageCode">The language code.</param>
 18    public static IRouteAndInstructions ForLanguage(this IRouteAndBaseInstructions routeAndBaseInstructions,
 19        string languageCode = "en")
 220    {
 221        if (!routeAndBaseInstructions.Languages.TryGetValue(languageCode, out var languageGenerator))
 022        {
 023            throw new ArgumentOutOfRangeException($"Language {languageCode} not configured");
 24        }
 25
 226        var instructions = routeAndBaseInstructions.BaseInstructions.Select(baseInstruction =>
 627            new Instruction(baseInstruction, new Dictionary<string, string>() { { languageCode, languageGenerator.ToText
 28
 229        return new RouteAndInstructions(routeAndBaseInstructions.Route, instructions);
 230    }
 31
 32    /// <summary>
 33    /// Generates text for all the base instructions for the given language code.
 34    /// </summary>
 35    /// <param name="routeAndBaseInstructions">The route and base instructions.</param>
 36    /// <param name="languageCodes">The language codes.</param>
 37    public static IRouteAndInstructions ForLanguage(this IRouteAndBaseInstructions routeAndBaseInstructions,
 38        IEnumerable<string> languageCodes)
 039    {
 040        var languageGenerators = languageCodes.Select(languageCode =>
 041        {
 042            if (!routeAndBaseInstructions.Languages.TryGetValue(languageCode, out var languageGenerator))
 043            {
 044                throw new ArgumentOutOfRangeException($"Language {languageCode} not configured");
 045            }
 046
 047            return (languageCode, languageGenerator);
 048        });
 49
 050        var instructions = routeAndBaseInstructions.BaseInstructions.Select(baseInstruction =>
 051        {
 052            var text = new Dictionary<string, string>();
 053            foreach (var (languageCode, languageGenerator) in languageGenerators)
 054            {
 055                text[languageCode] = languageGenerator.ToText(baseInstruction);
 056            }
 057
 058            return new Instruction(baseInstruction, text);
 059        }).ToList();
 60
 061        return new RouteAndInstructions(routeAndBaseInstructions.Route, instructions);
 062    }
 63}

Methods/Properties

ForLanguage(...)
ForLanguage(...)