public void TestJsonInputWithJsonValue() { List <string> jsonInputs = new List <string> { "null", "123", "123.45", "\"hello\"", "true", "false", "[]", "{}", "[1,2,3]", "[[[1],[2,2]],3,[4,5,6]]", "{\"a\":123,\"b\":null,\"c\":[1,2],\"d\":{\"e\":1}}", }; string[] contentTypes = new string[] { "text/json", "text/json; charset=utf-8", "application/json", ApplicationJsonContentTypeWithCharset, }; int contentTypeIndex = 0; foreach (string json in jsonInputs) { string contentType = contentTypes[contentTypeIndex]; Console.WriteLine("Sending JSON {0} with content-type {1}", json, contentType); WebHttpBehavior3Tests.Test("POST", Endpoint + "/Echo", contentType, json, HttpStatusCode.OK, json == "null" ? "" : ApplicationJsonContentTypeWithCharset, json == "null" ? "" : json); contentTypeIndex = (contentTypeIndex + 1) % contentTypes.Length; } }
public void WebGetTest() { string queryString = "/JQueryGet/Foo/Bar?Address=Capital+Hill&customer%5BName%5D=Pete&customer%5BAddress%5D=Redmond&" + "customer%5BAge%5D%5B0%5D%5B%5D=23&customer%5BAge%5D%5B0%5D%5B%5D=24&customer%5BAge%5D%5B1%5D%5B%5D=25&" + "customer%5BAge%5D%5B1%5D%5B%5D=26&customer%5BPhones%5D%5B%5D=425+888+1111&customer%5BPhones%5D%5B%5D=425+345+7777&" + "customer%5BPhones%5D%5B%5D=425+888+4564&customer%5BEnrolmentDate%5D=%2FDate(1277243030667)%2F&role=PM&changeDate=3&count=15"; string expectedReturn = @"{""Name"":""Yavor"",""Address"":""Capital Hill"",""Age"":[[""23"",""24""],[""25"",""26""]],""Phones"":[""425 888 1111"",""425 345 7777"",""425 888 4564""],""EnrolmentDate"":""\/Date(1277243030667)\/""}"; WebHttpBehavior3Tests.Test("GET", Endpoint + queryString, null, null, HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, expectedReturn); }
public void TestJsonInputWithNoJsonValue() { int x, y; string expectedJson, expectedXml; CreateInputValuesAndExpectedResults(1, out x, out y, out expectedJson, out expectedXml); string json = String.Format(CultureInfo.InvariantCulture, "{{\"x\":{0}, \"y\":{1}}}", x, y); WebHttpBehavior3Tests.Test("POST", Endpoint + "/AddJson", "application/json", json, HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, expectedJson); WebHttpBehavior3Tests.Test("POST", Endpoint + "/AddXml", "application/json", json, HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, expectedJson); }
public void TestXmlInputWithNoJsonValue() { int x, y; string expectedJson, expectedXml; CreateInputValuesAndExpectedResults(2, out x, out y, out expectedJson, out expectedXml); string addXmlInput = String.Format(CultureInfo.InvariantCulture, "<AddXml xmlns=\"http://tempuri.org/\"><x>{0}</x><y>{1}</y></AddXml>", x, y); string addJsonInput = addXmlInput.Replace("AddXml", "AddJson"); WebHttpBehavior3Tests.Test("POST", Endpoint + "/AddJson", "text/xml", addJsonInput, HttpStatusCode.OK, "text/xml; charset=utf-8", expectedXml); WebHttpBehavior3Tests.Test("POST", Endpoint + "/AddXml", "text/xml", addXmlInput, HttpStatusCode.OK, "text/xml; charset=utf-8", expectedXml); }
static void Test <TService, IContract>(WebHttpBinding binding, WebHttpBehavior3 behavior, string method, string address, string contentType, string body, HttpStatusCode expectedHttpStatus, string expectedResponseContentType, string expectedResponseBody) { using (ServiceHost host = new ServiceHost(typeof(TService), new Uri(WebHttpBehavior3Tests.Endpoint))) { host.AddServiceEndpoint(typeof(IContract), binding, "").Behaviors.Add(behavior); try { host.Open(); WebHttpBehavior3Tests.Test(method, address, contentType, body, expectedHttpStatus, expectedResponseContentType, expectedResponseBody); } catch { host.Abort(); throw; } } }
static void WebInvokeTestWithEncoding(Encoding encoding, string contentType) { string jsonString = @"customer%5BName%5D=Pete&customer%5BAddress%5D=Redmond&customer%5BAge%5D%5B0%5D%5B%5D=23&" + "customer%5BAge%5D%5B0%5D%5B%5D=24&customer%5BAge%5D%5B1%5D%5B%5D=25&customer%5BAge%5D%5B1%5D%5B%5D=26&" + "customer%5BPhones%5D%5B%5D=425+888+1111&customer%5BPhones%5D%5B%5D=425+345+7777&" + "customer%5BPhones%5D%5B%5D=425+888+4564&customer%5BEnrolmentDate%5D=%2FDate(1277243030664)%2F&" + "customers%5B0%5D%5BName%5D=Pete2&customers%5B0%5D%5BAddress%5D=Redmond2&customers%5B0%5D%5BAge%5D%5B0%5D%5B%5D=23&" + "customers%5B0%5D%5BAge%5D%5B0%5D%5B%5D=24&customers%5B0%5D%5BAge%5D%5B1%5D%5B%5D=25&" + "customers%5B0%5D%5BAge%5D%5B1%5D%5B%5D=26&customers%5B0%5D%5BPhones%5D%5B%5D=425+888+1111&" + "customers%5B0%5D%5BPhones%5D%5B%5D=425+345+7777&customers%5B0%5D%5BPhones%5D%5B%5D=425+888+4564&" + "customers%5B0%5D%5BEnrolmentDate%5D=%2FDate(1277243030664)%2F&customers%5B1%5D%5BName%5D=Pete3&" + "customers%5B1%5D%5BAddress%5D=Redmond3&customers%5B1%5D%5BAge%5D%5B0%5D%5B%5D=23&customers%5B1%5D%5BAge%5D%5B0%5D%5B%5D=24&" + "customers%5B1%5D%5BAge%5D%5B1%5D%5B%5D=25&customers%5B1%5D%5BAge%5D%5B1%5D%5B%5D=26&" + "customers%5B1%5D%5BPhones%5D%5B%5D=425+888+1111&customers%5B1%5D%5BPhones%5D%5B%5D=425+345+7777&" + "customers%5B1%5D%5BPhones%5D%5B%5D=425+888+4564&customers%5B1%5D%5BEnrolmentDate%5D=%2FDate(1277243030664)%2F&role=NewRole&changeDate=3&count=15"; string expectedReturn = @"{""Name"":""Yavor"",""Address"":""Redmond"",""Age"":[[""23"",""24""],[""25"",""26""]],""Phones"":[""425 888 1111"",""425 345 7777"",""425 888 4564""],""EnrolmentDate"":""\/Date(1277243030664)\/""}"; WebHttpBehavior3Tests.Test("POST", Endpoint + "/JQuery/Foo/Bar", contentType, jsonString, encoding, HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, expectedReturn); }
public void TestJsonValueNotLastParameter() { WebHttpBehavior3Tests.Test("POST", Endpoint + "/GetKeyValue/b", FormUrlEncodedContentType, "a=1&b=2", HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, "\"2\""); }
public void WebInvokeWithWebOperationContextChangingContentType() { WebHttpBehavior3Tests.Test("POST", Endpoint + "/PostSettingHttpHeaders", FormUrlEncodedContentType, "Content-Type=text%2Fplain", HttpStatusCode.OK, "text/plain", "{\"Content-Type\":\"text\\/plain\"}"); }
public void WebInvokeWithWebOperationContext() { WebHttpBehavior3Tests.Test("POST", Endpoint + "/PostSettingHttpHeaders", FormUrlEncodedContentType, "Cache-Control=no-cache", HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, "{\"Cache-Control\":\"no-cache\"}"); }
public void WebGetWithWebOperationContext() { WebHttpBehavior3Tests.Test("GET", Endpoint + "/GetSettingHttpHeaders?X-Foo=something", null, null, HttpStatusCode.OK, ApplicationJsonContentTypeWithCharset, "{\"X-Foo\":\"something\"}"); }