Ejemplo n.º 1
0
        public static GrpcUrl Parse(string address)
        {
            var splitRes = address.Split(':');

            if (splitRes.Length != 3)
            {
                return(null);
            }

            GrpcUrl url = new GrpcUrl();

            url.IpVersion = splitRes[0];
            url.IpAddress = splitRes[1];
            url.Port      = int.Parse(splitRes[2]);

            return(url);
        }
Ejemplo n.º 2
0
        public void GrpcUrl_ParseTest()
        {
            //wrong format
            {
                string address = "127.0.0.1:8000";
                var    grpcUrl = GrpcUrl.Parse(address);

                grpcUrl.ShouldBeNull();
            }

            //correct format
            {
                string address = "ipv4:127.0.0.1:8000";
                var    grpcUrl = GrpcUrl.Parse(address);

                grpcUrl.IpVersion.ShouldBe("ipv4");
                grpcUrl.IpAddress.ShouldBe("127.0.0.1");
                grpcUrl.Port.ShouldBe(8000);

                var ipPortFormat = grpcUrl.ToIpPortFormat();
                ipPortFormat.ShouldBe("127.0.0.1:8000");
            }
        }