< Summary

Information
Class: MyNet.Fakers.Contacts.MailFaker
Assembly: MyNet.Fakers
File(s): https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Fakers/Contacts/MailFaker.cs
Tag: 342_31701152804
Line coverage
100%
Covered lines: 8
Uncovered lines: 0
Coverable lines: 8
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Email(...)100%66100%

File(s)

https://raw.githubusercontent.com/sandre58/MyNet/5aaaab311aa14541478b9e402357d98b657a23e4/src/MyNet.Fakers/Contacts/MailFaker.cs

#LineLine coverage
 1// -----------------------------------------------------------------------
 2// <copyright file="MailFaker.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.Fakers.Identity;
 10using MyNet.Fakers.Internet;
 11using MyNet.Generator;
 12
 13namespace MyNet.Fakers.Contacts;
 14
 15/// <summary>
 16/// Current implementation of <see cref="IMailFaker"/>.
 17/// </summary>
 18/// <param name="random">The random generator.</param>
 19/// <param name="identity">The identity faker.</param>
 20/// <param name="domainFaker">The domain faker.</param>
 21public sealed class MailFaker(IRandomGenerator random, IIdentityFaker identity, IDomainFaker domainFaker) : IMailFaker
 22{
 23    /// <inheritdoc />
 24    public string Email(string? host = null, CultureInfo? culture = null)
 25    {
 1226        if (host is null)
 27        {
 928            host = domainFaker.Host(culture);
 29
 930            if (string.IsNullOrWhiteSpace(host))
 331                host = $"example{random.Int(1, 999)}.com";
 632            else if (!host.Contains('.', StringComparison.Ordinal))
 333                host = $"{host}.{domainFaker.Domain(culture)}";
 34        }
 35
 1236        var user = identity.Username();
 37
 1238        return $"{user}@{host}";
 39    }
 40}
 41