protected T GetFromQueryString <T>() where T : new()
        {
            var obj        = new T();
            var properties = typeof(T).GetProperties();

            foreach (var property in properties)
            {
                var valueAsString = HttpContext.Current.Request.QueryString[property.Name];

                if (property.Name.ToLower() == "filter")
                {
                    valueAsString = RequestExtensions.GetFilterRequest(HttpContext.Current.Request.Url.Query);
                }

                if (valueAsString == null)
                {
                    continue;
                }

                if (property.PropertyType == typeof(string))
                {
                    property.SetValue(obj, valueAsString, null);
                }

                else if (property.PropertyType == typeof(int))
                {
                    var value = int.Parse(valueAsString);
                    property.SetValue(obj, value, null);
                }
            }

            return(obj);
        }
Ejemplo n.º 2
0
        public void ShouldGetFilterRequestGetEmptyString(string queryString)
        {
            var filterRequest = RequestExtensions.GetFilterRequest(queryString);

            Assert.IsEmpty(filterRequest);
        }
Ejemplo n.º 3
0
        public void ShouldGetFilterRequestWithAlternateParamName(string queryString, string expectedValue)
        {
            var filterRequest = RequestExtensions.GetFilterRequest(queryString, "opportunityFilter");

            Assert.AreEqual(expectedValue, filterRequest);
        }
Ejemplo n.º 4
0
        public void ShouldGetFilterRequest(string queryString, string expectedValue)
        {
            var filterRequest = RequestExtensions.GetFilterRequest(queryString);

            Assert.AreEqual(expectedValue, filterRequest);
        }