Example #1
0
        /// <summary>
        /// Composes a relative URI from given ClientRequest instance
        /// </summary>
        /// <param name="request">Instance of ClientRequest object</param>
        /// <returns></returns>
        protected virtual string ComposeUri(ClientRequest request)
        {
            request.HydratePaginationQuery();
            request.HydrateSortingQuery();
            request.HydrateFilteringQuery();

            string queryString = null;

            if (request.Query != null && request.Query.Count > 0)
            {
                List <string> queryStringList = new List <string>();
                foreach (KeyValuePair <string, string> query in request.Query)
                {
                    if (query.Value != null)
                    {
                        queryStringList.Add($"{query.Key}={query.Value}");
                    }
                    else
                    {
                        queryStringList.Add(query.Key);
                    }
                }

                queryString = "?" + string.Join("&", queryStringList);
            }

            return(request.Resource.TrimStart('/') + queryString);
        }
        public void HydrateSortingQuery_NullParameters_MissingSortingQueryExpected()
        {
            var request = new ClientRequest()
            {
                Parameters = null
            };

            request.HydrateSortingQuery();

            Assert.AreEqual(0, request.Query.Count);
        }
        public void HydrateSortingQuery_EmptySortingProperty_MissingSortingQueryExpected()
        {
            var request = new ClientRequest()
            {
                Parameters = new ClientRequestParameters()
                {
                    Sorting = new ClientRequestSorting()
                    {
                        Property = ""
                    }
                }
            };

            request.HydrateSortingQuery();

            Assert.AreEqual(0, request.Query.Count);
        }
        public void HydrateSortingQuery_WithoutDescending_ExpectedQuery()
        {
            ClientRequestParameters parameters = new ClientRequestParameters()
            {
                Sorting = new ClientRequestSorting()
                {
                    Property = "testproperty"
                }
            };

            var request = new ClientRequest()
            {
                Parameters = parameters
            };

            request.HydrateSortingQuery();

            Assert.IsTrue(request.Query.ContainsKey("sort"));
            Assert.AreEqual("testproperty:asc", request.Query["sort"]);
        }