diff --git a/Vonage.Test/AccountTest.cs b/Vonage.Test/AccountTest.cs index 32b2c9ab5..10c846ea5 100644 --- a/Vonage.Test/AccountTest.cs +++ b/Vonage.Test/AccountTest.cs @@ -5,19 +5,19 @@ using Vonage.Request; using Xunit; -namespace Vonage.Test +namespace Vonage.Test; + +[Trait("Category", "Legacy")] +public class AccountTest : TestBase { - [Trait("Category", "Legacy")] - public class AccountTest : TestBase + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void CreateApiSecretAsync(bool passCreds) { - [Theory] - [InlineData(false)] - [InlineData(true)] - public void CreateApiSecret(bool passCreds) - { - //ARRANGE - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets"; - var expectedResponse = @"{ + //ARRANGE + var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets"; + var expectedResponse = @"{ ""_links"": { ""self"": { ""href"": ""abc123"" @@ -26,197 +26,79 @@ public void CreateApiSecret(bool passCreds) ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"", ""created_at"": ""2017-03-02T16:34:49Z"" }"; - this.Setup(expectedUri, expectedResponse); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - Secret secret; - if (passCreds) - { - secret = client.AccountClient.CreateApiSecret(new CreateSecretRequest {Secret = "password"}, - this.ApiKey, creds); - } - else - { - secret = client.AccountClient.CreateApiSecret(new CreateSecretRequest {Secret = "password"}, - this.ApiKey); - } - - //ASSERT - Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secret.Id); - Assert.Equal("2017-03-02T16:34:49Z", secret.CreatedAt); - Assert.Equal("abc123", secret.Links.Self.Href); - Assert.Null(secret.Links.Next); - Assert.Null(secret.Links.Prev); - Assert.Null(secret.Links.First); - Assert.Null(secret.Links.Last); - } + this.Setup(expectedUri, expectedResponse); - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void CreateApiSecretAsync(bool passCreds) + //ACT + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + var client = this.BuildVonageClient(creds); + Secret secret; + if (passCreds) { - //ARRANGE - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets"; - var expectedResponse = @"{ - ""_links"": { - ""self"": { - ""href"": ""abc123"" - } - }, - ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"", - ""created_at"": ""2017-03-02T16:34:49Z"" - }"; - this.Setup(expectedUri, expectedResponse); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - Secret secret; - if (passCreds) - { - secret = await client.AccountClient.CreateApiSecretAsync( - new CreateSecretRequest {Secret = "password"}, this.ApiKey, creds); - } - else - { - secret = await client.AccountClient.CreateApiSecretAsync( - new CreateSecretRequest {Secret = "password"}, this.ApiKey); - } - - //ASSERT - Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secret.Id); - Assert.Equal("2017-03-02T16:34:49Z", secret.CreatedAt); - Assert.Equal("abc123", secret.Links.Self.Href); + secret = await client.AccountClient.CreateApiSecretAsync( + new CreateSecretRequest {Secret = "password"}, this.ApiKey, creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void GetAccountBalance(bool passCreds) + else { - //ARRANGE - var expectedUri = $"{this.RestUrl}/account/get-balance?api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - var expectedResponseContent = @"{""value"": 3.14159, ""autoReload"": false }"; - this.Setup(expectedUri, expectedResponseContent); - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - Balance balance; - if (passCreds) - { - balance = client.AccountClient.GetAccountBalance(creds); - } - else - { - balance = client.AccountClient.GetAccountBalance(); - } - - //ASSERT - Assert.Equal(3.14159m, balance.Value); - Assert.False(balance.AutoReload); + secret = await client.AccountClient.CreateApiSecretAsync( + new CreateSecretRequest {Secret = "password"}, this.ApiKey); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void GetAccountBalanceAsync(bool passCreds) - { - //ARRANGE - var expectedUri = $"{this.RestUrl}/account/get-balance?api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - var expectedResponseContent = @"{""value"": 3.14159, ""autoReload"": false }"; - this.Setup(expectedUri, expectedResponseContent); - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - Balance balance; - if (passCreds) - { - balance = await client.AccountClient.GetAccountBalanceAsync(creds); - } - else - { - balance = await client.AccountClient.GetAccountBalanceAsync(); - } - - //ASSERT - Assert.Equal(3.14159m, balance.Value); - Assert.False(balance.AutoReload); - } + //ASSERT + Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secret.Id); + Assert.Equal("2017-03-02T16:34:49Z", secret.CreatedAt); + Assert.Equal("abc123", secret.Links.Self.Href); + } - [Fact] - public async void GetAccountBalanceAsync_ShouldReturnbalance_GivenCredentialsContainSecuritySecret() + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void GetAccountBalanceAsync(bool passCreds) + { + //ARRANGE + var expectedUri = $"{this.RestUrl}/account/get-balance?api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; + var expectedResponseContent = @"{""value"": 3.14159, ""autoReload"": false }"; + this.Setup(expectedUri, expectedResponseContent); + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + var client = this.BuildVonageClient(creds); + Balance balance; + if (passCreds) { - var mockTimeProvider = new Mock(); - mockTimeProvider.Setup(provider => provider.Epoch).Returns(10); - var expectedUri = - $"{this.RestUrl}/account/get-balance?api_key={this.ApiKey}×tamp=10&sig=1b692bddcdbb74dcafaa0a036a1200c2"; - const string expectedResponseContent = @"{""value"": 3.14159, ""autoReload"": false }"; - this.Setup(expectedUri, expectedResponseContent); - var credentials = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - credentials.SecuritySecret = "yolo"; - var client = new VonageClient(credentials, this.configuration, mockTimeProvider.Object); - var balance = await client.AccountClient.GetAccountBalanceAsync(); - Assert.Equal(3.14159m, balance.Value); - Assert.False(balance.AutoReload); + balance = await client.AccountClient.GetAccountBalanceAsync(creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void RetrieveApiSecrets(bool passCreds) + else { - //ARRANGE - var expectedResponse = @"{ - ""_links"": { - ""self"": { - ""href"": ""abc123"" - } - }, - ""_embedded"": { - ""secrets"": [ - { - ""_links"": { - ""self"": { - ""href"": ""abc123"" - } - }, - ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"", - ""created_at"": ""2017-03-02T16:34:49Z"" - } - ] - } - }"; - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets"; - this.Setup(expectedUri, expectedResponse); + balance = await client.AccountClient.GetAccountBalanceAsync(); + } - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - SecretsRequestResult secrets; - if (passCreds) - { - secrets = client.AccountClient.RetrieveApiSecrets(this.ApiKey, creds); - } - else - { - secrets = client.AccountClient.RetrieveApiSecrets(this.ApiKey); - } + //ASSERT + Assert.Equal(3.14159m, balance.Value); + Assert.False(balance.AutoReload); + } - //ASSERT - Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secrets.Embedded.Secrets[0].Id); - Assert.Equal("2017-03-02T16:34:49Z", secrets.Embedded.Secrets[0].CreatedAt); - Assert.Equal("abc123", secrets.Embedded.Secrets[0].Links.Self.Href); - Assert.Equal("abc123", secrets.Links.Self.Href); - } + [Fact] + public async void GetAccountBalanceAsync_ShouldReturnBalance_GivenCredentialsContainSecuritySecret() + { + var mockTimeProvider = new Mock(); + mockTimeProvider.Setup(provider => provider.Epoch).Returns(10); + var expectedUri = + $"{this.RestUrl}/account/get-balance?api_key={this.ApiKey}×tamp=10&sig=1b692bddcdbb74dcafaa0a036a1200c2"; + const string expectedResponseContent = @"{""value"": 3.14159, ""autoReload"": false }"; + this.Setup(expectedUri, expectedResponseContent); + var credentials = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + credentials.SecuritySecret = "yolo"; + var client = new VonageClient(credentials, this.configuration, mockTimeProvider.Object); + var balance = await client.AccountClient.GetAccountBalanceAsync(); + Assert.Equal(3.14159m, balance.Value); + Assert.False(balance.AutoReload); + } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void RetrieveApiSecretsAsync(bool passCreds) - { - //ARRANGE - var expectedResponse = @"{ + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void RetrieveApiSecretsAsync(bool passCreds) + { + //ARRANGE + var expectedResponse = @"{ ""_links"": { ""self"": { ""href"": ""abc123"" @@ -236,76 +118,38 @@ public async void RetrieveApiSecretsAsync(bool passCreds) ] } }"; - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets"; - this.Setup(expectedUri, expectedResponse); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - SecretsRequestResult secrets; - if (passCreds) - { - secrets = await client.AccountClient.RetrieveApiSecretsAsync(this.ApiKey, creds); - } - else - { - secrets = await client.AccountClient.RetrieveApiSecretsAsync(this.ApiKey); - } - - //ASSERT - Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secrets.Embedded.Secrets[0].Id); - Assert.Equal("2017-03-02T16:34:49Z", secrets.Embedded.Secrets[0].CreatedAt); - Assert.Equal("abc123", secrets.Embedded.Secrets[0].Links.Self.Href); - Assert.Equal("abc123", secrets.Links.Self.Href); + var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets"; + this.Setup(expectedUri, expectedResponse); + + //ACT + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + var client = this.BuildVonageClient(creds); + SecretsRequestResult secrets; + if (passCreds) + { + secrets = await client.AccountClient.RetrieveApiSecretsAsync(this.ApiKey, creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void RetrieveSecret(bool passCreds) + else { - //ARRANGE - var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"; - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets/{secretId}"; - var expectedResponse = @"{ - ""_links"": { - ""self"": { - ""href"": ""abc123"" - } - }, - ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"", - ""created_at"": ""2017-03-02T16:34:49Z"" - }"; - this.Setup(expectedUri, expectedResponse); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - Secret secret; - if (passCreds) - { - secret = client.AccountClient.RetrieveApiSecret(secretId, this.ApiKey, creds); - } - else - { - secret = client.AccountClient.RetrieveApiSecret(secretId, this.ApiKey); - } - - //ASSERT - Assert.Equal(secretId, secret.Id); - Assert.Equal("2017-03-02T16:34:49Z", secret.CreatedAt); - Assert.Equal("abc123", secret.Links.Self.Href); + secrets = await client.AccountClient.RetrieveApiSecretsAsync(this.ApiKey); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void RetrieveSecretAsync(bool passCreds) - { - //ARRANGE - var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"; - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets/{secretId}"; - var expectedResponse = @"{ + //ASSERT + Assert.Equal("ad6dc56f-07b5-46e1-a527-85530e625800", secrets.Embedded.Secrets[0].Id); + Assert.Equal("2017-03-02T16:34:49Z", secrets.Embedded.Secrets[0].CreatedAt); + Assert.Equal("abc123", secrets.Embedded.Secrets[0].Links.Self.Href); + Assert.Equal("abc123", secrets.Links.Self.Href); + } + + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void RetrieveSecretAsync(bool passCreds) + { + //ARRANGE + var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"; + var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets/{secretId}"; + var expectedResponse = @"{ ""_links"": { ""self"": { ""href"": ""abc123"" @@ -314,227 +158,125 @@ public async void RetrieveSecretAsync(bool passCreds) ""id"": ""ad6dc56f-07b5-46e1-a527-85530e625800"", ""created_at"": ""2017-03-02T16:34:49Z"" }"; - this.Setup(expectedUri, expectedResponse); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - Secret secret; - if (passCreds) - { - secret = await client.AccountClient.RetrieveApiSecretAsync(secretId, this.ApiKey, creds); - } - else - { - secret = await client.AccountClient.RetrieveApiSecretAsync(secretId, this.ApiKey); - } + this.Setup(expectedUri, expectedResponse); - //ASSERT - Assert.Equal(secretId, secret.Id); - Assert.Equal("2017-03-02T16:34:49Z", secret.CreatedAt); - Assert.Equal("abc123", secret.Links.Self.Href); + //ACT + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + var client = this.BuildVonageClient(creds); + Secret secret; + if (passCreds) + { + secret = await client.AccountClient.RetrieveApiSecretAsync(secretId, this.ApiKey, creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public void RevokeSecret(bool passCreds) + else { - //ARRANGE - var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"; - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets/{secretId}"; - var expectedResponse = @""; - this.Setup(expectedUri, expectedResponse); + secret = await client.AccountClient.RetrieveApiSecretAsync(secretId, this.ApiKey); + } - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - bool response; - if (passCreds) - { - response = client.AccountClient.RevokeApiSecret(secretId, this.ApiKey, creds); - } - else - { - response = client.AccountClient.RevokeApiSecret(secretId, this.ApiKey); - } + //ASSERT + Assert.Equal(secretId, secret.Id); + Assert.Equal("2017-03-02T16:34:49Z", secret.CreatedAt); + Assert.Equal("abc123", secret.Links.Self.Href); + } - //ASSERT - Assert.True(response); + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void RevokeSecretAsync(bool passCreds) + { + //ARRANGE + var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"; + var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets/{secretId}"; + var expectedResponse = @""; + this.Setup(expectedUri, expectedResponse); + + //ACT + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + var client = this.BuildVonageClient(creds); + bool response; + if (passCreds) + { + response = await client.AccountClient.RevokeApiSecretAsync(secretId, this.ApiKey, creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void RevokeSecretAsync(bool passCreds) + else { - //ARRANGE - var secretId = "ad6dc56f-07b5-46e1-a527-85530e625800"; - var expectedUri = $"https://api.nexmo.com/accounts/{this.ApiKey}/secrets/{secretId}"; - var expectedResponse = @""; - this.Setup(expectedUri, expectedResponse); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - bool response; - if (passCreds) - { - response = await client.AccountClient.RevokeApiSecretAsync(secretId, this.ApiKey, creds); - } - else - { - response = await client.AccountClient.RevokeApiSecretAsync(secretId, this.ApiKey); - } - - //ASSERT - Assert.True(response); + response = await client.AccountClient.RevokeApiSecretAsync(secretId, this.ApiKey); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public void SetSettings(bool passCreds) - { - //ARRANGE - var expectedUri = $"{this.RestUrl}/account/settings"; - var expectedRequestContents = - $"moCallBackUrl={WebUtility.UrlEncode("https://example.com/webhooks/inbound-sms")}&drCallBackUrl={WebUtility.UrlEncode("https://example.com/webhooks/delivery-receipt")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - var expectedResponseContent = - @"{""mo-callback-url"": ""https://example.com/webhooks/inbound-sms"",""dr-callback-url"": ""https://example.com/webhooks/delivery-receipt"",""max-outbound-request"": 15,""max-inbound-request"": 30,""max-calls-per-second"": 4}"; - this.Setup(expectedUri, expectedResponseContent, - expectedRequestContents); + //ASSERT + Assert.True(response); + } - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - AccountSettingsResult result; - if (passCreds) - { - result = client.AccountClient.ChangeAccountSettings( - new AccountSettingsRequest - { - MoCallBackUrl = "https://example.com/webhooks/inbound-sms", - DrCallBackUrl = "https://example.com/webhooks/delivery-receipt", - }, creds); - } - else - { - result = client.AccountClient.ChangeAccountSettings(new AccountSettingsRequest + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void SetSettingsAsync(bool passCreds) + { + //ARRANGE + var expectedUri = $"{this.RestUrl}/account/settings"; + var expectedRequestContents = + $"moCallBackUrl={WebUtility.UrlEncode("https://example.com/webhooks/inbound-sms")}&drCallBackUrl={WebUtility.UrlEncode("https://example.com/webhooks/delivery-receipt")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; + var expectedResponseContent = + @"{""mo-callback-url"": ""https://example.com/webhooks/inbound-sms"",""dr-callback-url"": ""https://example.com/webhooks/delivery-receipt"",""max-outbound-request"": 15,""max-inbound-request"": 30,""max-calls-per-second"": 4}"; + this.Setup(expectedUri, expectedResponseContent, + expectedRequestContents); + + //ACT + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + var client = this.BuildVonageClient(creds); + AccountSettingsResult result; + if (passCreds) + { + result = await client.AccountClient.ChangeAccountSettingsAsync( + new AccountSettingsRequest { MoCallBackUrl = "https://example.com/webhooks/inbound-sms", DrCallBackUrl = "https://example.com/webhooks/delivery-receipt", - }); - } - - //ASSERT - Assert.Equal("https://example.com/webhooks/delivery-receipt", result.DrCallbackurl); - Assert.Equal("https://example.com/webhooks/inbound-sms", result.MoCallbackUrl); - Assert.Equal(4, result.MaxCallsPerSecond); - Assert.Equal(30, result.MaxInboundRequest); - Assert.Equal(15, result.MaxOutboundRequest); + }, creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void SetSettingsAsync(bool passCreds) + else { - //ARRANGE - var expectedUri = $"{this.RestUrl}/account/settings"; - var expectedRequestContents = - $"moCallBackUrl={WebUtility.UrlEncode("https://example.com/webhooks/inbound-sms")}&drCallBackUrl={WebUtility.UrlEncode("https://example.com/webhooks/delivery-receipt")}&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - var expectedResponseContent = - @"{""mo-callback-url"": ""https://example.com/webhooks/inbound-sms"",""dr-callback-url"": ""https://example.com/webhooks/delivery-receipt"",""max-outbound-request"": 15,""max-inbound-request"": 30,""max-calls-per-second"": 4}"; - this.Setup(expectedUri, expectedResponseContent, - expectedRequestContents); - - //ACT - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - var client = this.BuildVonageClient(creds); - AccountSettingsResult result; - if (passCreds) - { - result = await client.AccountClient.ChangeAccountSettingsAsync( - new AccountSettingsRequest - { - MoCallBackUrl = "https://example.com/webhooks/inbound-sms", - DrCallBackUrl = "https://example.com/webhooks/delivery-receipt", - }, creds); - } - else + result = await client.AccountClient.ChangeAccountSettingsAsync(new AccountSettingsRequest { - result = await client.AccountClient.ChangeAccountSettingsAsync(new AccountSettingsRequest - { - MoCallBackUrl = "https://example.com/webhooks/inbound-sms", - DrCallBackUrl = "https://example.com/webhooks/delivery-receipt", - }); - } - - //ASSERT - Assert.Equal("https://example.com/webhooks/delivery-receipt", result.DrCallbackurl); - Assert.Equal("https://example.com/webhooks/inbound-sms", result.MoCallbackUrl); - Assert.Equal(4, result.MaxCallsPerSecond); - Assert.Equal(30, result.MaxInboundRequest); - Assert.Equal(15, result.MaxOutboundRequest); + MoCallBackUrl = "https://example.com/webhooks/inbound-sms", + DrCallBackUrl = "https://example.com/webhooks/delivery-receipt", + }); } - [Theory] - [InlineData(false)] - [InlineData(true)] - public void TopUp(bool passCreds) - { - //ARRANGE - var expectedUri = - $"{this.RestUrl}/account/top-up?trx=00X123456Y7890123Z&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - var expectedResponseContent = @"{""response"":""abc123""}"; - this.Setup(expectedUri, expectedResponseContent); - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - - //Act - var client = this.BuildVonageClient(creds); - TopUpResult response; - if (passCreds) - { - response = client.AccountClient.TopUpAccountBalance( - new TopUpRequest {Trx = "00X123456Y7890123Z"}, creds); - } - else - { - response = client.AccountClient.TopUpAccountBalance(new TopUpRequest - {Trx = "00X123456Y7890123Z"}); - } + //ASSERT + Assert.Equal("https://example.com/webhooks/delivery-receipt", result.DrCallbackurl); + Assert.Equal("https://example.com/webhooks/inbound-sms", result.MoCallbackUrl); + Assert.Equal(4, result.MaxCallsPerSecond); + Assert.Equal(30, result.MaxInboundRequest); + Assert.Equal(15, result.MaxOutboundRequest); + } - Assert.Equal("abc123", response.Response); + [Theory] + [InlineData(false)] + [InlineData(true)] + public async void TopUpAsync(bool passCreds) + { + //ARRANGE + var expectedUri = + $"{this.RestUrl}/account/top-up?trx=00X123456Y7890123Z&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; + var expectedResponseContent = @"{""response"":""abc123""}"; + this.Setup(expectedUri, expectedResponseContent); + var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); + + //Act + var client = this.BuildVonageClient(creds); + TopUpResult response; + if (passCreds) + { + response = await client.AccountClient.TopUpAccountBalanceAsync( + new TopUpRequest {Trx = "00X123456Y7890123Z"}, creds); } - - [Theory] - [InlineData(false)] - [InlineData(true)] - public async void TopUpAsync(bool passCreds) + else { - //ARRANGE - var expectedUri = - $"{this.RestUrl}/account/top-up?trx=00X123456Y7890123Z&api_key={this.ApiKey}&api_secret={this.ApiSecret}&"; - var expectedResponseContent = @"{""response"":""abc123""}"; - this.Setup(expectedUri, expectedResponseContent); - var creds = Credentials.FromApiKeyAndSecret(this.ApiKey, this.ApiSecret); - - //Act - var client = this.BuildVonageClient(creds); - TopUpResult response; - if (passCreds) - { - response = await client.AccountClient.TopUpAccountBalanceAsync( - new TopUpRequest {Trx = "00X123456Y7890123Z"}, creds); - } - else - { - response = await client.AccountClient.TopUpAccountBalanceAsync(new TopUpRequest - {Trx = "00X123456Y7890123Z"}); - } - - Assert.Equal("abc123", response.Response); + response = await client.AccountClient.TopUpAccountBalanceAsync(new TopUpRequest + {Trx = "00X123456Y7890123Z"}); } + + Assert.Equal("abc123", response.Response); } } \ No newline at end of file diff --git a/Vonage/Accounts/AccountClient.cs b/Vonage/Accounts/AccountClient.cs index eb73e5674..5752884be 100644 --- a/Vonage/Accounts/AccountClient.cs +++ b/Vonage/Accounts/AccountClient.cs @@ -1,5 +1,4 @@ -using System; -using System.Net.Http; +using System.Net.Http; using System.Threading.Tasks; using Vonage.Common; using Vonage.Request; @@ -26,17 +25,7 @@ internal AccountClient(Credentials creds, Configuration configuration, ITimeProv public Credentials Credentials { get; set; } - /// - [Obsolete("Favor asynchronous version instead.")] - public AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest request, Credentials creds = null) => - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoPostRequestUrlContentFromObject - ( - ApiRequest.GetBaseUriFor(this.configuration, "/account/settings"), - request - ); - - /// + /// public Task ChangeAccountSettingsAsync(AccountSettingsRequest request, Credentials creds = null) => ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) @@ -46,18 +35,7 @@ public Task ChangeAccountSettingsAsync(AccountSettingsReq request ); - /// - [Obsolete("Favor asynchronous version instead.")] - public Secret CreateApiSecret(CreateSecretRequest request, string apiKey = null, Credentials creds = null) => - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoRequestWithJsonContent( - HttpMethod.Post, - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, $"/accounts/{apiKey}/secrets"), - request, - AuthType.Basic - ); - - /// + /// public Task CreateApiSecretAsync(CreateSecretRequest request, string apiKey = null, Credentials creds = null) => ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) @@ -68,64 +46,14 @@ public Task CreateApiSecretAsync(CreateSecretRequest request, string api AuthType.Basic ); - /// - [Obsolete("Use SubAccountsClient instead.")] - public SubAccount CreateSubAccount(CreateSubAccountRequest request, string apiKey = null, - Credentials creds = null) - { - var credentials = this.GetCredentials(creds); - var accountId = apiKey ?? credentials.ApiKey; - return ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoRequestWithJsonContent( - HttpMethod.Post, - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, $"/accounts/{accountId}/subaccounts"), - request, - AuthType.Basic - ); - } - - /// - [Obsolete("Use SubAccountsClient instead.")] - public Task CreateSubAccountAsync(CreateSubAccountRequest request, string apiKey = null, - Credentials creds = null) - { - var credentials = this.GetCredentials(creds); - var accountId = apiKey ?? credentials.ApiKey; - return ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoRequestWithJsonContentAsync( - HttpMethod.Post, - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, $"/accounts/{accountId}/subaccounts"), - request, - AuthType.Basic - ); - } - - /// - [Obsolete("Favor asynchronous version instead.")] - public Balance GetAccountBalance(Credentials creds = null) => - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoGetRequestWithQueryParameters( - ApiRequest.GetBaseUriFor(this.configuration, "/account/get-balance"), - AuthType.Query); - - /// + /// public Task GetAccountBalanceAsync(Credentials creds = null) => ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) .DoGetRequestWithQueryParametersAsync( ApiRequest.GetBaseUriFor(this.configuration, "/account/get-balance"), AuthType.Query); - /// - [Obsolete("Favor asynchronous version instead.")] - public Secret RetrieveApiSecret(string secretId, string apiKey = null, Credentials creds = null) => - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoGetRequestWithQueryParameters( - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, - $"/accounts/{apiKey}/secrets/{secretId}"), - AuthType.Basic - ); - - /// + /// public Task RetrieveApiSecretAsync(string secretId, string apiKey = null, Credentials creds = null) => ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) .DoGetRequestWithQueryParametersAsync( @@ -134,16 +62,7 @@ public Task RetrieveApiSecretAsync(string secretId, string apiKey = null AuthType.Basic ); - /// - [Obsolete("Favor asynchronous version instead.")] - public SecretsRequestResult RetrieveApiSecrets(string apiKey = null, Credentials creds = null) => - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoGetRequestWithQueryParameters( - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, $"/accounts/{apiKey}/secrets"), - AuthType.Basic - ); - - /// + /// public Task RetrieveApiSecretsAsync(string apiKey = null, Credentials creds = null) => ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) .DoGetRequestWithQueryParametersAsync( @@ -151,50 +70,7 @@ public Task RetrieveApiSecretsAsync(string apiKey = null, AuthType.Basic ); - /// - [Obsolete("Use SubAccountsClient instead.")] - public SubAccount RetrieveSubAccount(string subAccountKey, string apiKey = null, Credentials creds = null) - { - var credentials = this.GetCredentials(creds); - var accountId = apiKey ?? credentials.ApiKey; - return ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoGetRequestWithQueryParameters( - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, - $"/accounts/{accountId}/subaccounts/{subAccountKey}"), - AuthType.Basic - ); - } - - /// - [Obsolete("Use SubAccountsClient instead.")] - public Task RetrieveSubAccountAsync(string subAccountKey, string apiKey = null, - Credentials creds = null) - { - var credentials = this.GetCredentials(creds); - var accountId = apiKey ?? credentials.ApiKey; - return ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoGetRequestWithQueryParametersAsync( - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, - $"/accounts/{accountId}/subaccounts/{subAccountKey}"), - AuthType.Basic - ); - } - - /// - [Obsolete("Favor asynchronous version instead.")] - public bool RevokeApiSecret(string secretId, string apiKey = null, Credentials creds = null) - { - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoDeleteRequestWithUrlContent( - ApiRequest.GetBaseUri(ApiRequest.UriType.Api, this.configuration, - $"/accounts/{apiKey}/secrets/{secretId}"), - null, - AuthType.Basic - ); - return true; - } - - /// + /// public async Task RevokeApiSecretAsync(string secretId, string apiKey = null, Credentials creds = null) { await ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) @@ -207,17 +83,7 @@ await ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.time return true; } - /// - [Obsolete("Favor asynchronous version instead.")] - public TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = null) => - ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) - .DoGetRequestWithQueryParameters( - ApiRequest.GetBaseUriFor(this.configuration, "/account/top-up"), - AuthType.Query, - request - ); - - /// + /// public Task TopUpAccountBalanceAsync(TopUpRequest request, Credentials creds = null) => ApiRequest.Build(this.GetCredentials(creds), this.configuration, this.timeProvider) .DoGetRequestWithQueryParametersAsync( diff --git a/Vonage/Accounts/IAccountClient.cs b/Vonage/Accounts/IAccountClient.cs index 906077354..a195ec97c 100644 --- a/Vonage/Accounts/IAccountClient.cs +++ b/Vonage/Accounts/IAccountClient.cs @@ -6,18 +6,19 @@ namespace Vonage.Accounts; public interface IAccountClient { /// - /// Retrieve the current balance of your Vonage API account + /// Retrieve the current balance of your Vonage API account /// /// /// Task GetAccountBalanceAsync(Credentials creds = null); /// - /// You can top up your account using this API when you have enabled auto-reload in the dashboard. - /// The amount added by the top-up operation will be the same amount as was added in the payment - /// when auto-reload was enabled. Your account balance is checked every 5-10 minutes and if it falls - /// below the threshold and auto-reload is enabled, then it will be topped up automatically. Use this - /// endpoint if you need to top up at times when your credit may be exhausted more quickly than the auto-reload may occur. + /// You can top up your account using this API when you have enabled auto-reload in the dashboard. + /// The amount added by the top-up operation will be the same amount as was added in the payment + /// when auto-reload was enabled. Your account balance is checked every 5-10 minutes and if it falls + /// below the threshold and auto-reload is enabled, then it will be topped up automatically. Use this + /// endpoint if you need to top up at times when your credit may be exhausted more quickly than the auto-reload may + /// occur. /// /// /// @@ -25,9 +26,10 @@ public interface IAccountClient Task TopUpAccountBalanceAsync(TopUpRequest request, Credentials creds = null); /// - /// Update the default callback URLs (where the webhooks are sent to) associated with your account: - /// * Callback URL for incoming SMS messages * Callback URL for delivery receipts - /// Note: that the URLs you provide must be valid and active. Vonage will check that they return a 200 OK response before the setting is saved + /// Update the default callback URLs (where the webhooks are sent to) associated with your account: + /// * Callback URL for incoming SMS messages * Callback URL for delivery receipts + /// Note: that the URLs you provide must be valid and active. Vonage will check that they return a 200 OK response + /// before the setting is saved /// /// /// @@ -35,143 +37,40 @@ public interface IAccountClient Task ChangeAccountSettingsAsync(AccountSettingsRequest request, Credentials creds = null); /// - /// Many of Vonage's APIs are accessed using an API key and secret. It is recommended that you change or "rotate" - /// your secrets from time to time for security purposes. This section provides the API interface for achieving this. - /// Note: to work on secrets for your secondary accounts, you may authenticate with your primary - /// credentials and supply the secondary API keys as URL parameters to these API endpoints. + /// Many of Vonage's APIs are accessed using an API key and secret. It is recommended that you change or "rotate" + /// your secrets from time to time for security purposes. This section provides the API interface for achieving this. + /// Note: to work on secrets for your secondary accounts, you may authenticate with your primary + /// credentials and supply the secondary API keys as URL parameters to these API endpoints. /// /// /// /// - Task RetrieveApiSecretsAsync(string apiKey=null, Credentials creds = null); + Task RetrieveApiSecretsAsync(string apiKey = null, Credentials creds = null); /// - /// Createse an API Secret + /// Createse an API Secret /// /// /// The Api Key to create a secret for /// /// - Task CreateApiSecretAsync(CreateSecretRequest request, string apiKey=null, Credentials creds = null); + Task CreateApiSecretAsync(CreateSecretRequest request, string apiKey = null, Credentials creds = null); /// - /// retrieves info about an api secret at the given id + /// retrieves info about an api secret at the given id /// /// the id of the secret /// Api Key the secret is for /// /// - Task RetrieveApiSecretAsync(string secretId, string apiKey=null, Credentials creds = null); + Task RetrieveApiSecretAsync(string secretId, string apiKey = null, Credentials creds = null); /// - /// Deletes an Api Secret + /// Deletes an Api Secret /// /// the id of the secret to be deleted /// the api key the secret is for /// /// - Task RevokeApiSecretAsync(string secretId, string apiKey=null, Credentials creds = null); - - /// - /// Create a new sub account - /// - /// - /// - /// - /// - Task CreateSubAccountAsync(CreateSubAccountRequest request, string apiKey = null, Credentials creds = null); - - /// - /// Retrieve a sub account - /// - /// - /// - /// - /// - Task RetrieveSubAccountAsync(string subAccountKey, string apiKey = null, Credentials creds = null); - - /// - /// Create a new sub account - /// - /// - /// - /// - /// - SubAccount CreateSubAccount(CreateSubAccountRequest request, string apiKey = null, Credentials creds = null); - - /// - /// Retrieve a sub account - /// - /// - /// - /// - /// - SubAccount RetrieveSubAccount(string subAccountKey, string apiKey = null, Credentials creds = null); - - /// - /// Retrieve the current balance of your Vonage API account - /// - /// - /// - Balance GetAccountBalance(Credentials creds = null); - - /// - /// You can top up your account using this API when you have enabled auto-reload in the dashboard. - /// The amount added by the top-up operation will be the same amount as was added in the payment - /// when auto-reload was enabled. Your account balance is checked every 5-10 minutes and if it falls - /// below the threshold and auto-reload is enabled, then it will be topped up automatically. Use this - /// endpoint if you need to top up at times when your credit may be exhausted more quickly than the auto-reload may occur. - /// - /// - /// - /// - TopUpResult TopUpAccountBalance(TopUpRequest request, Credentials creds = null); - - /// - /// Update the default callback URLs (where the webhooks are sent to) associated with your account: - /// * Callback URL for incoming SMS messages * Callback URL for delivery receipts - /// Note: that the URLs you provide must be valid and active. Vonage will check that they return a 200 OK response before the setting is saved - /// - /// - /// - /// - AccountSettingsResult ChangeAccountSettings(AccountSettingsRequest request, Credentials creds = null); - - /// - /// Many of Vonage's APIs are accessed using an API key and secret. It is recommended that you change or "rotate" - /// your secrets from time to time for security purposes. This section provides the API interface for achieving this. - /// Note: to work on secrets for your secondary accounts, you may authenticate with your primary - /// credentials and supply the secondary API keys as URL parameters to these API endpoints. - /// - /// - /// - /// - SecretsRequestResult RetrieveApiSecrets(string apiKey = null, Credentials creds = null); - - /// - /// Createse an API Secret - /// - /// - /// The Api Key to create a secret for - /// - /// - Secret CreateApiSecret(CreateSecretRequest request, string apiKey = null, Credentials creds = null); - - /// - /// retrieves info about an api secret at the given id - /// - /// the id of the secret - /// Api Key the secret is for - /// - /// - Secret RetrieveApiSecret(string secretId, string apiKey = null, Credentials creds = null); - - /// - /// Deletes an Api Secret - /// - /// the id of the secret to be deleted - /// the api key the secret is for - /// - /// - bool RevokeApiSecret(string secretId, string apiKey = null, Credentials creds = null); + Task RevokeApiSecretAsync(string secretId, string apiKey = null, Credentials creds = null); } \ No newline at end of file