< Summary

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

#LineLine coverage
 1using System.ComponentModel.DataAnnotations;
 2using LGDXRobotCloud.Data.Models.Business.Automation;
 3
 4namespace LGDXRobotCloud.Data.Models.DTOs.V1.Commands;
 5
 6public record TriggerUpdateDto : IValidatableObject
 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
 21  public int? ApiKeyInsertLocationId { get; set; }
 22
 23  [MaxLength(50)]
 24  public string? ApiKeyFieldName { get; set; }
 25
 26  public int? ApiKeyId { get; set; }
 27
 28  public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
 29  {
 30    if (!(ApiKeyInsertLocationId == null && string.IsNullOrWhiteSpace(ApiKeyFieldName) && ApiKeyId == null))
 31    {
 32      if (ApiKeyInsertLocationId == null)
 33      {
 34        yield return new ValidationResult("Please select an insert location.", [nameof(ApiKeyInsertLocationId)]);
 35      }
 36      if (ApiKeyFieldName == null)
 37      {
 38        yield return new ValidationResult("Please enter a field name.", [nameof(ApiKeyFieldName)]);
 39      }
 40      if (ApiKeyId == null)
 41      {
 42        yield return new ValidationResult("Please select an API Key.", [nameof(ApiKeyId)]);
 43      }
 44    }
 45  }
 46}
 47
 48public static class TriggerUpdateDtoExtensions
 49{
 50  public static TriggerUpdateBusinessModel ToBusinessModel(this TriggerUpdateDto triggerUpdateDto)
 051  {
 052    return new TriggerUpdateBusinessModel {
 053      Name = triggerUpdateDto.Name,
 054      Url = triggerUpdateDto.Url,
 055      HttpMethodId = triggerUpdateDto.HttpMethodId,
 056      Body = triggerUpdateDto.Body,
 057      ApiKeyInsertLocationId = triggerUpdateDto.ApiKeyInsertLocationId,
 058      ApiKeyFieldName = triggerUpdateDto.ApiKeyFieldName,
 059      ApiKeyId = triggerUpdateDto.ApiKeyId,
 060    };
 061  }
 62}