コード例 #1
0
        public void AddUrlQueryTest()
        {
            var request = new HttpApiRequestMessage();

            Assert.Throws <ApiInvalidConfigException>(() => request.AddUrlQuery("xKey", "xValue"));

            request.RequestUri = new Uri("http://webapiclient.com/");
            request.AddUrlQuery("xKey", "xValue");
            Assert.True(request.RequestUri == new Uri("http://webapiclient.com?xKey=xValue"));

            Assert.Throws <ArgumentNullException>(() => request.AddUrlQuery(null, string.Empty));

            request.AddUrlQuery("yKey", "yValue");
            Assert.True(request.RequestUri == new Uri("http://webapiclient.com?xKey=xValue&yKey=yValue"));

            var unicodeValue = Uri.EscapeDataString("老九");

            request.AddUrlQuery("zKey", "老九");
            var url = new Uri($"http://webapiclient.com?xKey=xValue&yKey=yValue&zKey={unicodeValue}");

            Assert.True(request.RequestUri == url);
        }
コード例 #2
0
        public void AddUrlQueryTest()
        {
            var request = new HttpApiRequestMessage();

            Assert.Throws <HttpApiInvalidOperationException>(() => request.AddUrlQuery("xKey", "xValue"));

            request.RequestUri = new Uri("http://webapiclient.com/");
            request.AddUrlQuery("xKey", "xValue");
            Assert.True(request.RequestUri == new Uri("http://webapiclient.com?xKey=xValue"));

            Assert.Throws <ArgumentNullException>(() => request.AddUrlQuery(null, string.Empty));

            var kv = new KeyValue("yKey", "yValue");

            request.AddUrlQuery(kv);
            Assert.True(request.RequestUri == new Uri("http://webapiclient.com?xKey=xValue&yKey=yValue"));

            var unicodeValue = HttpUtility.UrlEncode("老九", Encoding.UTF8);

            request.AddUrlQuery(new[] { new KeyValue("zKey", "老九") }, Encoding.UTF8);
            var url = new Uri($"http://webapiclient.com?xKey=xValue&yKey=yValue&zKey={unicodeValue}");

            Assert.True(request.RequestUri == url);
        }