< Summary

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

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Name()100%210%
get_Secret()100%210%
get_IsThirdParty()100%210%
Validate()0%7280%

File(s)

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

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using LGDXRobotCloud.Data.Models.Business.Administration;
 3
 4namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 5
 6public record ApiKeyCreateDto
 7{
 8  [Required (ErrorMessage = "Please enter a name.")]
 9  [MaxLength(50)]
 010  public required string Name { get; set; }
 11
 12  [MaxLength(200)]
 013  public string? Secret { get; set; }
 14
 15  [Required]
 016  public required bool IsThirdParty { get; set; }
 17
 18  public virtual IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 019  {
 020    if (IsThirdParty && string.IsNullOrWhiteSpace(Secret))
 021    {
 022      yield return new ValidationResult("Secret is required for Third-Party API Key.", [nameof(Secret)]);
 023    }
 024    if (!IsThirdParty && !string.IsNullOrWhiteSpace(Secret))
 025    {
 026      yield return new ValidationResult("LGDXRobot Cloud API Keys will be generated automatically.", [nameof(Secret)]);
 027    }
 028  }
 29}
 30
 31public static class ApiKeyCreateDtoExtensions
 32{
 33  public static ApiKeyCreateBusinessModel ToBusinessModel(this ApiKeyCreateDto apiKey)
 34  {
 35    return new ApiKeyCreateBusinessModel{
 36      Name = apiKey.Name,
 37      Secret = apiKey.Secret,
 38      IsThirdParty = apiKey.IsThirdParty
 39    };
 40  }
 41}