public async Task TestMultipleIndexedValuesFormData(string label1, string label2) { using (var webClient = new HttpClient()) { var content = new[] { new KeyValuePair<string, string>("test", "data"), new KeyValuePair<string, string>(label1, "1"), new KeyValuePair<string, string>(label2, "2") }; var formContent = new FormUrlEncodedContent(content); var result = await webClient.PostAsync(WebServerUrl + TestController.EchoPath, formContent); Assert.IsNotNull(result); var data = await result.Content.ReadAsStringAsync(); var obj = Json.Deserialize<FormDataSample>(data); Assert.IsNotNull(obj); Assert.AreEqual(content.First().Value, obj.test); Assert.AreEqual(2, obj.id.Count); Assert.AreEqual(content.Last().Value, obj.id.Last()); } }
public async Task TestDictionaryFormData() { using (var webClient = new HttpClient()) { var content = new[] { new KeyValuePair<string, string>("test", "data"), new KeyValuePair<string, string>("id", "1") }; var formContent = new FormUrlEncodedContent(content); var result = await webClient.PostAsync(WebServerUrl + TestController.EchoPath, formContent); Assert.IsNotNull(result); var data = await result.Content.ReadAsStringAsync(); var obj = Json.Deserialize<Dictionary<string, string>>(data); Assert.AreEqual(2, obj.Keys.Count); Assert.AreEqual(content.First().Key, obj.First().Key); Assert.AreEqual(content.First().Value, obj.First().Value); } }