public void CallConstructorTest() { Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("start_time_t", "84023452"); parameters.Add("call_center_call_id", "991234567"); parameters.Add("calling_number", "+1 8049274933"); parameters.Add("sku_list", "dvd, cleaner"); Call target = new Call(parameters); Assert.AreEqual(4, target.Parameters.Count); // target has set all parameters? // target parameters have correct keys? Assert.AreEqual(true, target.Parameters.ContainsKey("start_time_t")); Assert.AreEqual(true, target.Parameters.ContainsKey("call_center_call_id")); Assert.AreEqual(true, target.Parameters.ContainsKey("calling_number")); Assert.AreEqual(true, target.Parameters.ContainsKey("sku_list")); // target parameters have correct values? Assert.AreEqual(true, target.Parameters.ContainsValue("84023452")); Assert.AreEqual(true, target.Parameters.ContainsValue("991234567")); Assert.AreEqual(true, target.Parameters.ContainsValue("+1 8049274933")); Assert.AreEqual(true, target.Parameters.ContainsValue("dvd, cleaner")); }
public void ConvertToFormTest() { // create a Call object w/the following parameters String[] a = { "DVD", "cleaner" }; String[] b = { "2", "1" }; Dictionary<string, object> parameters = new Dictionary<string, object>(); parameters.Add("start_time_t", 1339721018); parameters.Add("call_center_call_id", 91234568); parameters.Add("duration_in_seconds", 200); parameters.Add("reason_code", "Terms&Conditions"); parameters.Add("sale_currency", "USD"); parameters.Add("sale_amount", 1.12); parameters.Add("email_address", "*****@*****.**"); parameters.Add("sku_list", a); parameters.Add("quantity_list", b); parameters.Add("calling_number", "+1 8889990000"); Call target = new Call(parameters); string expected = "start_time_t=1339721018&call_center_call_id=91234568&duration_in_seconds=200&reason_code=Terms%26Conditions&sale_currency=USD&sale_amount=1.12&email_address=john%40doe.com&sku_list[]=DVD&sku_list[]=cleaner&quantity_list[]=2&quantity_list[]=1&calling_number=%2b1+8889990000"; string actual = target.ConvertToForm(parameters); Assert.AreEqual(expected, actual); }
static void Main() { Dictionary<string, string> dict = new Dictionary<string, string>(); dict.Add("CallCenterID", "1"); dict.Add("APIVersion", "2010-04-22"); dict.Add("APIUsername", "*****@*****.**"); dict.Add("APIPassword", "firefox"); CallCenter.config(dict); // create a list of parameters List<Dictionary<string, object>> parameters = new List<Dictionary<string, object>>(); Dictionary<string, object> c1params = new Dictionary<string, object>(); c1params.Add("start_time_t", 1339289018); c1params.Add("call_center_call_id", 91234567); c1params.Add("duration_in_seconds", 200); c1params.Add("reason_code", "Terms&Conditions"); c1params.Add("sale_currency", "USD"); c1params.Add("sale_amount", 1.01); parameters.Add(c1params); String[] a = { "DVD", "cleaner" }; String[] b = { "2", "1" }; Dictionary<string, object> c2params = new Dictionary<string, object>(); c2params.Add("start_time_t", 1339721018); c2params.Add("call_center_call_id", 91234568); c2params.Add("duration_in_seconds", 200); c2params.Add("reason_code", "S"); c2params.Add("sale_currency", "USD"); c2params.Add("sale_amount", 1.12); c2params.Add("email_address", "*****@*****.**"); c2params.Add("sku_list", a); c2params.Add("quantity_list", b); parameters.Add(c2params); Dictionary<string, object> c3params = new Dictionary<string, object>(); c3params.Add("start_time_t", 1340153017); c3params.Add("call_center_call_id", 91234569); c3params.Add("duration_in_seconds", 200); c3params.Add("reason_code", "S"); c3params.Add("sale_currency", "USD"); c3params.Add("sale_amount", 2.02); c3params.Add("called_phone_number", "+1 8888665440"); c3params.Add("calling_phone_number", "+1 8056801218"); parameters.Add(c3params); foreach (var options in parameters) { try { Call call = new Call(options); Dictionary<string, string> response = call.save(); Console.WriteLine("status_code: {0}\nresponse_body: {1}", response["status_code"], response["response_body"]); } catch (Exception e) { Console.WriteLine("Alternative exception caught."); Console.WriteLine(e.Message); } } Thread.Sleep(15000); }