コード例 #1
0
        public void TestCompletelyEmptyString()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse("");

            Assert.AreEqual("", e.HostName);
            Assert.AreEqual(Protocols.DefaultProtocol.DefaultPort, e.Port);
        }
コード例 #2
0
        public void TestEmptyHostWithPort()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse(":1234");

            Assert.AreEqual("", e.HostName);
            Assert.AreEqual(1234, e.Port);
        }
コード例 #3
0
        public void TestEmptyHostWithoutPort()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse(":");

            Assert.AreEqual("", e.HostName);
            Assert.AreEqual(Protocols.DefaultProtocol.DefaultPort, e.Port);
        }
コード例 #4
0
        public void TestIpv6WithPort()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse("[::1]:1234");

            Assert.AreEqual("::1", e.HostName);
            Assert.AreEqual(1234, e.Port);
        }
コード例 #5
0
        public void TestIpv6WithoutPort()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse("[::1]");

            Assert.AreEqual("::1", e.HostName);
            Assert.AreEqual(Protocols.DefaultProtocol.DefaultPort, e.Port);
        }
コード例 #6
0
        public void TestHostWithoutPort()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse("host");

            Assert.Equal("host", e.HostName);
            Assert.Equal(Protocols.DefaultProtocol.DefaultPort, e.Port);
        }
コード例 #7
0
        public void TestHostWithPort()
        {
            AmqpTcpEndpoint e = AmqpTcpEndpoint.Parse("host:1234");

            Assert.Equal("host", e.HostName);
            Assert.Equal(1234, e.Port);
        }
コード例 #8
0
 public void TestInvalidPort()
 {
     try
     {
         AmqpTcpEndpoint.Parse("host:port");
         Assert.Fail("Expected FormatException");
     }
     catch (FormatException)
     {
         // OK.
     }
 }
コード例 #9
0
 ///<summary>Conservative extension to the spec, supporting
 ///multiple interfaces in the "host" field of the
 ///connection.redirect method.</summary>
 ///<remarks>
 /// We use ParseMultiple rather than Parse, because a single
 /// host may have multiple interfaces. The spec doesn't say
 /// what to do here, so this is a conservative extension (as
 /// in, if a broker only returns a single address, we handle
 /// that fine). We arbitrarily take the first element of the
 /// array.
 ///</remarks>
 public static AmqpTcpEndpoint ParseHost(IProtocol protocol, string host)
 {
     AmqpTcpEndpoint[] addresses = AmqpTcpEndpoint.ParseMultiple(protocol, host);
     if (addresses.Length == 0)
     {
         return(AmqpTcpEndpoint.Parse(protocol, ""));
         // ^^ effectively, a (kind of useless) default or null result
     }
     else
     {
         return(addresses[0]);
     }
 }
コード例 #10
0
        private void ApplySettings(ConnectionFactory connectionFactory, ConnectionSettings settings)
        {
            var endpoint = settings.Endpoint;

            if (!string.IsNullOrWhiteSpace(settings.Connection))
            {
                endpoint = _configuration?.GetSection(settings.Connection).Value;
            }

            if (!string.IsNullOrWhiteSpace(endpoint))
            {
                connectionFactory.Endpoint = AmqpTcpEndpoint.Parse(endpoint);
            }

            if (settings.UserName != null)
            {
                connectionFactory.UserName = settings.UserName;
            }

            if (settings.Password != null)
            {
                connectionFactory.Password = settings.Password;
            }

            if (settings.HostName != null)
            {
                connectionFactory.HostName = settings.HostName;
            }

            if (settings.Port.HasValue)
            {
                connectionFactory.Port = settings.Port.Value;
            }

            if (settings.VirtualHost != null)
            {
                connectionFactory.VirtualHost = settings.VirtualHost;
            }
        }
コード例 #11
0
 public void TestInvalidPort()
 {
     Assert.Throws <FormatException>(() => AmqpTcpEndpoint.Parse("host:port"));
 }