Summary

Class:WireMock.Http.PortUtil
Assembly:WireMock.Net
File(s):C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Http\PortUtil.cs
Covered lines:10
Uncovered lines:0
Coverable lines:10
Total lines:34
Line coverage:100%
Branch coverage:50%

Metrics

MethodCyclomatic complexity  NPath complexity  Sequence coverage  Branch coverage  
FindFreeTcpPort()2210066.67

File(s)

C:\Users\Stef\Documents\GitHub\WireMock.Net\src\WireMock.Net\Http\PortUtil.cs

#LineLine coverage
 1using System.Net;
 2using System.Net.Sockets;
 3
 4namespace WireMock.Http
 5{
 6    /// <summary>
 7    /// The ports.
 8    /// </summary>
 9    public static class PortUtil
 10    {
 11        /// <summary>
 12        /// The find free TCP port.
 13        /// </summary>
 14        /// <returns>
 15        /// The <see cref="int"/>.
 16        /// </returns>
 17        /// <remarks>see http://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net.</remarks>
 18        public static int FindFreeTcpPort()
 1619        {
 1620            TcpListener tcpListener = null;
 21            try
 1622            {
 1623                tcpListener = new TcpListener(IPAddress.Loopback, 0);
 1624                tcpListener.Start();
 25
 1626                return ((IPEndPoint)tcpListener.LocalEndpoint).Port;
 27            }
 28            finally
 1629            {
 1630                 tcpListener?.Stop();
 1631            }
 1632        }
 33    }
 34}

Methods/Properties

FindFreeTcpPort()