public void TestReadEmptyResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"countries\": [],\"meta\": {\"first_page_url\": \"https://pricing.twilio.com/v1/PhoneNumbers/Countries?PageSize=1&Page=0\",\"key\": \"countries\",\"next_page_url\": null,\"page\": 0,\"page_size\": 1,\"previous_page_url\": null,\"url\": \"https://pricing.twilio.com/v1/PhoneNumbers/Countries?PageSize=1&Page=0\"}}" )); var response = CountryResource.Read(client: twilioRestClient); Assert.NotNull(response); }
public void TestReadUsResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"content\": [{\"iso_code\": \"US\",\"name\": \"United States/Canada\",\"country_codes\": [\"+1\"],\"continent\": \"NORTH_AMERICA\",\"low_risk_numbers_enabled\": false,\"high_risk_special_numbers_enabled\": false,\"high_risk_tollfraud_numbers_enabled\": false,\"url\": \"https://voice.twilio.com/v1/DialingPermissions/Countries/US\",\"links\": {\"highrisk_special_prefixes\": \"https://voice.twilio.com/v1/DialingPermissions/Countries/US/HighRiskSpecialPrefixes\"}}],\"meta\": {\"first_page_url\": \"https://voice.twilio.com/v1/DialingPermissions/Countries?PageSize=50&Page=0\",\"key\": \"content\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://voice.twilio.com/v1/DialingPermissions/Countries?PageSize=50&Page=0\"}}" )); var response = CountryResource.Read(client: twilioRestClient); Assert.NotNull(response); }
public void TestReadFullResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.OK, "{\"countries\": [{\"country\": \"Andorra\",\"iso_country\": \"AD\",\"url\": \"https://pricing.twilio.com/v1/Voice/Countries/AD\"}],\"meta\": {\"first_page_url\": \"https://pricing.twilio.com/v1/Voice/Countries?PageSize=50&Page=0\",\"key\": \"countries\",\"next_page_url\": null,\"page\": 0,\"page_size\": 50,\"previous_page_url\": null,\"url\": \"https://pricing.twilio.com/v1/Voice/Countries?PageSize=50&Page=0\"}}" )); var response = CountryResource.Read(client: twilioRestClient); Assert.NotNull(response); }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var countries = CountryResource.Read(); foreach (var country in countries) { Console.WriteLine(country.IsoCountry); } }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console // DANGER! This is insecure. See http://twil.io/secure const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var countries = CountryResource.Read(limit: 20); foreach (var record in countries) { Console.WriteLine(record.Country); } }
public static void Main(string[] args) { // Find your Account SID and Auth Token at twilio.com/console // To set up environmental variables, see http://twil.io/secure const string accountSid = Environment.GetEnvironmentVariable("TWILIO_ACCOUNT_SID"); const string authToken = Environment.GetEnvironmentVariable("TWILIO_AUTH_TOKEN"); TwilioClient.Init(accountSid, authToken); var countries = CountryResource.Read(); foreach (var country in countries) { Console.WriteLine(country.IsoCountry); } }
public void TestReadRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Get, Twilio.Rest.Domain.Voice, "/v1/DialingPermissions/Countries", "" ); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { CountryResource.Read(client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }