public void ShouldAddNewIncomingPhoneNumberAsynchronously() { manualResetEvent = new ManualResetEvent(false); var client = new TwilioRestClient(Credentials.TestAccountSid, Credentials.TestAuthToken); PhoneNumberOptions options = new PhoneNumberOptions(); options.PhoneNumber = "+15005550006"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; IncomingPhoneNumber result = null; client.AddIncomingPhoneNumber(options, number => { result = number; manualResetEvent.Set(); }); manualResetEvent.WaitOne(); Assert.IsNotNull(result); Assert.IsNull(result.RestException); Assert.IsNotNull(result.Sid); }
public void ShouldAddNewIncomingPhoneNumber() { IRestRequest savedRequest = null; mockClient.Setup(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<IRestRequest>())) .Callback<IRestRequest>((request) => savedRequest = request) .Returns(new IncomingPhoneNumber()); var client = mockClient.Object; var options = new PhoneNumberOptions { PhoneNumber = "+15005550006", VoiceUrl = "http://example.com/phone", VoiceMethod = "GET", VoiceFallbackUrl = "http://example.com/phone", VoiceFallbackMethod = "GET", SmsUrl = "http://example.com/sms", SmsMethod = "GET", SmsFallbackUrl = "http://example.com/sms", SmsFallbackMethod = "GET", TrunkSid = "83a4a6d359f04fb693dff4cad19792b28H" }; client.AddIncomingPhoneNumber(options); mockClient.Verify(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<IRestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual(Method.POST, savedRequest.Method); Assert.AreEqual(10, savedRequest.Parameters.Count); var phoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "PhoneNumber"); Assert.IsNotNull(phoneNumberParam); Assert.AreEqual(options.PhoneNumber, phoneNumberParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethodParam); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethodParam.Value); var trunkSidParam = savedRequest.Parameters.Find(x => x.Name == "TrunkSid"); Assert.IsNotNull(trunkSidParam); Assert.AreEqual(options.TrunkSid, trunkSidParam.Value); }
public async Task ShouldAddNewIncomingPhoneNumber() { RestRequest savedRequest = null; var tcs = new TaskCompletionSource<IncomingPhoneNumber>(); tcs.SetResult(new IncomingPhoneNumber()); mockClient.Setup(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<RestRequest>())) .Callback<RestRequest>((request) => savedRequest = request) .Returns(tcs.Task); var client = mockClient.Object; PhoneNumberOptions options = new PhoneNumberOptions(); options.PhoneNumber = "+15005550006"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; await client.AddIncomingPhoneNumberAsync(options); mockClient.Verify(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<RestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual("POST", savedRequest.Method); Assert.AreEqual(9, savedRequest.Parameters.Count); var phoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "PhoneNumber"); Assert.IsNotNull(phoneNumberParam); Assert.AreEqual(options.PhoneNumber, phoneNumberParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethodParam); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethodParam.Value); }
public void ShouldAddNewIncomingPhoneNumberByAreaCode() { var client = new TwilioRestClient(Credentials.TestAccountSid, Credentials.TestAuthToken); PhoneNumberOptions options = new PhoneNumberOptions(); options.AreaCode = "500"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; var result = client.AddIncomingPhoneNumber(options); Assert.IsNotNull(result); Assert.IsNull(result.RestException); Assert.IsNotNull(result.Sid); }
public void ShouldUpdateIncomingPhoneNumberAsynchronously() { manualResetEvent = new ManualResetEvent(false); var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken); PhoneNumberOptions options = new PhoneNumberOptions(); IncomingPhoneNumber result = null; client.UpdateIncomingPhoneNumber("", options, number => { result = number; manualResetEvent.Set(); }); manualResetEvent.WaitOne(); Assert.IsNotNull(result); Assert.IsNull(result.RestException); Assert.IsNotNull(result.Sid); Assert.Fail(); }
public void ShouldUpdateIncomingPhoneNumber() { var client = new TwilioRestClient(Credentials.AccountSid, Credentials.AuthToken); PhoneNumberOptions options = new PhoneNumberOptions(); var result = client.UpdateIncomingPhoneNumber("", options); Assert.IsNotNull(result); Assert.IsNull(result.RestException); Assert.IsNotNull(result.Sid); Assert.Fail(); }
public async Task ShouldUpdateIncomingPhoneNumber() { RestRequest savedRequest = null; var tcs = new TaskCompletionSource<IncomingPhoneNumber>(); tcs.SetResult(new IncomingPhoneNumber()); mockClient.Setup(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<RestRequest>())) .Callback<RestRequest>((request) => savedRequest = request) .Returns(tcs.Task); var client = mockClient.Object; PhoneNumberOptions options = new PhoneNumberOptions(); await client.UpdateIncomingPhoneNumberAsync(INCOMING_PHONE_NUMBER_SID, options); mockClient.Verify(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<RestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers/{IncomingPhoneNumberSid}.json", savedRequest.Resource); Assert.AreEqual("POST", savedRequest.Method); Assert.AreEqual(1, savedRequest.Parameters.Count); var incomingPhoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "IncomingPhoneNumberSid"); Assert.IsNotNull(incomingPhoneNumberParam); Assert.AreEqual(INCOMING_PHONE_NUMBER_SID, incomingPhoneNumberParam.Value); }
public void ShouldAddNewIncomingPhoneNumber() { IRestRequest savedRequest = null; mockClient.Setup(trc => trc.Execute <IncomingPhoneNumber>(It.IsAny <IRestRequest>())) .Callback <IRestRequest>((request) => savedRequest = request) .Returns(new IncomingPhoneNumber()); var client = mockClient.Object; var options = new PhoneNumberOptions { PhoneNumber = "+15005550006", VoiceUrl = "http://example.com/phone", VoiceMethod = "GET", VoiceFallbackUrl = "http://example.com/phone", VoiceFallbackMethod = "GET", SmsUrl = "http://example.com/sms", SmsMethod = "GET", SmsFallbackUrl = "http://example.com/sms", SmsFallbackMethod = "GET", TrunkSid = "83a4a6d359f04fb693dff4cad19792b28H" }; client.AddIncomingPhoneNumber(options); mockClient.Verify(trc => trc.Execute <IncomingPhoneNumber>(It.IsAny <IRestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual(Method.POST, savedRequest.Method); Assert.AreEqual(10, savedRequest.Parameters.Count); var phoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "PhoneNumber"); Assert.IsNotNull(phoneNumberParam); Assert.AreEqual(options.PhoneNumber, phoneNumberParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethodParam); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethodParam.Value); var trunkSidParam = savedRequest.Parameters.Find(x => x.Name == "TrunkSid"); Assert.IsNotNull(trunkSidParam); Assert.AreEqual(options.TrunkSid, trunkSidParam.Value); }
public void ShouldAddNewIncomingPhoneNumberByAreaCode() { IRestRequest savedRequest = null; mockClient.Setup(trc => trc.Execute <IncomingPhoneNumber>(It.IsAny <IRestRequest>())) .Callback <IRestRequest>((request) => savedRequest = request) .Returns(new IncomingPhoneNumber()); var client = mockClient.Object; PhoneNumberOptions options = new PhoneNumberOptions(); options.AreaCode = "500"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; client.AddIncomingPhoneNumber(options); mockClient.Verify(trc => trc.Execute <IncomingPhoneNumber>(It.IsAny <IRestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual(Method.POST, savedRequest.Method); Assert.AreEqual(9, savedRequest.Parameters.Count); var areaCodeParam = savedRequest.Parameters.Find(x => x.Name == "AreaCode"); Assert.IsNotNull(areaCodeParam); Assert.AreEqual(options.AreaCode, areaCodeParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethod = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethod); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethod.Value); }
public void ShouldAddNewIncomingPhoneNumberAsynchronously() { RestRequest savedRequest = null; mockClient.Setup(trc => trc.ExecuteAsync<IncomingPhoneNumber>(It.IsAny<RestRequest>(), It.IsAny<Action<IncomingPhoneNumber>>())) .Callback<RestRequest, Action<IncomingPhoneNumber>>((request, action) => savedRequest = request); var client = mockClient.Object; manualResetEvent = new ManualResetEvent(false); PhoneNumberOptions options = new PhoneNumberOptions(); options.PhoneNumber = "+15005550006"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; client.AddIncomingPhoneNumber(options, number => { manualResetEvent.Set(); }); manualResetEvent.WaitOne(1); mockClient.Verify(trc => trc.ExecuteAsync<IncomingPhoneNumber>(It.IsAny<RestRequest>(), It.IsAny<Action<IncomingPhoneNumber>>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual("POST", savedRequest.Method); Assert.AreEqual(9, savedRequest.Parameters.Count); var phoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "PhoneNumber"); Assert.IsNotNull(phoneNumberParam); Assert.AreEqual(options.PhoneNumber, phoneNumberParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethodParam); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethodParam.Value); }
public void ShouldUpdateIncomingPhoneNumberAsynchronously() { RestRequest savedRequest = null; mockClient.Setup(trc => trc.ExecuteAsync<IncomingPhoneNumber>(It.IsAny<RestRequest>(), It.IsAny<Action<IncomingPhoneNumber>>())) .Callback<RestRequest, Action<IncomingPhoneNumber>>((request, action) => savedRequest = request); var client = mockClient.Object; manualResetEvent = new ManualResetEvent(false); PhoneNumberOptions options = new PhoneNumberOptions(); client.UpdateIncomingPhoneNumber(INCOMING_PHONE_NUMBER_SID, options, number => { manualResetEvent.Set(); }); manualResetEvent.WaitOne(1); mockClient.Verify(trc => trc.ExecuteAsync<IncomingPhoneNumber>(It.IsAny<RestRequest>(), It.IsAny<Action<IncomingPhoneNumber>>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers/{IncomingPhoneNumberSid}.json", savedRequest.Resource); Assert.AreEqual("POST", savedRequest.Method); Assert.AreEqual(1, savedRequest.Parameters.Count); var incomingPhoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "IncomingPhoneNumberSid"); Assert.IsNotNull(incomingPhoneNumberParam); Assert.AreEqual(INCOMING_PHONE_NUMBER_SID, incomingPhoneNumberParam.Value); }
public void ShouldAddNewIncomingPhoneNumberByAreaCode() { RestRequest savedRequest = null; mockClient.Setup(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<RestRequest>())) .Callback<RestRequest>((request) => savedRequest = request) .Returns(new IncomingPhoneNumber()); var client = mockClient.Object; PhoneNumberOptions options = new PhoneNumberOptions(); options.AreaCode = "500"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; client.AddIncomingPhoneNumber(options); mockClient.Verify(trc => trc.Execute<IncomingPhoneNumber>(It.IsAny<RestRequest>()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual("POST", savedRequest.Method); Assert.AreEqual(9, savedRequest.Parameters.Count); var areaCodeParam = savedRequest.Parameters.Find(x => x.Name == "AreaCode"); Assert.IsNotNull(areaCodeParam); Assert.AreEqual(options.AreaCode, areaCodeParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethod = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethod); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethod.Value); }
void HandleUrlForIncomingSms(string accountSid, string authToken, string receivingNumber, PhoneNumberOptions phoneOptions) { if (!receivingNumber.StartsWith(TestSendNumberPrefix)) { var cleanNumber = PhoneNumberHelper.CleanNumber(receivingNumber); var twilioClient = new TwilioRestClient(accountSid, authToken); var numbersRequest = twilioClient.ListIncomingPhoneNumbers(); if (numbersRequest.RestException != null) { throw new TwilioException($"Failed to fetch list of numbers from Twilio: {numbersRequest.RestException.Message}"); } var number = numbersRequest.IncomingPhoneNumbers.FirstOrDefault(n => PhoneNumberHelper.CleanNumber(n.PhoneNumber) == cleanNumber); if (number == null) { throw new ArgumentException("Unable to find matching number", nameof(receivingNumber)); } twilioClient.UpdateIncomingPhoneNumber(number.Sid, phoneOptions); } }
public void ShouldAddNewIncomingPhoneNumberAsynchronously() { IRestRequest savedRequest = null; mockClient.Setup(trc => trc.ExecuteAsync <IncomingPhoneNumber>(It.IsAny <IRestRequest>(), It.IsAny <Action <IncomingPhoneNumber> >())) .Callback <IRestRequest, Action <IncomingPhoneNumber> >((request, action) => savedRequest = request); var client = mockClient.Object; manualResetEvent = new ManualResetEvent(false); PhoneNumberOptions options = new PhoneNumberOptions(); options.PhoneNumber = "+15005550006"; options.VoiceUrl = "http://example.com/phone"; options.VoiceMethod = "GET"; options.VoiceFallbackUrl = "http://example.com/phone"; options.VoiceFallbackMethod = "GET"; options.SmsUrl = "http://example.com/sms"; options.SmsMethod = "GET"; options.SmsFallbackUrl = "http://example.com/sms"; options.SmsFallbackMethod = "GET"; client.AddIncomingPhoneNumber(options, number => { manualResetEvent.Set(); }); manualResetEvent.WaitOne(1); mockClient.Verify(trc => trc.ExecuteAsync <IncomingPhoneNumber>(It.IsAny <IRestRequest>(), It.IsAny <Action <IncomingPhoneNumber> >()), Times.Once); Assert.IsNotNull(savedRequest); Assert.AreEqual("Accounts/{AccountSid}/IncomingPhoneNumbers.json", savedRequest.Resource); Assert.AreEqual(Method.POST, savedRequest.Method); Assert.AreEqual(9, savedRequest.Parameters.Count); var phoneNumberParam = savedRequest.Parameters.Find(x => x.Name == "PhoneNumber"); Assert.IsNotNull(phoneNumberParam); Assert.AreEqual(options.PhoneNumber, phoneNumberParam.Value); var voiceUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceUrl"); Assert.IsNotNull(voiceUrlParam); Assert.AreEqual(options.VoiceUrl, voiceUrlParam.Value); var voiceMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceMethod"); Assert.IsNotNull(voiceMethodParam); Assert.AreEqual(options.VoiceMethod, voiceMethodParam.Value); var voiceFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackUrl"); Assert.IsNotNull(voiceFallbackUrlParam); Assert.AreEqual(options.VoiceFallbackUrl, voiceFallbackUrlParam.Value); var voiceFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "VoiceFallbackMethod"); Assert.IsNotNull(voiceFallbackMethodParam); Assert.AreEqual(options.VoiceFallbackMethod, voiceFallbackMethodParam.Value); var smsUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsUrl"); Assert.IsNotNull(smsUrlParam); Assert.AreEqual(options.SmsUrl, smsUrlParam.Value); var smsMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsMethod"); Assert.IsNotNull(smsMethodParam); Assert.AreEqual(options.SmsMethod, smsMethodParam.Value); var smsFallbackUrlParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackUrl"); Assert.IsNotNull(smsFallbackUrlParam); Assert.AreEqual(options.SmsFallbackUrl, smsFallbackUrlParam.Value); var smsFallbackMethodParam = savedRequest.Parameters.Find(x => x.Name == "SmsFallbackMethod"); Assert.IsNotNull(smsFallbackMethodParam); Assert.AreEqual(options.SmsFallbackMethod, smsFallbackMethodParam.Value); }