< Summary

Information
Class: Elsa.Workflows.Activities.Flowchart.Models.Connection
Assembly: Elsa.Workflows.Core
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/Connection.cs
Line coverage
95%
Covered lines: 20
Uncovered lines: 1
Coverable lines: 21
Total lines: 85
Line coverage: 95.2%
Branch coverage
71%
Covered branches: 10
Total branches: 14
Branch coverage: 71.4%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
.ctor(...)100%11100%
.ctor(...)100%11100%
get_Source()100%11100%
get_Target()100%11100%
get_Vertices()100%11100%
ToString()75%44100%
Equals(...)75%44100%
Equals(...)0%620%
GetHashCode()100%11100%
AreEndpointsEqual(...)100%22100%
GetEndpointHashCode(...)100%22100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Core/Activities/Flowchart/Models/Connection.cs

#LineLine coverage
 1using System.Text.Json.Serialization;
 2
 3namespace Elsa.Workflows.Activities.Flowchart.Models;
 4
 5/// <summary>
 6/// A connection between a source and a target endpoint.
 7/// </summary>
 8public class Connection : IEquatable<Connection>
 9{
 10    /// <summary>
 11    /// Initializes a new instance of the <see cref="Connection"/> class.
 12    /// </summary>
 13    [JsonConstructor]
 16414    public Connection()
 15    {
 16416    }
 17
 18    /// <summary>
 19    /// Initializes a new instance of the <see cref="Connection"/> class.
 20    /// </summary>
 21    /// <param name="source">The source endpoint.</param>
 22    /// <param name="target">The target endpoint.</param>
 57223    public Connection(Endpoint source, Endpoint target)
 24    {
 57225        Source = source;
 57226        Target = target;
 57227    }
 28
 29    /// <summary>
 30    /// Initializes a new instance of the <see cref="Connection"/> class.
 31    /// </summary>
 32    /// <param name="source">The source endpoint.</param>
 33    /// <param name="target">The target endpoint.</param>
 12834    public Connection(IActivity source, IActivity target)
 35    {
 12836        Source = new(source);
 12837        Target = new(target);
 12838    }
 39
 40    /// <summary>
 41    /// The source endpoint.
 42    /// </summary>
 1678843    public Endpoint Source { get; set; } = null!;
 44
 45    /// <summary>
 46    /// The target endpoint.
 47    /// </summary>
 1355448    public Endpoint Target { get; set; } = null!;
 49
 50    /// <summary>
 51    /// A collection of points representing the vertices of the connection.
 52    /// </summary>
 149553    public ICollection<Position> Vertices { get; set; } = [];
 54
 55    public override string ToString() =>
 71556        $"{Source.Activity.Id}{(string.IsNullOrEmpty(Source.Port) ? "" : $":{Source.Port}")}->" +
 71557        $"{Target.Activity.Id}{(string.IsNullOrEmpty(Target.Port) ? "" : $":{Target.Port}")}";
 58
 59    // Implement equality logic
 60    public bool Equals(Connection? other)
 61    {
 14362        if (other == null) return false;
 14363        return AreEndpointsEqual(Source, other.Source) && AreEndpointsEqual(Target, other.Target);
 64    }
 65
 66    public override bool Equals(object? obj)
 67    {
 068        return obj is Connection other && Equals(other);
 69    }
 70
 71    public override int GetHashCode()
 72    {
 211073        return HashCode.Combine(GetEndpointHashCode(Source), GetEndpointHashCode(Target));
 74    }
 75
 76    private static bool AreEndpointsEqual(Endpoint e1, Endpoint e2)
 77    {
 27078        return e1.Activity.Equals(e2.Activity) && e1.Port == e2.Port;
 79    }
 80
 81    private static int GetEndpointHashCode(Endpoint endpoint)
 82    {
 422083        return HashCode.Combine(endpoint.Activity.GetHashCode(), endpoint.Port?.GetHashCode() ?? 0);
 84    }
 85}