< Summary

Information
Class: Allyaria.Theming.Helpers.ThemeConfigurator
Assembly: Allyaria.Theming
File(s): /home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Helpers/ThemeConfigurator.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
Total lines: 84
Line coverage: 100%
Branch coverage
100%
Covered branches: 18
Total branches: 18
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
get_Count()100%11100%
get_Item(...)100%11100%
GetEnumerator()100%11100%
System.Collections.IEnumerable.GetEnumerator()100%11100%
Override(...)100%1818100%

File(s)

/home/runner/work/allyaria/allyaria/src/Allyaria.Theming/Helpers/ThemeConfigurator.cs

#LineLine coverage
 1namespace Allyaria.Theming.Helpers;
 2
 3/// <summary>
 4/// Provides a configurable implementation of <see cref="IThemeConfigurator" /> that allows consumers to override specif
 5/// theming values through a collection of <see cref="ThemeUpdater" /> entries.
 6/// </summary>
 7/// <remarks>
 8///     <para>
 9///     The <see cref="ThemeConfigurator" /> is used during application startup to register or customize the Allyaria th
 10///     by chaining calls to <see cref="Override(ThemeUpdater)" />.
 11///     </para>
 12///     <para>
 13///     It enforces immutability rules by preventing modification of system or high-contrast themes, ensuring consistent
 14///     accessibility and visual integrity.
 15///     </para>
 16/// </remarks>
 17public sealed class ThemeConfigurator : IThemeConfigurator
 18{
 19    /// <summary>Internal list of <see cref="ThemeUpdater" /> instances representing theme overrides.</summary>
 1520    private readonly List<ThemeUpdater> _internalList = new();
 21
 22    /// <summary>Gets the total number of configured <see cref="ThemeUpdater" /> entries.</summary>
 323    public int Count => _internalList.Count;
 24
 25    /// <summary>Gets the <see cref="ThemeUpdater" /> at the specified index.</summary>
 26    /// <param name="index">The zero-based index of the updater to retrieve.</param>
 27    /// <returns>The <see cref="ThemeUpdater" /> at the specified index.</returns>
 628    public ThemeUpdater this[int index] => _internalList[index: index];
 29
 30    /// <summary>Returns an enumerator that iterates through the collection of theme updaters.</summary>
 31    /// <returns>An enumerator for the <see cref="ThemeUpdater" /> collection.</returns>
 232    public IEnumerator<ThemeUpdater> GetEnumerator() => _internalList.GetEnumerator();
 33
 34    /// <summary>Returns a non-generic enumerator that iterates through the collection of theme updaters.</summary>
 35    /// <returns>An enumerator for the <see cref="ThemeUpdater" /> collection.</returns>
 136    IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_internalList).GetEnumerator();
 37
 38    /// <summary>Adds or replaces a <see cref="ThemeUpdater" /> in the configuration sequence.</summary>
 39    /// <param name="updater">The <see cref="ThemeUpdater" /> that defines a theming update or override to apply.</param
 40    /// <returns>The current <see cref="IThemeConfigurator" /> instance, allowing for fluent chaining.</returns>
 41    /// <exception cref="AryArgumentException">
 42    /// Thrown when an invalid override is attempted, such as modifying system or high-contrast themes, or restricted co
 43    /// states.
 44    /// </exception>
 45    public IThemeConfigurator Override(ThemeUpdater updater)
 46    {
 1947        if (updater.Navigator.ThemeTypes.Contains(value: ThemeType.System))
 48        {
 149            throw new AryArgumentException(
 150                message: "System theme cannot be set directly.", argName: nameof(updater.Value)
 151            );
 52        }
 53
 1854        if (updater.Navigator.ComponentStates.Contains(value: ComponentState.Hidden) ||
 1855            updater.Navigator.ComponentStates.Contains(value: ComponentState.ReadOnly))
 56        {
 257            throw new AryArgumentException(
 258                message: "Hidden and read-only states cannot be set directly.", argName: nameof(updater.Value)
 259            );
 60        }
 61
 1662        if (updater.Navigator.ThemeTypes.Contains(value: ThemeType.HighContrastDark) ||
 1663            updater.Navigator.ThemeTypes.Contains(value: ThemeType.HighContrastLight))
 64        {
 265            throw new AryArgumentException(
 266                message: "Cannot alter High Contrast themes.", argName: nameof(updater.Value)
 267            );
 68        }
 69
 1470        if (updater.Navigator.ComponentStates.Contains(value: ComponentState.Focused) &&
 1471            (updater.Navigator.StyleTypes.Contains(value: StyleType.OutlineOffset) ||
 1472                updater.Navigator.StyleTypes.Contains(value: StyleType.OutlineStyle) ||
 1473                updater.Navigator.StyleTypes.Contains(value: StyleType.OutlineWidth)))
 74        {
 375            throw new AryArgumentException(
 376                message: "Cannot change focused outline offset, style or width.", argName: nameof(updater.Value)
 377            );
 78        }
 79
 1180        _internalList.Add(item: updater);
 81
 1182        return this;
 83    }
 84}