diff --git a/Vonage.Test/MessagingTests.cs b/Vonage.Test/MessagingTests.cs index c9e4819f4..3bd7b3d1e 100644 --- a/Vonage.Test/MessagingTests.cs +++ b/Vonage.Test/MessagingTests.cs @@ -14,7 +14,7 @@ namespace Vonage.Test public class MessagingTests : TestBase { [Fact] - public void NullMessagesResponse() + public async Task NullMessagesResponse() { var expectedResponse = @""; var expectedUri = $"{this.RestUrl}/sms/json"; @@ -22,8 +22,8 @@ public void NullMessagesResponse() $"from=AcmeInc&to=447700900000&text={WebUtility.UrlEncode("Hello World!")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; this.Setup(expectedUri, expectedResponse, expectedRequestContent); var client = this.BuildVonageClient(Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret)); - var exception = Assert.Throws(() => - client.SmsClient.SendAnSms(new SendSmsRequest + var exception = await Assert.ThrowsAsync(() => + client.SmsClient.SendAnSmsAsync(new SendSmsRequest {From = "AcmeInc", To = "447700900000", Text = "Hello World!"})); Assert.NotNull(exception); Assert.Equal("Encountered an Empty SMS response", exception.Message); @@ -93,26 +93,7 @@ public async Task SendSmsAsyncWithAllPropertiesSet(bool passCreds) } [Fact] - public void SendSmsBadResponse() - { - var expectedResponse = this.GetResponseJson(); - var expectedUri = $"{this.RestUrl}/sms/json"; - var expectedRequestContent = - $"from=AcmeInc&to=447700900000&text={WebUtility.UrlEncode("Hello World!")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - this.Setup(expectedUri, expectedResponse, expectedRequestContent); - var client = this.BuildVonageClient(Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret)); - var exception = Assert.Throws(() => - client.SmsClient.SendAnSms(new SendSmsRequest - {From = "AcmeInc", To = "447700900000", Text = "Hello World!"})); - Assert.NotNull(exception); - Assert.Equal( - $"SMS Request Failed with status: {exception.Response.Messages[0].Status} and error message: {exception.Response.Messages[0].ErrorText}", - exception.Message); - Assert.Equal(SmsStatusCode.InvalidCredentials, exception.Response.Messages[0].StatusCode); - } - - [Fact] - public void SendSmsTypicalUsage() + public async Task SendSmsTypicalUsage() { var expectedResponse = @"{ ""message-count"": ""1"", @@ -133,7 +114,7 @@ public void SendSmsTypicalUsage() $"from=AcmeInc&to=447700900000&text={WebUtility.UrlEncode("Hello World!")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; this.Setup(expectedUri, expectedResponse, expectedRequestContent); var client = this.BuildVonageClient(Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret)); - var response = client.SmsClient.SendAnSms(new SendSmsRequest + var response = await client.SmsClient.SendAnSmsAsync(new SendSmsRequest {From = "AcmeInc", To = "447700900000", Text = "Hello World!"}); Assert.Equal("1", response.MessageCount); Assert.Equal("447700900000", response.Messages[0].To); @@ -145,39 +126,6 @@ public void SendSmsTypicalUsage() Assert.Equal("customer1234", response.Messages[0].AccountRef); } - [Fact] - public void SendSmsTypicalUsageSimplified() - { - var expectedResponse = @"{ - ""message-count"": ""1"", - ""messages"": [ - { - ""to"": ""447700900000"", - ""message-id"": ""0A0000000123ABCD1"", - ""status"": ""0"", - ""remaining-balance"": ""3.14159265"", - ""message-price"": ""0.03330000"", - ""network"": ""12345"", - ""account-ref"": ""customer1234"" - } - ] - }"; - var expectedUri = $"{this.RestUrl}/sms/json"; - var expectedRequestContent = - $"from=AcmeInc&to=447700900000&text={WebUtility.UrlEncode("Hello World!")}&type=text&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - this.Setup(expectedUri, expectedResponse, expectedRequestContent); - var client = this.BuildVonageClient(Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret)); - var response = client.SmsClient.SendAnSms("AcmeInc", "447700900000", "Hello World!"); - Assert.Equal("1", response.MessageCount); - Assert.Equal("447700900000", response.Messages[0].To); - Assert.Equal("0A0000000123ABCD1", response.Messages[0].MessageId); - Assert.Equal("0", response.Messages[0].Status); - Assert.Equal(SmsStatusCode.Success, response.Messages[0].StatusCode); - Assert.Equal("3.14159265", response.Messages[0].RemainingBalance); - Assert.Equal("12345", response.Messages[0].Network); - Assert.Equal("customer1234", response.Messages[0].AccountRef); - } - [Fact] public async Task SendSmsTypicalUsageSimplifiedAsync() { @@ -199,7 +147,7 @@ public async Task SendSmsTypicalUsageSimplifiedAsync() } [Fact] - public void SendSmsUnicode() + public async Task SendSmsUnicode() { var expectedResponse = @"{ ""message-count"": ""1"", @@ -220,7 +168,7 @@ public void SendSmsUnicode() $"from=AcmeInc&to=447700900000&text={WebUtility.UrlEncode("こんにちは世界")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; this.Setup(expectedUri, expectedResponse, expectedRequestContent); var client = this.BuildVonageClient(Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret)); - var response = client.SmsClient.SendAnSms(new SendSmsRequest + var response = await client.SmsClient.SendAnSmsAsync(new SendSmsRequest {From = "AcmeInc", To = "447700900000", Text = "こんにちは世界"}); Assert.Equal("1", response.MessageCount); Assert.Equal("447700900000", response.Messages[0].To); @@ -235,7 +183,7 @@ public void SendSmsUnicode() [Theory] [InlineData(false)] [InlineData(true)] - public void SendSmsWithAllPropertiesSet(bool passCreds) + public async Task SendSmsWithAllPropertiesSet(bool passCreds) { var expectedResponse = this.GetResponseJson(); var expectedUri = $"{this.RestUrl}/sms/json"; @@ -265,8 +213,8 @@ public void SendSmsWithAllPropertiesSet(bool passCreds) this.Setup(expectedUri, expectedResponse, expectedRequestContent); var client = this.BuildVonageClient(creds); var response = passCreds - ? client.SmsClient.SendAnSms(request, creds) - : client.SmsClient.SendAnSms(request); + ? await client.SmsClient.SendAnSmsAsync(request, creds) + : await client.SmsClient.SendAnSmsAsync(request); Assert.Equal("1", response.MessageCount); Assert.Equal("447700900000", response.Messages[0].To); Assert.Equal("0A0000000123ABCD1", response.Messages[0].MessageId); diff --git a/Vonage/Messaging/ISmsClient.cs b/Vonage/Messaging/ISmsClient.cs index 49d9d7b28..f4bed2fef 100644 --- a/Vonage/Messaging/ISmsClient.cs +++ b/Vonage/Messaging/ISmsClient.cs @@ -13,25 +13,6 @@ public interface ISmsClient /// Task SendAnSmsAsync(SendSmsRequest request, Credentials creds = null); - /// - /// Send an outbound SMS from your Vonage account - /// - /// - /// - /// - SendSmsResponse SendAnSms(SendSmsRequest request, Credentials creds = null); - - /// - /// Send an outbound SMS from your Vonage account - /// - /// The name or number the message should be sent from. - /// The number that the message should be sent to. Numbers are specified in E.164 format. - /// The body of the message being sent. - /// The format of the message body. - /// - /// - Task SendAnSmsAsync(string from, string to, string text, SmsType type = SmsType.Text, Credentials creds = null); - /// /// Send an outbound SMS from your Vonage account /// @@ -41,5 +22,6 @@ public interface ISmsClient /// The format of the message body. /// /// - SendSmsResponse SendAnSms(string from, string to, string text, SmsType type = SmsType.Text, Credentials creds = null); + Task SendAnSmsAsync(string from, string to, string text, SmsType type = SmsType.Text, + Credentials creds = null); } \ No newline at end of file diff --git a/Vonage/Messaging/SmsClient.cs b/Vonage/Messaging/SmsClient.cs index 2df9a8ea0..ae45c3259 100644 --- a/Vonage/Messaging/SmsClient.cs +++ b/Vonage/Messaging/SmsClient.cs @@ -1,5 +1,4 @@ -using System; -using System.Threading.Tasks; +using System.Threading.Tasks; using Vonage.Common; using Vonage.Request; @@ -25,25 +24,6 @@ internal SmsClient(Credentials credentials, Configuration configuration, ITimePr public Credentials Credentials { get; set; } - /// - [Obsolete("Favor asynchronous version instead.")] - public SendSmsResponse SendAnSms(SendSmsRequest request, Credentials creds = null) - { - var result = ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoPostRequestUrlContentFromObject( - ApiRequest.GetBaseUri(ApiRequest.UriType.Rest, this.configuration, "/sms/json"), - request - ); - ValidSmsResponse(result); - return result; - } - - /// - [Obsolete("Favor asynchronous version instead.")] - public SendSmsResponse SendAnSms(string from, string to, string text, SmsType type = SmsType.Text, - Credentials creds = null) => - this.SendAnSms(new SendSmsRequest {From = from, To = to, Type = type, Text = text}, creds); - /// /// Send a SMS message. ///