public void CreateChannelUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var udpChan = new SIPUDPChannel(IPAddress.Any, 0);

            logger.LogDebug($"Listening end point {udpChan.ListeningSIPEndPoint}.");

            udpChan.Close();

            logger.LogDebug("-----------------------------------------");
        }
        public async void InterChannelCommsUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var udpChan1 = new SIPUDPChannel(IPAddress.Any, 0);

            logger.LogDebug($"Listening end point {udpChan1.ListeningSIPEndPoint}.");
            var udpChan2 = new SIPUDPChannel(IPAddress.Any, 0);

            logger.LogDebug($"Listening end point {udpChan2.ListeningSIPEndPoint}.");

            TaskCompletionSource <bool> gotMessage = new TaskCompletionSource <bool>();
            SIPEndPoint receivedFromEP             = null;
            SIPEndPoint receivedOnEP = null;

            udpChan2.SIPMessageReceived = (SIPChannel sipChannel, SIPEndPoint localSIPEndPoint, SIPEndPoint remoteEndPoint, byte[] buffer) =>
            {
                logger.LogDebug($"SIP message received from {remoteEndPoint}.");
                logger.LogDebug($"SIP message received on {localSIPEndPoint}.");
                logger.LogDebug(Encoding.UTF8.GetString(buffer));

                receivedFromEP = remoteEndPoint;
                receivedOnEP   = localSIPEndPoint;
                gotMessage.SetResult(true);
                return(Task.CompletedTask);
            };

            var dstEndPoint = new SIPEndPoint(SIPProtocolsEnum.udp, IPAddress.Loopback, udpChan2.Port);
            var optionsReq  = SIPRequest.GetRequest(SIPMethodsEnum.OPTIONS, new SIPURI(SIPSchemesEnum.sip, dstEndPoint));

            logger.LogDebug($"Attempting to send OPTIONS request to {dstEndPoint}.");

            // Give sockets a chance to start up.
            //await Task.Delay(500);

            await udpChan1.SendAsync(dstEndPoint, Encoding.UTF8.GetBytes(optionsReq.ToString()), null);

            bool res = gotMessage.Task.Wait(1000);

            Assert.True(res);
            Assert.NotNull(receivedFromEP);
            Assert.NotNull(receivedOnEP);
            Assert.Equal(IPAddress.Loopback, receivedFromEP.Address);
            Assert.Equal(IPAddress.Any, receivedOnEP.Address);

            udpChan1.Close();
            udpChan2.Close();

            logger.LogDebug("-----------------------------------------");
        }
        public void GetDefaultContactURIUnitTest()
        {
            logger.LogDebug("--> " + System.Reflection.MethodBase.GetCurrentMethod().Name);
            logger.BeginScope(System.Reflection.MethodBase.GetCurrentMethod().Name);

            var udpChan = new SIPUDPChannel(IPAddress.Any, 0);

            logger.LogDebug($"Listening end point {udpChan.ListeningSIPEndPoint}.");

            var contactURI = udpChan.GetContactURI(SIPSchemesEnum.sip, new SIPEndPoint(udpChan.SIPProtocol, SIPChannel.InternetDefaultAddress, 0));

            Assert.NotNull(contactURI);

            logger.LogDebug($"Contact URI: {contactURI}.");

            udpChan.Close();

            logger.LogDebug("-----------------------------------------");
        }