Example #1
0
        public void ToQueryString_WithObjectContainingCollection_ReturnsQuery()
        {
            string queryString = "names=" +
                                 "%5B" +
                                 "%22John%20Smith%22%2C" +
                                 "%22David%20Jones%22%2C" +
                                 "%22Sam%20Smith%22" +
                                 "%5D" +
                                 "&dob=2000-01-01T00%3A00%3A00";

            var query = new
            {
                names = new[]
                {
                    "John Smith",
                    "David Jones",
                    "Sam Smith"
                },
                dob = new DateTime(2000, 1, 1)
            };

            var formattedUrl = UrlSerializer.ToQueryString(query);

            Assert.AreEqual(queryString, formattedUrl);
        }
Example #2
0
        public void ToQueryString_WithNull_ReturnsEmptyString()
        {
            string expected = string.Empty;

            var result = UrlSerializer.ToQueryString(null);

            Assert.AreEqual(expected, result);
        }
Example #3
0
        /// <summary>
        /// Use an url-encoded form format body content, with a specified body
        /// </summary>
        /// <param name="body">The data to send as body content</param>
        /// <param name="encoding">The text encoding to use</param>
        /// <returns>The source <see cref="FluentRequest"/></returns>
        /// <exception cref="ArgumentNullException"><paramref name="encoding"/> is <see langword="null"/></exception>
        public FluentRequest Form(object body, Encoding encoding)
        {
            if (encoding is null)
            {
                throw new ArgumentNullException(nameof(encoding));
            }

            var bodyAsQueryString = UrlSerializer.ToQueryString(body);

            ToContent(ContentType.Application.Form, bodyAsQueryString, encoding);

            return(_request);
        }
Example #4
0
        public void ToQueryString_WithSimpleObject_ReturnsQuery()
        {
            string queryString = "name=John%20Smith&dob=2000-01-01T00%3A00%3A00";

            var query = new
            {
                name = "John Smith",
                dob  = new DateTime(2000, 1, 1)
            };

            var formattedUrl = UrlSerializer.ToQueryString(query);

            Assert.AreEqual(queryString, formattedUrl);
        }
        public void Form_WithData_AddsHeaderAndContent()
        {
            var form = new
            {
                q = "test"
            };
            var expected = UrlSerializer.ToQueryString(form);

            var request = Mock.CreateRequest();

            request
            .WithBody()
            .Form(form);

            Assert.AreEqual(expected, GetBodyOfRequest(request));
            Assert.AreEqual("application/x-www-form-urlencoded", GetContentType(request));
        }
Example #6
0
 /// <summary>
 /// Use a query string for the request
 /// </summary>
 /// <param name="query">The object to convert and use as the query string</param>
 /// <returns>This <see cref="FluentRequestUrl"/></returns>
 public FluentRequestUrl Query(object query)
 {
     return(Query(UrlSerializer.ToQueryString(query)));
 }