< Summary

Information
Class: Enjoy.Domain.Users.ValueObjects.Email
Assembly: Enjoy.Domain
File(s): D:\Dotnet\Propuesta-trabajo\Enjoy Project\EnjoyApp\Enjoy\src\Enjoy.Domain\Users\ValueObjects\Email.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Value()100%11100%
.ctor(...)100%11100%
Create(...)100%1010100%
ToString()100%11100%
op_Implicit(...)100%11100%

File(s)

D:\Dotnet\Propuesta-trabajo\Enjoy Project\EnjoyApp\Enjoy\src\Enjoy.Domain\Users\ValueObjects\Email.cs

#LineLine coverage
 1using System.Text.RegularExpressions;
 2using Enjoy.Domain.Shared.Errors;
 3using Enjoy.Domain.Shared.Extensions;
 4using Enjoy.Domain.Shared.Results;
 5
 6namespace Enjoy.Domain.Users.ValueObjects;
 7
 8public readonly record struct Email
 9{
 710    public string Value { get; }
 11
 12    public const int MinLength = 8;
 13    public const int MaxLength = 50;
 14
 15    public const string EmailPattern = @"^[^@]+@[^@]+$";
 16
 6017    private Email(string value)  => Value = value;
 18
 19    public static Result<Email> Create(string value)
 7320    {
 7321        if (string.IsNullOrWhiteSpace(value))
 722            return Result<Email>.Failure(Error.Email.IsNullOrEmpty);
 23
 6624        var normalized = value.Trim().ToLowerInvariant();
 6625        List<Error> errors = [];
 6626        if (normalized.Length < MinLength)
 227            errors.Add(Error.Email.TooShort(MinLength));
 6628        if (normalized.Length > MaxLength)
 129            errors.Add(Error.Email.TooLong(MaxLength));
 6630        if (!Regex.IsMatch(normalized, EmailPattern))
 431            errors.Add(Error.Email.InvalidFormat);
 32
 6633        return errors.IsEmpty()
 6634            ? Result<Email>.Success(new Email(normalized))
 6635            : Result<Email>.Failure(errors);
 7336    }
 37
 138    public override string ToString() => Value;
 39
 140    public static implicit operator string(Email email) => email.Value;
 41}