< Summary

Information
Class: Elsa.Workflows.Runtime.Comparers.WorkflowTriggerEqualityComparer
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Comparers/WorkflowTriggerEqualityComparer.cs
Line coverage
100%
Covered lines: 24
Uncovered lines: 0
Coverable lines: 24
Total lines: 58
Line coverage: 100%
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
.ctor()100%11100%
Equals(...)50%44100%
GetHashCode(...)100%11100%
Serialize(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Comparers/WorkflowTriggerEqualityComparer.cs

#LineLine coverage
 1using System.Text.Json;
 2using Elsa.Expressions.Services;
 3using Elsa.Workflows.Runtime.Entities;
 4using Elsa.Workflows.Serialization.Converters;
 5
 6namespace Elsa.Workflows.Runtime.Comparers;
 7
 8/// <summary>
 9/// Compares two <see cref="StoredTrigger"/> instances for equality.
 10/// </summary>
 11public class WorkflowTriggerEqualityComparer : IEqualityComparer<StoredTrigger>
 12{
 13    private readonly JsonSerializerOptions _settings;
 14
 15    /// <summary>
 16    /// Initializes a new instance of the <see cref="WorkflowTriggerEqualityComparer"/> class.
 17    /// </summary>
 64018    public WorkflowTriggerEqualityComparer()
 19    {
 64020        _settings = new JsonSerializerOptions
 64021        {
 64022            // Enables serialization of ValueTuples, which use fields instead of properties.
 64023            IncludeFields = true,
 64024            PropertyNameCaseInsensitive = true
 64025        };
 26
 64027        _settings.Converters.Add(new TypeJsonConverter(WellKnownTypeRegistry.CreateDefault()));
 64028    }
 29
 30    /// <inheritdoc />
 31    public bool Equals(StoredTrigger? x, StoredTrigger? y)
 32    {
 15033        var xJson = x != null ? Serialize(x) : null;
 15034        var yJson = y != null ? Serialize(y) : null;
 15035        return xJson == yJson;
 36    }
 37
 38    /// <inheritdoc />
 39    public int GetHashCode(StoredTrigger obj)
 40    {
 37541        var json = Serialize(obj);
 37542        return json.GetHashCode();
 43    }
 44
 45    private string Serialize(StoredTrigger storedTrigger)
 46    {
 67547        var input = new
 67548        {
 67549            storedTrigger.Payload,
 67550            storedTrigger.Name,
 67551            storedTrigger.ActivityId,
 67552            storedTrigger.WorkflowDefinitionId,
 67553            storedTrigger.WorkflowDefinitionVersionId,
 67554            storedTrigger.Hash
 67555        };
 67556        return JsonSerializer.Serialize(input, _settings);
 57    }
 58}