< Summary - Syki

Line coverage
23%
Covered lines: 15
Uncovered lines: 49
Coverable lines: 64
Total lines: 339
Line coverage: 23.4%
Branch coverage
8%
Covered branches: 3
Total branches: 34
Branch coverage: 8.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

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{
 8    public CommandId Id { get; set; }
 9    public Guid InstitutionId { get; set; }
 10    public string Type { get; set; }
 11    public string Data { get; set; }
 12    public CommandStatus Status { get; set; }
 13    public DateTime CreatedAt { get; set; }
 14    public int Duration { get; set; }
 15    public DateTime? ProcessedAt { get; set; }
 16    public Guid? ProcessorId { get; set; }
 17    public string? Error { get; set; }
 18
 19    /// <summary>
 20    /// Id do evento que gerou o comando
 21    /// </summary>
 22    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>
 28    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>
 35    public CommandId? OriginalId { get; set; }
 36
 37    /// <summary>
 38    /// Id do lote que contém o comando
 39    /// </summary>
 40    public CommandBatchId? BatchId { get; set; }
 41
 42    public DateTime? NotBefore { get; set; }
 43
 44    public string? ActivityId { get; set; }
 45
 46    public Command() { }
 47
 48    public Command(
 49        Guid institutionId,
 50        object data,
 51        DomainEventId? eventId = null,
 52        CommandId? parentId = null,
 53        CommandId? originalId = null,
 54        CommandBatchId? batchId = null,
 55        int? delaySeconds = null,
 56        string? activityId = null
 57    ) {
 58        Id = CommandId.CreateNew();
 59        InstitutionId = institutionId;
 60        Type = data.GetType().ToString();
 61        Data = data.Serialize();
 62        CreatedAt = DateTime.UtcNow;
 63        EventId = eventId;
 64        ParentId = parentId;
 65        OriginalId = originalId;
 66        BatchId = batchId;
 67        ActivityId = activityId;
 68        NotBefore = delaySeconds != null ? DateTime.UtcNow.AddSeconds(delaySeconds.Value) : null;
 69    }
 70
 71    public void SetAwaiting()
 72    {
 73        Status = CommandStatus.Awaiting;
 74    }
 75
 76    public void Processed(double duration)
 77    {
 78        ProcessedAt = DateTime.UtcNow;
 79        Duration = Convert.ToInt32(duration);
 80        Status = Error.HasValue() ? CommandStatus.Error : CommandStatus.Success;
 81    }
 82
 83    public ActivityContext GetParentContext()
 84    {
 85        ActivityContext.TryParse(ActivityId, null, out var parsedContext);
 86        return parsedContext;
 87    }
 88}
 89
 90[StronglyTypedId]
 91public partial struct CommandId
 92{
 93    public static CommandId CreateNew()
 94    {
 268895        return new CommandId(Guid.CreateVersion7());
 96    }
 97
 98    public class CommandIdEfCoreValueConverter : Microsoft.EntityFrameworkCore.Storage.ValueConversion.ValueConverter<Co
 99    {
 20100        public CommandIdEfCoreValueConverter() : this(null) { }
 101
 102        public CommandIdEfCoreValueConverter(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints
 10103            : base(
 10104                id => id.Value,
 10105                value => new CommandId(value),
 10106                mappingHints
 10107            )
 10108        { }
 109    }
 110}

/home/runner/work/syki/syki/Back/obj/Release/net10.0/StronglyTypedIds/StronglyTypedIds.StronglyTypedIdGenerator/Syki.Back.Commands.CommandId.g.cs

File '/home/runner/work/syki/syki/Back/obj/Release/net10.0/StronglyTypedIds/StronglyTypedIds.StronglyTypedIdGenerator/Syki.Back.Commands.CommandId.g.cs' does not exist (any more).

Methods/Properties

CreateNew()
.ctor()
.ctor(Microsoft.EntityFrameworkCore.Storage.ValueConversion.ConverterMappingHints)
get_Value()
.ctor(System.Guid)
New()
.cctor()
Equals(Syki.Back.Commands.CommandId)
Equals(System.Object)
GetHashCode()
ToString()
op_Equality(Syki.Back.Commands.CommandId,Syki.Back.Commands.CommandId)
op_Inequality(Syki.Back.Commands.CommandId,Syki.Back.Commands.CommandId)
op_GreaterThan(Syki.Back.Commands.CommandId,Syki.Back.Commands.CommandId)
op_LessThan(Syki.Back.Commands.CommandId,Syki.Back.Commands.CommandId)
op_GreaterThanOrEqual(Syki.Back.Commands.CommandId,Syki.Back.Commands.CommandId)
op_LessThanOrEqual(Syki.Back.Commands.CommandId,Syki.Back.Commands.CommandId)
CompareTo(Syki.Back.Commands.CommandId)
CanConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Type)
ConvertFrom(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object)
CanConvertTo(System.ComponentModel.ITypeDescriptorContext,System.Type)
ConvertTo(System.ComponentModel.ITypeDescriptorContext,System.Globalization.CultureInfo,System.Object,System.Type)
Read(System.Text.Json.Utf8JsonReader&,System.Type,System.Text.Json.JsonSerializerOptions)
Write(System.Text.Json.Utf8JsonWriter,Syki.Back.Commands.CommandId,System.Text.Json.JsonSerializerOptions)
ReadAsPropertyName(System.Text.Json.Utf8JsonReader&,System.Type,System.Text.Json.JsonSerializerOptions)
WriteAsPropertyName(System.Text.Json.Utf8JsonWriter,Syki.Back.Commands.CommandId,System.Text.Json.JsonSerializerOptions)
Parse(System.String)
Parse(System.String,System.IFormatProvider)
TryParse(System.String,System.IFormatProvider,Syki.Back.Commands.CommandId&)
ToString(System.String,System.IFormatProvider)
Parse(System.ReadOnlySpan`1<System.Char>)
Parse(System.ReadOnlySpan`1<System.Char>,System.IFormatProvider)
TryParse(System.ReadOnlySpan`1<System.Char>,System.IFormatProvider,Syki.Back.Commands.CommandId&)
TryFormat(System.Span`1<System.Char>,System.Int32&,System.ReadOnlySpan`1<System.Char>,System.IFormatProvider)
TryFormat(System.Span`1<System.Char>,System.Int32&,System.ReadOnlySpan`1<System.Char>)
TryFormat(System.Span`1<System.Byte>,System.Int32&,System.ReadOnlySpan`1<System.Char>,System.IFormatProvider)