public void TestCreateRequest() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); var request = new Request( HttpMethod.Post, Twilio.Rest.Domain.Preview, "/HostedNumbers/HostedNumberOrders", "" ); request.AddPostParam("AddressSid", Serialize("ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); request.AddPostParam("PhoneNumber", Serialize(new Twilio.Types.PhoneNumber("+987654321"))); request.AddPostParam("IsoCountry", Serialize("IsoCountry")); request.AddPostParam("SmsCapability", Serialize(true)); request.AddPostParam("Email", Serialize("Email")); twilioRestClient.Request(request).Throws(new ApiException("Server Error, no content")); try { HostedNumberOrderResource.Create("ADaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", new Twilio.Types.PhoneNumber("+987654321"), "IsoCountry", true, "Email", client: twilioRestClient); Assert.Fail("Expected TwilioException to be thrown for 500"); } catch (ApiException) {} twilioRestClient.Received().Request(request); }
public void TestCreateWithoutOptionalLoaFieldsResponse() { var twilioRestClient = Substitute.For <ITwilioRestClient>(); twilioRestClient.AccountSid.Returns("ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); twilioRestClient.Request(Arg.Any <Request>()) .Returns(new Response( System.Net.HttpStatusCode.Created, "{\"account_sid\": \"ACaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"address_sid\": null,\"capabilities\": {\"sms\": true,\"voice\": false},\"cc_emails\": [],\"date_created\": \"2017-03-28T20:06:39Z\",\"date_updated\": \"2017-03-28T20:06:39Z\",\"email\": null,\"friendly_name\": null,\"incoming_phone_number_sid\": \"PN11111111111111111111111111111111\",\"phone_number\": \"+14153608311\",\"sid\": \"HRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"signing_document_sid\": null,\"status\": \"received\",\"unique_name\": null,\"url\": \"https://preview.twilio.com/HostedNumbers/HostedNumberOrders/HRaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\",\"verification_attempts\": 0}" )); var response = HostedNumberOrderResource.Create(new Twilio.Types.PhoneNumber("+987654321"), true, client: twilioRestClient); Assert.NotNull(response); }
static void Main(string[] args) { // Find your Account Sid and Token at twilio.com/console const string accountSid = "ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; const string authToken = "your_auth_token"; TwilioClient.Init(accountSid, authToken); var hostedNumberOrder = HostedNumberOrderResource.Create( phoneNumber: new Twilio.Types.PhoneNumber("+15017122661"), smsCapability: true ); Console.WriteLine(hostedNumberOrder.Sid); }