< Summary

Information
Class: LGDXRobotCloud.Data.Models.DTOs.V1.Commands.TriggerCreateDtoExtensions
Assembly: LGDXRobotCloud.Data
File(s): /builds/yukaitung/lgdxrobot2-cloud/LGDXRobotCloud.Data/Models/DTOs/V1/Commands/TriggerCreateDto.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 12
Coverable lines: 12
Total lines: 64
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/TriggerCreateDto.cs

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using LGDXRobotCloud.Data.Models.Business.Automation;
 3
 4namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 5
 6public record TriggerCreateDto
 7{
 8  [Required (ErrorMessage = "Please enter a name.")]
 9  [MaxLength(50)]
 10  public required string Name { get; set; }
 11
 12  [Required (ErrorMessage = "Please enter an URL.")]
 13  [MaxLength(200)]
 14  public required string Url { get; set; }
 15
 16  public required int HttpMethodId { get; set; }
 17
 18  public string? Body { get; set; }
 19
 20  public required bool SkipOnFailure { get; set; } = false;
 21
 22  public int? ApiKeyInsertLocationId { get; set; }
 23
 24  [MaxLength(50)]
 25  public string? ApiKeyFieldName { get; set; }
 26
 27  public int? ApiKeyId { get; set; }
 28
 29  public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 30  {
 31    if (!(ApiKeyInsertLocationId != null && ApiKeyFieldName != null && ApiKeyId != null))
 32    {
 33      if (ApiKeyInsertLocationId == null)
 34      {
 35        yield return new ValidationResult("Please select an insert location.", [nameof(ApiKeyInsertLocationId)]);
 36      }
 37      if (ApiKeyFieldName == null)
 38      {
 39        yield return new ValidationResult("Please enter a field name.", [nameof(ApiKeyFieldName)]);
 40      }
 41      if (ApiKeyId == null)
 42      {
 43        yield return new ValidationResult("Please select an API Key.", [nameof(ApiKeyId)]);
 44      }
 45    }
 46  }
 47}
 48
 49public static class TriggerCreateDtoExtensions
 50{
 51  public static TriggerCreateBusinessModel ToBusinessModel(this TriggerCreateDto triggerCreateDto)
 052  {
 053    return new TriggerCreateBusinessModel {
 054      Name = triggerCreateDto.Name,
 055      Url = triggerCreateDto.Url,
 056      HttpMethodId = triggerCreateDto.HttpMethodId,
 057      Body = triggerCreateDto.Body,
 058      SkipOnFailure = triggerCreateDto.SkipOnFailure,
 059      ApiKeyInsertLocationId = triggerCreateDto.ApiKeyInsertLocationId,
 060      ApiKeyFieldName = triggerCreateDto.ApiKeyFieldName,
 061      ApiKeyId = triggerCreateDto.ApiKeyId,
 062    };
 063  }
 64}