< Summary

Information
Class: LGDXRobotCloud.Data.Models.DTOs.V1.Commands.LgdxRoleCreateDtoExtensions
Assembly: LGDXRobotCloud.Data
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/Models/DTOs/V1/Commands/LgdxRoleCreateDto.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 8
Coverable lines: 8
Total lines: 40
Line coverage: 0%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
ToBusinessModel(...)100%210%

File(s)

/builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/Models/DTOs/V1/Commands/LgdxRoleCreateDto.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using LGDXRobotCloud.Data.Models.Business.Administration;
 3
 4namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 5
 6public record LgdxRoleCreateDto : IValidatableObject
 7{
 8  [Required (ErrorMessage = "Please enter a name.")]
 9  public required string Name { get; set; }
 10
 11  public string? Description { get; set; }
 12
 13  public IEnumerable<string> Scopes { get; set; } = []; // Empty scope is allowed
 14
 15  public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 16  {
 17    int i = 0;
 18    foreach (var scope in Scopes)
 19    {
 20      if (string.IsNullOrWhiteSpace(scope))
 21      {
 22        yield return new ValidationResult($"Scope is required.", [nameof(Scopes), $"{nameof(Scopes)}-{i}"]);
 23      }
 24      i++;
 25    }
 26  }
 27}
 28
 29public static class LgdxRoleCreateDtoExtensions
 30{
 31  public static LgdxRoleCreateBusinessModel ToBusinessModel(this LgdxRoleCreateDto model)
 032  {
 033    return new LgdxRoleCreateBusinessModel
 034    {
 035      Name = model.Name,
 036      Description = model.Description,
 037      Scopes = model.Scopes,
 038    };
 039  }
 40}