< Summary

Information
Class: MyNet.UI.Toasting.DefaultToastFactory
Assembly: MyNet.UI
File(s): https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Toasting/DefaultToastFactory.cs
Tag: 323_28699572109
Line coverage
100%
Covered lines: 11
Uncovered lines: 0
Coverable lines: 11
Total lines: 50
Line coverage: 100%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%22100%
Create(...)87.5%88100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/85372080fe102cd9ee155ceab49ae000e7f66103/src/MyNet.UI/Toasting/DefaultToastFactory.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="DefaultToastFactory.cs" company="Stéphane ANDRE">
 3// Copyright (c) Stéphane ANDRE. All rights reserved.
 4// </copyright>
 5// -----------------------------------------------------------------------
 6
 7using System;
 8using MyNet.UI.Commands;
 9using MyNet.UI.Notifications.Models;
 10using MyNet.UI.Toasting.Models;
 11using MyNet.UI.Toasting.Settings;
 12
 13namespace MyNet.UI.Toasting;
 14
 15/// <summary>
 16/// Creates default toast instances from notifications.
 17/// </summary>
 18public sealed class DefaultToastFactory : IToastFactory
 19{
 20    private readonly ToastManagerOptions _options;
 21    private readonly ICommandFactory _commandFactory;
 22
 23    /// <summary>
 24    /// Initializes a new instance of the <see cref="DefaultToastFactory"/> class.
 25    /// </summary>
 26    /// <param name="options">Global toast defaults used when resolving settings.</param>
 27    /// <param name="commandFactory">Optional command factory for toast interaction commands.</param>
 28    public DefaultToastFactory(ToastManagerOptions? options = null, ICommandFactory? commandFactory = null)
 29    {
 2130        _options = options ?? new ToastManagerOptions();
 2131        _commandFactory = commandFactory.GetOrDefault();
 2132    }
 33
 34    /// <inheritdoc />
 35    public IToast Create(INotification notification)
 36    {
 1837        var settings = ToastSettingsMerger.Merge(notification, _options);
 38
 1839        var closeCommand = notification is IClosableNotification { IsClosable: true } closable
 1840            ? _commandFactory.Create((Action)(() => closable.RequestClose()))
 1841            : null;
 42
 1843        var clickCommand = notification is ActionNotification { Action: not null } actionNotification
 1844            ? _commandFactory.Create(() => actionNotification.Action(actionNotification))
 1845            : null;
 46
 1847        return new Toast(notification, settings, clickCommand: clickCommand, closeCommand: closeCommand);
 48    }
 49}
 50