< Summary

Information
Class: Enjoy.Domain.Users.ValueObjects.Name
Assembly: Enjoy.Domain
File(s): D:\Dotnet\Propuesta-trabajo\Enjoy Project\EnjoyApp\Enjoy\src\Enjoy.Domain\Users\ValueObjects\Name.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\Name.cs

#LineLine coverage
 1using Enjoy.Domain.Shared.Errors;
 2using Enjoy.Domain.Shared.Extensions;
 3using Enjoy.Domain.Shared.Results;
 4using System.Text.RegularExpressions;
 5
 6namespace Enjoy.Domain.Users.ValueObjects;
 7
 8public readonly record struct Name
 9{
 710    public string Value { get; }
 11
 12    public const int MinLength = 2;
 13    public const int MaxLength = 50;
 14
 15    public const string Pattern = @"^[a-zA-ZáéíóúÁÉÍÓÚñÑçÇüÜàÀèÈìÌòÒùÙâêÊîôûäëïöüß\s]+$";
 16
 6317    private Name(string value) => Value = value;
 18
 19    public static Result<Name> Create(string value)
 7720    {
 7721        if (string.IsNullOrWhiteSpace(value))
 822            return Result<Name>.Failure(Error.Name.IsNullOrEmpty);
 23
 6924        var normalized = value.Trim().CapitalizeWords();
 6925        List<Error> errors = [];
 6926        if (normalized.Length < MinLength)
 227            errors.Add(Error.Name.TooShort(MinLength));
 6928        if (normalized.Length > MaxLength)
 129            errors.Add(Error.Name.TooLong(MaxLength));
 6930        if (!Regex.IsMatch(normalized, Pattern))
 431            errors.Add(Error.Name.InvalidFormat);
 32
 6933        return errors.IsEmpty()
 6934            ? Result<Name>.Success(new(normalized))
 6935            : Result<Name>.Failure(errors);
 7736    }
 37
 138    public override string ToString() => Value;
 39
 140    public static implicit operator string(Name name) => name.Value;
 41}