< Summary

Information
Class: MyNet.Globalization.GlobalizationService
Assembly: MyNet.Globalization
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Globalization/GlobalizationService.cs
Tag: 323_28699572109
Line coverage
31%
Covered lines: 7
Uncovered lines: 15
Coverable lines: 22
Total lines: 89
Line coverage: 31.8%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_CurrentCulture()100%11100%
get_CurrentTimeZone()100%210%
get_Now()100%210%
add_CultureChanged(...)100%11100%
remove_CultureChanged(...)100%11100%
add_TimeZoneChanged(...)100%11100%
remove_TimeZoneChanged(...)100%11100%
SetCulture(...)100%11100%
SetCulture(...)100%11100%
SetTimeZone(...)100%210%
SetTimeZone(...)100%210%
FromUtc(...)100%210%
ToUtc(...)100%210%
Convert(...)100%210%
UseCulture(...)100%210%
UseTimeZone(...)100%210%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Globalization/GlobalizationService.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="GlobalizationService.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using System.Globalization;
 9using MyNet.Globalization.Culture;
 10using MyNet.Globalization.DateTime;
 11using MyNet.Primitives;
 12
 13namespace MyNet.Globalization;
 14
 15/// <summary>
 16/// Provides a service for managing globalization settings, including culture and time zone information.
 17/// </summary>
 18public sealed class GlobalizationService(ICultureService cultureService, ITimeZoneService timeZoneService)
 19    : IGlobalizationService
 20{
 21    /// <inheritdoc />
 15322    public CultureInfo CurrentCulture => cultureService.CurrentCulture;
 23
 24    /// <inheritdoc />
 025    public TimeZoneInfo CurrentTimeZone => timeZoneService.CurrentTimeZone;
 26
 27    /// <inheritdoc />
 028    public System.DateTime Now => timeZoneService.Now;
 29
 30    /// <inheritdoc />
 31    public event EventHandler<CultureChangedEventArgs> CultureChanged
 32    {
 1533        add => cultureService.CultureChanged += value;
 634        remove => cultureService.CultureChanged -= value;
 35    }
 36
 37    /// <inheritdoc />
 38    public event EventHandler<TimeZoneChangedEventArgs> TimeZoneChanged
 39    {
 1540        add => timeZoneService.TimeZoneChanged += value;
 641        remove => timeZoneService.TimeZoneChanged -= value;
 42    }
 43
 44    /// <inheritdoc />
 570345    public void SetCulture(CultureInfo culture) => cultureService.SetCulture(culture);
 46
 47    /// <inheritdoc />
 5148    public void SetCulture(string cultureCode) => cultureService.SetCulture(cultureCode);
 49
 50    /// <inheritdoc />
 051    public void SetTimeZone(TimeZoneInfo timeZone) => timeZoneService.SetTimeZone(timeZone);
 52
 53    /// <inheritdoc />
 054    public void SetTimeZone(string timeZoneId) => timeZoneService.SetTimeZone(timeZoneId);
 55
 56    /// <inheritdoc />
 057    public DateTimeOffset FromUtc(DateTimeOffset utcDateTime) => timeZoneService.FromUtc(utcDateTime);
 58
 59    /// <inheritdoc />
 060    public DateTimeOffset ToUtc(DateTimeOffset localDateTime) => timeZoneService.ToUtc(localDateTime);
 61
 62    /// <inheritdoc />
 063    public DateTimeOffset Convert(DateTimeOffset dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone
 64
 65    /// <inheritdoc />
 66    public IDisposable UseCulture(CultureInfo culture)
 67    {
 068        ArgumentNullException.ThrowIfNull(culture);
 69
 070        var previousCulture = CurrentCulture;
 71
 072        cultureService.SetCulture(culture);
 73
 074        return new DelegateDisposable(() => cultureService.SetCulture(previousCulture));
 75    }
 76
 77    /// <inheritdoc />
 78    public IDisposable UseTimeZone(TimeZoneInfo timeZone)
 79    {
 080        ArgumentNullException.ThrowIfNull(timeZone);
 81
 082        var previousTimeZone = CurrentTimeZone;
 83
 084        timeZoneService.SetTimeZone(timeZone);
 85
 086        return new DelegateDisposable(() => timeZoneService.SetTimeZone(previousTimeZone));
 87    }
 88}
 89