public void Action_Login() { NameValueCollection values = new NameValueCollection(); values.Add("id", USER_ID); values.Add("pwd", USER_PWD); using (var wc = CreateWebClient()) { var bytes = wc.UploadValues(INTEGRATION_HTTP_ADDR + "LoginUser", values); var str = GetUTF8StringWOBOM(bytes); Console.WriteLine(str); Assert.AreEqual("application/json", wc.ResponseHeaders[HttpResponseHeader.ContentType]); var obj = JSONReader.DeserializeDynamic(str); Assert.AreEqual(USER_STATUS, obj["Status"]); Assert.AreEqual(USER_NAME, obj["Name"]); str = wc.DownloadString(INTEGRATION_HTTP_ADDR + "GetWithPermission"); Assert.IsFalse(Regex.IsMatch(str, "Authorization to .+/TestPath/TestPermission.+ failed")); } }
public void Action_RowGet_JSONDataMap() { DateTime start = DateTime.Now; System.Threading.Thread.Sleep(3000); using (var wc = CreateWebClient()) { string str = wc.DownloadString(INTEGRATION_HTTP_ADDR + "RowGet"); Assert.AreEqual("application/json", wc.ResponseHeaders[HttpResponseHeader.ContentType]); var obj = JSONReader.DeserializeDynamic(str); Assert.AreEqual(16, obj.Data.Count); Assert.AreEqual(777UL, obj.Data["ID"]); Assert.AreEqual("Test Name", obj.Data["Name"]); var date = DateTime.Parse(obj.Data["Date"]); Assert.IsTrue((DateTime.Now - start).TotalSeconds >= 2.0d); Assert.AreEqual("Ok", obj.Data["Status"]); var gotTs = TimeSpan.FromTicks((long)(ulong)(obj.Data["Span"])); Assert.AreEqual(TimeSpan.FromSeconds(1), gotTs); } }
public void Action_GetList(WebClient wc) { //using (var wc = CreateWebClient()) { string str = wc.DownloadString(m_ServerURI + "GetList"); if ("application/json" != wc.ResponseHeaders[HttpResponseHeader.ContentType]) { throw new Exception(); } var obj = JSONReader.DeserializeDynamic(str); if (3 != obj.Data.Count) { throw new Exception(); } if (1UL != obj.Data[0]) { throw new Exception(); } if (2UL != obj.Data[1]) { throw new Exception(); } if (3UL != obj.Data[2]) { throw new Exception(); } } }
public void Action_GetAnonymousObject() { using (var wc = CreateWebClient()) { var str = wc.UploadString(INTEGRATION_HTTP_ADDR + "GetAnonymousObject", string.Empty); Console.WriteLine(str); var obj = JSONReader.DeserializeDynamic(str); Assert.AreEqual(55UL, obj.Data["ID"]); Assert.AreEqual("test", obj.Data["Name"]); } }
public void Action_GetArray() { using (var wc = CreateWebClient()) { string str = wc.DownloadString(INTEGRATION_HTTP_ADDR + "GetArray"); Assert.AreEqual("application/json", wc.ResponseHeaders[HttpResponseHeader.ContentType]); var obj = JSONReader.DeserializeDynamic(str); Assert.AreEqual(3, obj.Data.Count); Assert.AreEqual(1UL, obj.Data[0]); Assert.AreEqual(2UL, obj.Data[1]); Assert.AreEqual(3UL, obj.Data[2]); } }
public void Action_RowGet_JSONDataMap(WebClient wc) { var start = DateTime.Now; System.Threading.Thread.Sleep(3000); //using (var wc = CreateWebClient()) { string str = wc.DownloadString(m_ServerURI + "RowGet"); if ("application/json" != wc.ResponseHeaders[HttpResponseHeader.ContentType]) { throw new Exception(); } var obj = JSONReader.DeserializeDynamic(str); if (16 != obj.Data.Count) { throw new Exception(); } if (777UL != obj.Data["ID"]) { throw new Exception(); } if ("Test Name" != obj.Data["Name"]) { throw new Exception(); } var date = DateTime.Parse(obj.Data["Date"]); if ((DateTime.Now - start).TotalSeconds < 2.0d) { throw new Exception(); } if ("Ok" != obj.Data["Status"]) { throw new Exception(); } var gotTs = TimeSpan.FromTicks((long)(ulong)(obj.Data["Span"])); if (TimeSpan.FromSeconds(1) != gotTs) { throw new Exception(); } } }
public void Action_InboundJSONMapEcho() { var inboundJSONStr = "ID=777&Name=TestName"; using (var wc = CreateWebClient()) { wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; string str = wc.UploadString(INTEGRATION_HTTP_ADDR + "InboundJSONMapEcho", inboundJSONStr); Assert.AreEqual("application/json", wc.ResponseHeaders[HttpResponseHeader.ContentType]); var obj = JSONReader.DeserializeDynamic(str); Assert.AreEqual(4, obj.Data.Count); Assert.AreEqual("777", obj.Data["ID"]); Assert.AreEqual("TestName", obj.Data["Name"]); Assert.AreEqual(INTEGRATIONN_TESTER, obj.Data["type"]); Assert.AreEqual("InboundJSONMapEcho", obj.Data["mvc-action"]); } }
public void Action_Login(WebClient wc) { var values = new NameValueCollection(); values.Add("id", USER_ID); values.Add("pwd", USER_PWD); //using (var wc = CreateWebClient()) { var bytes = wc.UploadValues(m_ServerURI + "LoginUser", values); var str = GetUTF8StringWOBOM(bytes); Console.WriteLine(str); if ("application/json" != wc.ResponseHeaders[HttpResponseHeader.ContentType]) { throw new Exception(); } var obj = JSONReader.DeserializeDynamic(str); if (USER_STATUS != obj["Status"]) { throw new Exception(); } if (USER_NAME != obj["Name"]) { throw new Exception(); } str = wc.DownloadString(m_ServerURI + "GetWithPermission"); if (Regex.IsMatch(str, "Authorization to .+/TestPath/TestPermission.+ failed")) { throw new Exception(); } } }