< Summary - Syki

Information
Class: Syki.Back.Commands.CommandInvoker<T>
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Commands/ICommandHandler.cs
Tag: 56_26538939494
Line coverage
90%
Covered lines: 9
Uncovered lines: 1
Coverable lines: 10
Total lines: 36
Line coverage: 90%
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
.cctor()100%11100%
Invoke()100%11100%
Deserialize(...)100%210%

File(s)

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

#LineLine coverage
 1using System.Text.Json;
 2using Syki.Back.Converters;
 3
 4namespace Syki.Back.Commands;
 5
 6public interface ICommandHandler<T> where T : ICommand
 7{
 8    Task Handle(int commandId, T command);
 9}
 10
 11public interface ICommandInvoker
 12{
 13    Task Invoke(IServiceProvider sp, int commandId, string json);
 14    object Deserialize(string json);
 15}
 16
 17public class CommandInvoker<T> : ICommandInvoker where T : ICommand
 18{
 419    private static readonly JsonSerializerOptions _options = new()
 420    {
 421        PropertyNameCaseInsensitive = true,
 422        Converters = { new SykiStringEnumConverter() },
 423    };
 24
 25    public async Task Invoke(IServiceProvider sp, int commandId, string json)
 26    {
 30427        var data = JsonSerializer.Deserialize<T>(json, _options)!;
 30428        var handler = sp.GetRequiredService<ICommandHandler<T>>();
 30429        await handler.Handle(commandId, data);
 30430    }
 31
 32    public object Deserialize(string json)
 33    {
 034        return JsonSerializer.Deserialize<T>(json, _options)!;
 35    }
 36}