< Summary - Syki

Information
Class: Syki.Back.Commands.Command
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Commands/Command.cs
Tag: 4_16869239191
Line coverage
93%
Covered lines: 44
Uncovered lines: 3
Coverable lines: 47
Total lines: 110
Line coverage: 93.6%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Id()100%11100%
get_InstitutionId()100%11100%
get_Type()100%11100%
get_Data()100%11100%
get_Status()100%11100%
get_CreatedAt()100%11100%
get_Duration()100%11100%
get_ProcessedAt()100%11100%
get_ProcessorId()100%210%
get_Error()100%11100%
get_EventId()100%11100%
get_ParentId()100%11100%
get_OriginalId()100%11100%
get_BatchId()100%11100%
get_NotBefore()100%11100%
get_ActivityId()100%11100%
.ctor()100%11100%
.ctor(...)50%22100%
SetAwaiting()100%210%
Processed(...)50%22100%
GetParentContext()100%11100%

File(s)

/home/runner/work/syki/syki/Back/Commands/Command.cs

#LineLine coverage
 1using StronglyTypedIds;
 2using System.Diagnostics;
 3
 4namespace Syki.Back.Commands;
 5
 6public class Command
 7{
 53768    public CommandId Id { get; set; }
 26889    public Guid InstitutionId { get; set; }
 1612810    public string Type { get; set; }
 537611    public string Data { get; set; }
 268812    public CommandStatus Status { get; set; }
 268813    public DateTime CreatedAt { get; set; }
 268814    public int Duration { get; set; }
 268815    public DateTime? ProcessedAt { get; set; }
 016    public Guid? ProcessorId { get; set; }
 268817    public string? Error { get; set; }
 18
 19    /// <summary>
 20    /// Id do evento que gerou o comando
 21    /// </summary>
 268822    public DomainEventId? EventId { get; set; }
 23
 24    /// <summary>
 25    /// Id do comando que gerou o comando
 26    /// Utilizado quando um comando gera outro em seu handler
 27    /// </summary>
 268828    public CommandId? ParentId { get; set; }
 29
 30    /// <summary>
 31    /// Id do comando com erro que gerou o comando atual
 32    /// Utilizado quando o comando original está com erro e é reprocessado
 33    /// O comando atual é uma cópia do original (imutabilidade)
 34    /// </summary>
 268835    public CommandId? OriginalId { get; set; }
 36
 37    /// <summary>
 38    /// Id do lote que contém o comando
 39    /// </summary>
 268840    public CommandBatchId? BatchId { get; set; }
 41
 537642    public DateTime? NotBefore { get; set; }
 43
 537644    public string? ActivityId { get; set; }
 45
 537646    public Command() { }
 47
 268848    public Command(
 268849        Guid institutionId,
 268850        object data,
 268851        DomainEventId? eventId = null,
 268852        CommandId? parentId = null,
 268853        CommandId? originalId = null,
 268854        CommandBatchId? batchId = null,
 268855        int? delaySeconds = null,
 268856        string? activityId = null
 268857    ) {
 268858        Id = CommandId.CreateNew();
 268859        InstitutionId = institutionId;
 268860        Type = data.GetType().ToString();
 268861        Data = data.Serialize();
 268862        CreatedAt = DateTime.UtcNow;
 268863        EventId = eventId;
 268864        ParentId = parentId;
 268865        OriginalId = originalId;
 268866        BatchId = batchId;
 268867        ActivityId = activityId;
 268868        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 268869    }
 70
 71    public void SetAwaiting()
 72    {
 073        Status = CommandStatus.Awaiting;
 074    }
 75
 76    public void Processed(double duration)
 77    {
 268878        ProcessedAt = DateTime.UtcNow;
 268879        Duration = Convert.ToInt32(duration);
 268880        Status = Error.HasValue() ? CommandStatus.Error : CommandStatus.Success;
 268881    }
 82
 83    public ActivityContext GetParentContext()
 84    {
 268885        ActivityContext.TryParse(ActivityId, null, out var parsedContext);
 268886        return parsedContext;
 87    }
 88}
 89
 90[StronglyTypedId]
 91public partial struct CommandId
 92{
 93    public static CommandId CreateNew()
 94    {
 95        return new CommandId(Guid.CreateVersion7());
 96    }
 97
 98    public class CommandIdEfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<Co
 99    {
 100        public CommandIdEfCoreValueConverter() : this(null) { }
 101
 102        public CommandIdEfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints
 103            : base(
 104                id => id.Value,
 105                value => new CommandId(value),
 106                mappingHints
 107            )
 108        { }
 109    }
 110}