public async Task batch_url_is_correct() { string url = null; var proxy = new Mock<IRestCommunicationProxy>(); proxy.Setup( m => m.PostAsync(It.IsAny<RestHost>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<HttpWebRequest>>()) ) .Returns<RestHost, string, string,Action<HttpWebRequest>>( (h, u, data, res) => { url = u; Stream str = new MemoryStream(); var w = new StreamWriter(str); w.Write("{\"Response\":\"Ok\"}"); return Task.FromResult(str); }); IRest rest = new Evolution.RestSDK.Implementations.Rest(proxy.Object); var requests = new List<BatchRequest>(); var nvc = new NameValueCollection(); nvc.Add("parm", "p1"); requests.Add(new BatchRequest("info.json", 0) { ApiVersion = 2, RequestParameters = nvc }); var nvc2 = new NameValueCollection(); nvc2.Add("parm", "p1"); nvc2.Add("parm2", "p2"); requests.Add(new BatchRequest("users.json", 0) { ApiVersion = 2, RequestParameters = nvc2 }); var resp = await rest.BatchEndpointStringAsync(new TestRestHost("http://community/"), 2, requests); Assert.AreEqual("http://community/api.ashx/v2/batch.json", url); }
public async Task batch_postdata_requests_is_correct() { string postData = null; var proxy = new Mock<IRestCommunicationProxy>(); proxy.Setup( m => m.PostAsync(It.IsAny<RestHost>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Action<HttpWebRequest>>()) ) .Returns<RestHost, string, string, Action<HttpWebRequest>>( (h, u, data, res) => { postData = data; Stream str = new MemoryStream(); var w = new StreamWriter(str); w.Write("{\"Response\":\"Ok\"}"); return Task.FromResult(str); }); IRest rest = new Evolution.RestSDK.Implementations.Rest(proxy.Object); var requests = new List<BatchRequest>(); var nvc = new NameValueCollection(); nvc.Add("parm", "p1"); requests.Add(new BatchRequest("info.json", 0) { ApiVersion = 2, RequestParameters = nvc }); var nvc2 = new NameValueCollection(); nvc2.Add("parm", "p1"); nvc2.Add("parm2", "p2"); requests.Add(new BatchRequest("users.json", 1) { ApiVersion = 2, RequestParameters = nvc2 }); var resp = await rest.BatchEndpointStringAsync(new TestRestHost("http://community/"), 2, requests); var reqParms = HttpUtility.ParseQueryString(postData); Assert.AreEqual(7, reqParms.Keys.Count); Assert.AreEqual("false", reqParms["Sequential"]); //7 = 3 per request plus sequentially }