< Summary

Information
Class: MyNet.Observable.Behaviors.TimeZoneChangedBehavior
Assembly: MyNet.Observable
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/TimeZoneChangedBehavior.cs
Tag: 323_28699572109
Line coverage
90%
Covered lines: 10
Uncovered lines: 1
Coverable lines: 11
Total lines: 53
Line coverage: 90.9%
Branch coverage
50%
Covered branches: 3
Total branches: 6
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)50%22100%
OnTimeZoneChangedCallback(...)50%4475%
DisposeManagedResources()100%11100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.Observable/Behaviors/TimeZoneChangedBehavior.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="TimeZoneChangedBehavior.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.Globalization.DateTime;
 9using MyNet.Observable.Behaviors.Metadata.Features.Events;
 10
 11namespace MyNet.Observable.Behaviors;
 12
 13/// <summary>
 14/// Defines a behavior that listens for changes in the system time zone and raises an event when the time zone changes. 
 15/// </summary>
 16public sealed class TimeZoneChangedBehavior : EventBehavior<ObservableObject, TimeZoneChangedEvent>
 17{
 18    private readonly ITimeZoneService _service;
 19
 20    /// <summary>
 21    /// Initializes a new instance of the <see cref="TimeZoneChangedBehavior"/> class with the specified owner and time 
 22    /// </summary>
 23    /// <param name="owner">The owner object of this behavior.</param>
 24    /// <param name="timeZoneService">The time zone service to listen for changes.</param>
 25    /// <exception cref="ArgumentNullException">Thrown if the time zone service is null.</exception>
 26    public TimeZoneChangedBehavior(ObservableObject owner, ITimeZoneService timeZoneService)
 627        : base(owner)
 28    {
 629        _service = timeZoneService ?? throw new ArgumentNullException(nameof(timeZoneService));
 630        _service.TimeZoneChanged += OnTimeZoneChangedCallback;
 631    }
 32
 33    /// <summary>
 34    /// Callback method that is invoked when the system time zone changes. This method checks if the behavior is dispose
 35    /// </summary>
 36    /// <param name="sender">The source of the event.</param>
 37    /// <param name="e">The event data containing the new time zone information.</param>
 38    private void OnTimeZoneChangedCallback(object? sender, TimeZoneChangedEventArgs e)
 39    {
 340        if (IsDisposed || IsSuspended)
 041            return;
 42
 343        RaiseEvent(new(e.NewTimeZone));
 344    }
 45
 46    /// <inheritdoc/>
 47    protected override void DisposeManagedResources()
 48    {
 349        _service.TimeZoneChanged -= OnTimeZoneChangedCallback;
 350        base.DisposeManagedResources();
 351    }
 52}
 53