| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="MailFaker.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Globalization; |
| | | 9 | | using MyNet.Fakers.Identity; |
| | | 10 | | using MyNet.Fakers.Internet; |
| | | 11 | | using MyNet.Generator; |
| | | 12 | | |
| | | 13 | | namespace 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> |
| | | 21 | | public sealed class MailFaker(IRandomGenerator random, IIdentityFaker identity, IDomainFaker domainFaker) : IMailFaker |
| | | 22 | | { |
| | | 23 | | /// <inheritdoc /> |
| | | 24 | | public string Email(string? host = null, CultureInfo? culture = null) |
| | | 25 | | { |
| | 12 | 26 | | if (host is null) |
| | | 27 | | { |
| | 9 | 28 | | host = domainFaker.Host(culture); |
| | | 29 | | |
| | 9 | 30 | | if (string.IsNullOrWhiteSpace(host)) |
| | 3 | 31 | | host = $"example{random.Int(1, 999)}.com"; |
| | 6 | 32 | | else if (!host.Contains('.', StringComparison.Ordinal)) |
| | 3 | 33 | | host = $"{host}.{domainFaker.Domain(culture)}"; |
| | | 34 | | } |
| | | 35 | | |
| | 12 | 36 | | var user = identity.Username(); |
| | | 37 | | |
| | 12 | 38 | | return $"{user}@{host}"; |
| | | 39 | | } |
| | | 40 | | } |
| | | 41 | | |