< Summary

Information
Class: Renci.SshNet.ForwardedPortStatus
Assembly: Renci.SshNet
File(s): \home\appveyor\projects\ssh-net\src\Renci.SshNet\ForwardedPortStatus.cs
Line coverage
56%
Covered lines: 36
Uncovered lines: 28
Coverable lines: 64
Total lines: 148
Line coverage: 56.2%
Branch coverage
45%
Covered branches: 11
Total branches: 24
Branch coverage: 45.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity Line coverage
.cctor()100%1100%
.ctor(...)100%1100%
Equals(...)75%477.77%
op_Equality(...)50%266.66%
op_Inequality(...)100%10%
GetHashCode()100%10%
ToString()100%10%
ToStopping(...)33.33%1247.36%
ToStarting(...)50%658.33%

File(s)

\home\appveyor\projects\ssh-net\src\Renci.SshNet\ForwardedPortStatus.cs

#LineLine coverage
 1using System;
 2using System.Threading;
 3
 4namespace Renci.SshNet
 5{
 6    internal sealed class ForwardedPortStatus
 7    {
 48        public static readonly ForwardedPortStatus Stopped = new ForwardedPortStatus(1, "Stopped");
 49        public static readonly ForwardedPortStatus Stopping = new ForwardedPortStatus(2, "Stopping");
 410        public static readonly ForwardedPortStatus Started = new ForwardedPortStatus(3, "Started");
 411        public static readonly ForwardedPortStatus Starting = new ForwardedPortStatus(4, "Starting");
 12
 13        private readonly int _value;
 14        private readonly string _name;
 15
 1616        private ForwardedPortStatus(int value, string name)
 1617        {
 1618            _value = value;
 1619            _name = name;
 1620        }
 21
 22        public override bool Equals(object obj)
 587623        {
 587624            if (ReferenceEquals(this, obj))
 259925            {
 259926                return true;
 27            }
 28
 327729            if (obj is not ForwardedPortStatus forwardedPortStatus)
 030            {
 031                return false;
 32            }
 33
 327734            return forwardedPortStatus._value == _value;
 587635        }
 36
 37#pragma warning disable S3875 // "operator==" should not be overloaded on reference types
 38        public static bool operator ==(ForwardedPortStatus left, ForwardedPortStatus right)
 39#pragma warning restore S3875 // "operator==" should not be overloaded on reference types
 587640        {
 41            // check if lhs is null
 587642            if (left is null)
 043            {
 44                // check if both lhs and rhs are null
 045                return right is null;
 46            }
 47
 587648            return left.Equals(right);
 587649        }
 50
 51        public static bool operator !=(ForwardedPortStatus left, ForwardedPortStatus right)
 052        {
 053            return !(left==right);
 054        }
 55
 56        public override int GetHashCode()
 057        {
 058            return _value;
 059        }
 60
 61        public override string ToString()
 062        {
 063            return _name;
 064        }
 65
 66        /// <summary>
 67        /// Returns a value indicating whether <paramref name="status"/> has been changed to <see cref="Stopping"/>.
 68        /// </summary>
 69        /// <param name="status">The status to transition from.</param>
 70        /// <returns>
 71        /// <see langword="true"/> if <paramref name="status"/> has been changed to <see cref="Stopping"/>; otherwise, <
 72        /// </returns>
 73        /// <exception cref="InvalidOperationException">Cannot transition <paramref name="status"/> to <see cref="Stoppi
 74        /// <remarks>
 75        /// While a transition from <see cref="Stopped"/> to <see cref="Stopping"/> is not possible, this method will
 76        /// return <see langword="false"/> for any such attempts.  This is related to concurrency.
 77        /// </remarks>
 78        public static bool ToStopping(ref ForwardedPortStatus status)
 82979        {
 80            // attempt to transition from Started to Stopping
 82981            var previousStatus = Interlocked.CompareExchange(ref status, Stopping, Started);
 82982            if (previousStatus == Stopping || previousStatus == Stopped)
 30483            {
 84                // status is already Stopping or Stopped, so no transition to Stopping is necessary
 30485                return false;
 86            }
 87
 88            // we've successfully transitioned from Started to Stopping
 52589            if (status == Stopping)
 52590            {
 52591                return true;
 92            }
 93
 94            // attempt to transition from Starting to Stopping
 095            previousStatus = Interlocked.CompareExchange(ref status, Stopping, Starting);
 096            if (previousStatus == Stopping || previousStatus == Stopped)
 097            {
 98                // status is already Stopping or Stopped, so no transition to Stopping is necessary
 099                return false;
 100            }
 101
 102            // we've successfully transitioned from Starting to Stopping
 0103            if (status == Stopping)
 0104            {
 0105                return true;
 106            }
 107
 108            // there's no valid transition from status to Stopping
 0109            throw new InvalidOperationException(string.Format("Forwarded port cannot transition from '{0}' to '{1}'.",
 0110                                                              previousStatus,
 0111                                                              Stopping));
 829112        }
 113
 114        /// <summary>
 115        /// Returns a value indicating whether <paramref name="status"/> has been changed to <see cref="Starting"/>.
 116        /// </summary>
 117        /// <param name="status">The status to transition from.</param>
 118        /// <returns>
 119        /// <see langword="true"/> if <paramref name="status"/> has been changed to <see cref="Starting"/>; otherwise, <
 120        /// </returns>
 121        /// <exception cref="InvalidOperationException">Cannot transition <paramref name="status"/> to <see cref="Starti
 122        /// <remarks>
 123        /// While a transition from <see cref="Started"/> to <see cref="Starting"/> is not possible, this method will
 124        /// return <see langword="false"/> for any such attempts.  This is related to concurrency.
 125        /// </remarks>
 126        public static bool ToStarting(ref ForwardedPortStatus status)
 525127        {
 128            // attemp to transition from Stopped to Starting
 525129            var previousStatus = Interlocked.CompareExchange(ref status, Starting, Stopped);
 525130            if (previousStatus == Starting || previousStatus == Started)
 0131            {
 132                // port is already Starting or Started, so no transition to Starting is necessary
 0133                return false;
 134            }
 135
 136            // we've successfully transitioned from Stopped to Starting
 525137            if (status == Starting)
 525138            {
 525139                return true;
 140            }
 141
 142            // there's no valid transition from status to Starting
 0143            throw new InvalidOperationException(string.Format("Forwarded port cannot transition from '{0}' to '{1}'.",
 0144                                                              previousStatus,
 0145                                                              Starting));
 525146        }
 147    }
 148}