Esempio n. 1
0
        public void GetUriFor_noQueryParams(string host, string queryParams, string expected)
        {
            var uri = HttpClientRequest
                      .CreateGet(queryParams)
                      .GetUriFor(host);

            Assert.AreEqual(expected, uri.AbsoluteUri);
        }
Esempio n. 2
0
        public void GetUriFor_querySpecified_UrlIsCorrect()
        {
            string subPath = "/search";
            var    host    = "http://www.ya.ru";
            var    uri     = HttpClientRequest.CreateGet(subPath).GetUriFor(host);

            Assert.AreEqual(host + subPath, uri.AbsoluteUri);
        }
Esempio n. 3
0
        public void CreateWithBoundary_CountentTypeIsCorrect()
        {
            string boundary         = "theBoundary";
            var    getRequest       = HttpClientRequest.CreateGet();
            var    multipartContent = new MultipartContent(new[] { getRequest }, boundary);

            Assert.AreEqual($"multipart/mixed; boundary={boundary}", multipartContent.ContentType);
        }
Esempio n. 4
0
        public void GetUriFor_AddUriParam_UrlIsCorrect(object paramValue, string paramValueInPath)
        {
            var host      = "http://www.ya.ru";
            var paramName = "var";
            var uri       = HttpClientRequest.CreateGet()
                            .AddUriParam(paramName, paramValue).GetUriFor(host);


            Assert.AreEqual($"{host}/?{paramName}={paramValueInPath}", uri.AbsoluteUri);
        }
Esempio n. 5
0
        public void AddCustomHeader_BuildFor_CustomHeaderExists()
        {
            var name    = "myHeader";
            var value   = "myValue";
            var request = HttpClientRequest
                          .CreateGet()
                          .AddCustomHeader(name, value);

            var header = request.CustomHeaders.SingleOrDefault(c => c.Key == name);

            Assert.IsNotNull(header);
            Assert.AreEqual(value, header.Value);
        }
Esempio n. 6
0
        public void SetSubQuery_GetUriFor_UriIsCorrect(string host, string subquery)
        {
            var request = HttpClientRequest.CreateGet(subquery);


            var uri      = request.GetUriFor(host);
            var expected =
                $"{host.TrimEnd('/')}/{subquery.TrimStart('/')}";

            Assert.AreEqual(
                expected: expected,
                actual: uri.AbsoluteUri);
        }
Esempio n. 7
0
        public void CreateWithSingleEmptyGetRequest_WriteTo_ResultIsAsExpected()
        {
            string boundary         = "theBoundary";
            string host             = "http://www.ya.ru:9090/";
            string query            = "myquery";
            var    getRequest       = HttpClientRequest.CreateGet(query);
            var    multipartContent = new MultipartContent(new[] { getRequest }, boundary);
            string parsed           = GetContentString(host, multipartContent);

            string expected = "--" + boundary + "\r\n" +
                              "Content-Type: application/http; msgtype=request\r\n\r\n" + //todo: why it is application/http?
                              $"GET /{query} HTTP/1.1\r\n" +
                              "Host: www.ya.ru:9090\r\n" +
                              "\r\n\r\n" +
                              "--" + boundary + "--";

            Assert.AreEqual(expected, parsed);
        }
Esempio n. 8
0
        public void SetMultipleUrlParamAndSubQuery_GetUriFor_UriIsCorrect(string host, string subquery)
        {
            string[] paramNames         = { "var1", "var2", "var3" };
            object[] paramValues        = { "foo", 0, false };
            object[] paramValuesInQuery = { "foo", "0", "False" };

            var request = HttpClientRequest.CreateGet(subquery);

            for (int i = 0; i < paramNames.Length; i++)
            {
                request = request.AddUriParam(paramNames[i], paramValues[i]);
            }

            var uri      = request.GetUriFor(host);
            var expected =
                $"{host.TrimEnd('/')}/{subquery.TrimStart('/')}?{paramNames[0]}={paramValuesInQuery[0]}&{paramNames[1]}={paramValuesInQuery[1]}&{paramNames[2]}={paramValuesInQuery[2]}";

            Assert.AreEqual(
                expected: expected,
                actual: uri.AbsoluteUri);
        }
Esempio n. 9
0
        public void SetMultipleUrlParam_GetUriFor_UriIsCorrect()
        {
            var host = "http://www.ya.ru";

            string[] paramNames  = { "var1", "var2", "var3" };
            object[] paramValues = { "foo", 0, false };

            var request = HttpClientRequest.CreateGet();

            for (int i = 0; i < paramNames.Length; i++)
            {
                request = request.AddUriParam(paramNames[i], paramValues[i]);
            }


            var uri = request.GetUriFor(host);

            Assert.AreEqual(
                expected: $"{host}/?{paramNames[0]}={paramValues[0]}&{paramNames[1]}={paramValues[1]}&{paramNames[2]}={paramValues[2]}",
                actual: uri.AbsoluteUri);
        }