private T StringToPoco <T>(string str)
 {
     using (new BasicAppHost().Init())
     {
         NameValueCollection queryString = HttpUtility.ParseQueryString(str);
         var restPath    = new RestPath(typeof(T), "/query", "GET, POST");
         var restHandler = new RestHandler();
         var httpReq     = new MockHttpRequest("query", "GET", "application/json", "query", queryString,
                                               new MemoryStream(), new NameValueCollection());
         httpReq.SetRoute(restPath);
         var request = (T)restHandler.CreateRequestAsync(httpReq, "query").Result;
         return(request);
     }
 }
        public void Can_deserialize_TestRequest_QueryStringSerializer_output()
        {
            // Setup
            using (new BasicAppHost(typeof(TestService).Assembly).Init())
            {
                var restPath      = new RestPath(typeof(TestRequest), "/service", "GET");
                var restHandler   = new RestHandler();
                var requestString = "ListOfA={ListOfB:[{Property:prop1},{Property:prop2}]}";
                NameValueCollection queryString = HttpUtility.ParseQueryString(requestString);
                var httpReq = new MockHttpRequest("service", "GET", "application/json", "service", queryString, new MemoryStream(), new NameValueCollection());
                httpReq.SetRoute(restPath);
                var request2 = (TestRequest)restHandler.CreateRequestAsync(httpReq, "service").Result;

                Assert.That(request2.ListOfA.Count, Is.EqualTo(1));
                Assert.That(request2.ListOfA.First().ListOfB.Count, Is.EqualTo(2));
            }
        }
Example #3
0
        private T StringToPoco <T>(string str)
        {
            var envKey = Environment.GetEnvironmentVariable("SERVICESTACK_LICENSE");

            if (!string.IsNullOrEmpty(envKey))
            {
                Licensing.RegisterLicense(envKey);
            }
            using (new BasicAppHost().Init())
            {
                NameValueCollection queryString = HttpUtility.ParseQueryString(str);
                var restPath    = new RestPath(typeof(T), "/query", "GET, POST");
                var restHandler = new RestHandler
                {
                    RestPath = restPath
                };
                var httpReq = new MockHttpRequest("query", "GET", "application/json", "query", queryString,
                                                  new MemoryStream(), new NameValueCollection());
                var request = (T)restHandler.CreateRequestAsync(httpReq, "query").Result;
                return(request);
            }
        }