From 2f24b340fe78d54e2d1ae1f358ed12b2819a1608 Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Thu, 28 Sep 2023 14:36:41 -0400 Subject: [PATCH 1/8] SWI-1632: Working on API integration tests --- .../Api/MFAApiTests.cs | 8 +- .../Api/StatisticsApiTests.cs | 2 +- .../Integration/CallsIntegrationTests.cs | 390 +++++++++++ .../ConferencesIntegrationTests.cs | 416 +++++++++++ .../Integration/MFAIntegrationTests.cs | 208 ++++++ .../Integration/MediaIntegrationTests.cs | 159 +++++ .../Integration/MessagesIntegrationTests.cs | 199 ++++++ .../PhoneNumberLookupIntegrationTests.cs | 158 +++++ .../Integration/RecordingsIntegrationTests.cs | 659 ++++++++++++++++++ .../Integration/StatisticsIntegrationTests.cs | 67 ++ 10 files changed, 2258 insertions(+), 8 deletions(-) create mode 100644 src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs create mode 100644 src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs diff --git a/src/Bandwidth.Standard.Test/Api/MFAApiTests.cs b/src/Bandwidth.Standard.Test/Api/MFAApiTests.cs index 770b37cd..7a8f4841 100644 --- a/src/Bandwidth.Standard.Test/Api/MFAApiTests.cs +++ b/src/Bandwidth.Standard.Test/Api/MFAApiTests.cs @@ -9,12 +9,6 @@ */ using System; -using System.IO; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; @@ -91,7 +85,7 @@ public void GenerateVoiceCodeTest() var response = instance.GenerateVoiceCodeWithHttpInfo(accountId, codeRequest); Assert.IsType>(response); - Assert.Equal(HttpStatusCode.OK, apiResponse.StatusCode); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } /// diff --git a/src/Bandwidth.Standard.Test/Api/StatisticsApiTests.cs b/src/Bandwidth.Standard.Test/Api/StatisticsApiTests.cs index 830c7539..ee6d2caf 100644 --- a/src/Bandwidth.Standard.Test/Api/StatisticsApiTests.cs +++ b/src/Bandwidth.Standard.Test/Api/StatisticsApiTests.cs @@ -40,7 +40,7 @@ public StatisticsApiTests() mockClient = new Mock(); mockAsynchronousClient = new Mock(); fakeConfiguration = new Configuration(); - fakeConfiguration.BasePath = "https://numbers.bandwidth.com/api/v1"; + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; fakeConfiguration.Username = "username"; fakeConfiguration.Password = "password"; instance = new StatisticsApi(mockClient.Object, mockAsynchronousClient.Object, fakeConfiguration); diff --git a/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs new file mode 100644 index 00000000..67f67ac3 --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs @@ -0,0 +1,390 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing CallsApi + /// + public class CallsIntegrationTests : IDisposable + { + private CallsApi instance; + private CallsApi unauthorizedInstance; + private CallsApi forbiddenInstance; + private Configuration fakeConfiguration; + private CreateCall createCallBody; + private CreateCall mantecaCallBody; + private UpdateCall fakeUpdateCall; + private string accountId; + public CallsIntegrationTests() + { + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + instance = new CallsApi(fakeConfiguration); + + // Unauthorized API Client + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new CallsApi(fakeConfiguration); + + // Forbidden API Client + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); + forbiddenInstance = new CallsApi(fakeConfiguration); + + + + createCallBody = new CreateCall( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + from: Environment.GetEnvironmentVariable("BW_NUMBER"), + displayName: "Test Call", + applicationId: Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), + answerUrl: Environment.GetEnvironmentVariable("BASE_CALLBACK_URL"), + answerMethod: CallbackMethodEnum.POST, + username: "mySecretUsername", + password: "mySecretPassword!", + answerFallbackUrl: "https://www.myFallbackServer.com/webhooks/answer", + answerFallbackMethod: CallbackMethodEnum.POST, + fallbackUsername: "mySecretUsername", + fallbackPassword: "mySecretPassword!", + disconnectUrl: "https://myServer.com/bandwidth/webhooks/disconnectUrl", + disconnectMethod: CallbackMethodEnum.POST, + callTimeout: 30, + callbackTimeout: 15, + machineDetection: new MachineDetectionConfiguration( + mode: MachineDetectionModeEnum.Async, + detectionTimeout: 15, + silenceTimeout: 10, + speechThreshold: 10, + speechEndThreshold: 5, + machineSpeechEndThreshold: 5, + delayResult: false, + callbackUrl: "https://myServer.com/bandwidth/webhooks/machineDetectionComplete", + callbackMethod: CallbackMethodEnum.POST, + username: "MySecretUsername", + password: "MySecretPassword!", + fallbackUrl: "https://myFallbackServer.com/bandwidth/webhooks/machineDetectionComplete", + fallbackMethod: CallbackMethodEnum.POST, + fallbackUsername: "MySecretUsername", + fallbackPassword: "MySecretPassword!" + ), + priority: 5, + tag: "tag Example" + ); + + mantecaCallBody = new CreateCall( + to: Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"), + from: Environment.GetEnvironmentVariable("MANTECA_ACTIVE_NUMBER"), + applicationId: Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"), + answerUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/pause" + ); + + fakeUpdateCall = new UpdateCall( + state: CallStateEnum.Active, + redirectUrl: "https://www.myCallbackServer.example/webhooks/redirect", + redirectMethod: RedirectMethodEnum.POST, + username: Environment.GetEnvironmentVariable("BW_USERNAME"), + password: Environment.GetEnvironmentVariable("BW_PASSWORD"), + redirectFallbackUrl: "https://myFallbackServer.example/bandwidth/webhooks/redirect", + redirectFallbackMethod: RedirectMethodEnum.POST, + fallbackUsername: "fallbackUsername", + fallbackPassword: "fallbackPassword", + tag: "My Custom Tag" + ); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test CreateCall + /// + [Fact] + public void CreateCallTest() + { + ApiResponse response = instance.CreateCallWithHttpInfo(accountId, createCallBody); + Assert.Equal(HttpStatusCode.Created, response.StatusCode); + Assert.IsType(response.Data.CallId); + Assert.Equal(Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"), response.Data.AccountId); + Assert.Equal(Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), response.Data.ApplicationId); + Assert.Equal(Environment.GetEnvironmentVariable("USER_NUMBER"), response.Data.To); + Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), response.Data.From); + } + + /// + /// Test Create Call bad request + /// + [Fact] + public void CreateCallBadRequestTest() + { + createCallBody.To = "not a phone number"; + ApiException Exception = Assert.Throws(() => instance.CreateCallWithHttpInfo(accountId, createCallBody)); + Assert.Equal(400, Exception.ErrorCode); + } + + /// + /// Test Create Call unauthorized request + /// + [Fact] + public void CreateCallUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.CreateCallWithHttpInfo(accountId, createCallBody)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Create Call forbidden request + /// + [Fact] + public void CreateCallForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.CreateCallWithHttpInfo(accountId, createCallBody)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Get Call State + /// + [Fact] + public void GetCallStateTest() + { + CreateCallResponse createCallResponse = instance.CreateCall(accountId, createCallBody); + var callId = createCallResponse.CallId; + + System.Threading.Thread.Sleep(5000); + + ApiResponse response = instance.GetCallStateWithHttpInfo(accountId, callId); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.Equal(callId, response.Data.CallId); + Assert.IsType(response.Data.CallId); + Assert.Equal(CallDirectionEnum.Outbound, response.Data.Direction); + Assert.IsType(response.Data.EnqueuedTime); + Assert.IsType(response.Data.LastUpdate); + Assert.IsType(response.Data.StartTime); + } + + /// + /// Test Get Call State unauthorized request + /// + [Fact] + public void GetCallStateUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetCallStateWithHttpInfo(accountId, "Call-Id")); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Get Call State forbidden request + /// + [Fact] + public void GetCallStateForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GetCallStateWithHttpInfo(accountId, "Call-Id")); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Get Call State not found request + /// + [Fact] + public void GetCallStateNotFoundRequest() + { + ApiException Exception = Assert.Throws(() => instance.GetCallStateWithHttpInfo(accountId, "Call-Id")); + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Update Call + /// + [Fact] + public void UpdateCallTest() + { + CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); + string callId = createCallResponse.CallId; + + var updateCallBody = new UpdateCall( + state: CallStateEnum.Active, + redirectUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/pause", + redirectMethod: RedirectMethodEnum.POST, + username: "mySecretUsername", + password: "mySecretPassword!", + redirectFallbackUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/pause", + redirectFallbackMethod: RedirectMethodEnum.POST, + fallbackUsername: "mySecretUsername", + fallbackPassword: "mySecretPassword!", + tag: "My Custom Tag" + ); + + System.Threading.Thread.Sleep(5000); + ApiResponse response = instance.UpdateCallWithHttpInfo(accountId, callId, updateCallBody); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + System.Threading.Thread.Sleep(5000); + //Hanging up the call + updateCallBody.State = CallStateEnum.Completed; + response = instance.UpdateCallWithHttpInfo(accountId, callId, updateCallBody); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test Update Call bad request + /// + [Fact] + public void UpdateCallBadRequest() + { + CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); + string callId = createCallResponse.CallId; + + System.Threading.Thread.Sleep(5000); + + fakeUpdateCall.State = null; + ApiException Exception = Assert.Throws(() => instance.UpdateCall(accountId, callId, fakeUpdateCall)); + Assert.Equal(400, Exception.ErrorCode); + + //Hanging up the call + fakeUpdateCall.State = CallStateEnum.Completed; + var updateCallResponse = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); + Assert.Equal(HttpStatusCode.OK, updateCallResponse.StatusCode); + } + + /// + /// Test Update Call unauthorized request + /// + [Fact] + public void UpdateCallUnauthorizedRequest() + { + fakeUpdateCall.State = CallStateEnum.Completed; + + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateCallWithHttpInfo(accountId, "Call-Id", fakeUpdateCall)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Update Call forbidden request + /// + [Fact] + public void UpdateCallForbiddenRequest() + { + CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); + + string callId = createCallResponse.CallId; + System.Threading.Thread.Sleep(5000); + fakeUpdateCall.State = CallStateEnum.Completed; + + ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateCall(accountId, callId, fakeUpdateCall)); + Assert.Equal(403, Exception.ErrorCode); + + System.Threading.Thread.Sleep(5000); + + ApiResponse response = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test Update Call not found request + /// + [Fact] + public void UpdateCallNotFoundRequest() + { + fakeUpdateCall.State = CallStateEnum.Completed; + + ApiException Exception = Assert.Throws(() => instance.UpdateCallWithHttpInfo(accountId, "Call-Id", fakeUpdateCall)); + + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Update Call BXML + /// + [Fact] + public void UpdateCallBxml() + { + CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); + + string callId = createCallResponse.CallId; + System.Threading.Thread.Sleep(5000); + + ApiResponse updateCallBxmlResponse = instance.UpdateCallBxmlWithHttpInfo(accountId, callId, " This is a test sentence."); + Assert.Equal(HttpStatusCode.NoContent, updateCallBxmlResponse.StatusCode); + + System.Threading.Thread.Sleep(5000); + + fakeUpdateCall.State = CallStateEnum.Completed; + ApiResponse updateCallResponse = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); + Assert.Equal(HttpStatusCode.OK, updateCallResponse.StatusCode); + } + + /// + /// Test Update Call BXML bad request + /// + [Fact] + public void UpdateCallBxmlBadRequest() + { + ApiResponse createCallResponse = instance.CreateCallWithHttpInfo(accountId, mantecaCallBody); + + string callId = createCallResponse.Data.CallId; + System.Threading.Thread.Sleep(5000); + + ApiException Exception = Assert.Throws(() => instance.UpdateCallBxmlWithHttpInfo(accountId, callId, "invalid BXML")); + Assert.Equal(400, Exception.ErrorCode); + + System.Threading.Thread.Sleep(5000); + + fakeUpdateCall.State = CallStateEnum.Completed; + ApiResponse updateCallResponse = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); + Assert.Equal(HttpStatusCode.OK, updateCallResponse.StatusCode); + } + + /// + /// Test Update Call BXML unauthorized request + /// + [Fact] + public void UpdateCallBxmlUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateCallBxmlWithHttpInfo(accountId, "Call-Id", " This is a test sentence.")); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Update Call BXML forbidden request + /// + [Fact] + public void UpdateCallBxmlForbiddenRequest() + { + CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); + + string callId = createCallResponse.CallId; + System.Threading.Thread.Sleep(5000); + + ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateCallBxmlWithHttpInfo(accountId, callId, " This is a test sentence.")); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Update Call BXML not found request + /// + [Fact] + public void UpdateCallBxmlNotFoundRequest() + { + ApiException Exception = Assert.Throws(() => instance.UpdateCallBxmlWithHttpInfo(accountId, "Call-Id", " This is a test sentence.")); + Assert.Equal(404, Exception.ErrorCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs new file mode 100644 index 00000000..999ced1d --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs @@ -0,0 +1,416 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing ConferencesApi + /// + public class ConferencesIntegrationTests : IDisposable + { + private ConferencesApi conferenceApiInstance; + private ConferencesApi unauthorizedInstance; + private ConferencesApi forbiddenInstance; + private ApiClient restClient; + private UpdateConference updateConferenceBody; + private CallsApi callsApiInstance; + private Configuration fakeConfiguration; + private CreateCall createCallBody; + private CreateCall mantecaCallBody; + private UpdateConferenceMember updateConferenceMember; + private string accountId; + private string testConferenceId; + private string testMemberId; + private string testRecordingId; + private string testUpdateBxml; + + public ConferencesIntegrationTests() + { + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + conferenceApiInstance = new ConferencesApi(fakeConfiguration); + + + // Unauthorized API Client + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new ConferencesApi(fakeConfiguration); + + // Forbidden API Client + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); + forbiddenInstance = new ConferencesApi(fakeConfiguration); + + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + + restClient = new ApiClient(basePath: "https://voice.bandwidth.com/api/v2"); + + updateConferenceBody = new UpdateConference( + status: ConferenceStateEnum.Active, + redirectUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/pause", + redirectMethod: RedirectMethodEnum.POST, + username: "mySecretUsername", + password: "mySecretPassword!", + redirectFallbackUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/pause", + redirectFallbackMethod: RedirectMethodEnum.POST, + fallbackUsername: "mySecretUsername", + fallbackPassword: "mySecretPassword!" + ); + + createCallBody = new CreateCall( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + from: Environment.GetEnvironmentVariable("BW_NUMBER"), + displayName: "Test Call", + applicationId: Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), + answerUrl: Environment.GetEnvironmentVariable("BASE_CALLBACK_URL"), + answerMethod: CallbackMethodEnum.POST, + username: "mySecretUsername", + password: "mySecretPassword!", + answerFallbackUrl: "https://www.myFallbackServer.com/webhooks/answer", + answerFallbackMethod: CallbackMethodEnum.POST, + fallbackUsername: "mySecretUsername", + fallbackPassword: "mySecretPassword!", + disconnectUrl: "https://myServer.com/bandwidth/webhooks/disconnectUrl", + disconnectMethod: CallbackMethodEnum.POST, + callTimeout: 30, + callbackTimeout: 15, + machineDetection: new MachineDetectionConfiguration( + mode: MachineDetectionModeEnum.Async, + detectionTimeout: 15, + silenceTimeout: 10, + speechThreshold: 10, + speechEndThreshold: 5, + machineSpeechEndThreshold: 5, + delayResult: false, + callbackUrl: "https://myServer.com/bandwidth/webhooks/machineDetectionComplete", + callbackMethod: CallbackMethodEnum.POST, + username: "MySecretUsername", + password: "MySecretPassword!", + fallbackUrl: "https://myFallbackServer.com/bandwidth/webhooks/machineDetectionComplete", + fallbackMethod: CallbackMethodEnum.POST, + fallbackUsername: "MySecretUsername", + fallbackPassword: "MySecretPassword!" + ), + priority: 5, + tag: "tag Example" + ); + + mantecaCallBody = new CreateCall( + to: Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"), + from: Environment.GetEnvironmentVariable("MANTECA_ACTIVE_NUMBER"), + applicationId: Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"), + answerUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/joinConferencePause", + tag: "testID" + ); + + callsApiInstance = new CallsApi(fakeConfiguration); + updateConferenceMember = new UpdateConferenceMember(mute: false); + testConferenceId = "Conf-Id"; + testMemberId = "Member-Id"; + testRecordingId = "Recording-Id"; + testUpdateBxml = "This is test BXML."; + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// + /// + [Fact] + public void CreateConferenceTest() + { + // set up request options for creating a call + var options = new RequestOptions(); + options.HeaderParameters.Add("os", Environment.GetEnvironmentVariable("OPERATING_SYSTEM")); + options.HeaderParameters.Add("language", "csharp" + Environment.GetEnvironmentVariable("CSHARP_VERSION")); + options.HeaderParameters.Add("type", "CONFERENCE"); + + // initialize call with Manteca + var response = restClient.Post( + path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "tests", + options: options + ); + + var testId = response.Data.ToString(); + mantecaCallBody.Tag = testId; + + CreateCallResponse callResponse = callsApiInstance.CreateCall(accountId, mantecaCallBody); + + Assert.IsType(callResponse.CallId); + Assert.Equal(Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"), callResponse.AccountId); + Assert.Equal(Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"), callResponse.ApplicationId); + Assert.Equal(Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"), callResponse.To); + Assert.Equal(Environment.GetEnvironmentVariable("MANTECA_ACTIVE_NUMBER"), callResponse.From); + + System.Threading.Thread.Sleep(5000); + + var listConferencesResponse = conferenceApiInstance.ListConferencesWithHttpInfo( + accountId: accountId, + name: testId + ); + Assert.Equal(HttpStatusCode.OK, listConferencesResponse.StatusCode); + } + + /// + /// Test List Conferences Unauthorized + /// + [Fact] + public void ListConferencesUnauthorizedRequest() + { + // string accountId = "9900000"; + // string name = "my-custom-name"; + // string minCreatedTime = "2022-06-21T19:13:21Z"; + // string maxCreatedTime = "2022-06-21T19:13:21Z"; + // int? pageSize = 500; + + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // ApiException Exception = Assert.Throws(() => conferenceApiInstance.ListConferencesWithHttpInfo(accountId, name, minCreatedTime, maxCreatedTime, pageSize)); + + // Assert.Equal("Error calling ListConferences: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test List Conferences Forbidden + /// + [Fact] + public void ListConferenceForbiddenRequest() + { + // string accountId = "9900000"; + // string name = "my-custom-name"; + // string minCreatedTime = "2022-06-21T19:13:21Z"; + // string maxCreatedTime = "2022-06-21T19:13:21Z"; + // int? pageSize = 500; + + // fakeConfiguration.Username = "forbiddenUsername"; + // fakeConfiguration.Password = "forbiddenPassword"; + + // var apiResponse = new ApiResponse>(HttpStatusCode.OK, null); + // mockClient.Setup(x => x.Get>("/accounts/{accountId}/conferences", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = conferenceApiInstance.ListConferencesWithHttpInfo(accountId, name, minCreatedTime, maxCreatedTime, pageSize); + + // Assert.IsType>>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test Get Conferences Unauthorized + /// + [Fact] + public void GetConferencesUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListConferencesWithHttpInfo(accountId)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Get Conferences Forbidden + /// + [Fact] + public void GetConferencesForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GetConferenceWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Get Conferences Not Found + /// + [Fact] + public void GetConferencesNotFound() + { + ApiException Exception = Assert.Throws(() => conferenceApiInstance.GetConferenceWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Get Conference Member Unauthorized + /// + [Fact] + public void GetConferenceMemberUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Get Conference Member Forbidden + /// + [Fact] + public void GetConferenceMemberForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Get Conference Member Not Found + /// + [Fact] + public void GetConferenceMemberNotFoundRequest() + { + ApiException Exception = Assert.Throws(() => conferenceApiInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test List Conference Recordings Unauthorized + /// + [Fact] + public void ListConferenceRecordingsUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListConferenceRecordingsWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test List Conference Recordings Forbidden + /// + [Fact] + public void ListConferenceRecordingsForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.ListConferenceRecordingsWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Get Conference Recording Unauthorized + /// + [Fact] + public void GetConferenceRecordingUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Get Conference Recording Forbidden + /// + [Fact] + public void GetConferenceRecordingForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Get Conference Recording not found + /// + [Fact(Skip = "Actually throws a 500 error and needs to be fixed by the voice team")] + public void GetConferenceRecordingNotFound() + { + ApiException Exception = Assert.Throws(() => conferenceApiInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Update Conference Unauthorized Request + /// + [Fact] + public void UpdateConferenceUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Update Conference Forbidden Request + /// + [Fact] + public void UpdateConferenceForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Update Conference Not Found + /// + [Fact] + public void UpdateConferenceNotFoundRequest() + { + ApiException Exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); + + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Update Conference BXML Unauthorized + /// + [Fact] + public void UpdateConferenceBxmlUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Update Conference BXML Forbidden + /// + [Fact] + public void UpdateConferenceBxmlForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test Update Conference BXML Not Found + /// + [Fact] + public void UpdateConferenceBxmlNotFoundRequest() + { + ApiException Exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); + Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Update Conference Member Unauthorized + /// + [Fact] + public void UpdateConferenceMemberUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId, updateConferenceMember)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Update Conference Member Forbidden + /// + [Fact] + public void UpdateConferenceMemberForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId, updateConferenceMember)); + Assert.Equal(403, Exception.ErrorCode); // not erroring out + } + + /// + /// Test Update Conference Member Not Found + /// + [Fact] + public void UpdateConferenceMemberNotFoundRequest() + { + ApiException Exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceMember(accountId, testConferenceId, testMemberId, updateConferenceMember)); + Assert.Equal(404, Exception.ErrorCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs new file mode 100644 index 00000000..65be72ea --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs @@ -0,0 +1,208 @@ +/* + * Bandwidth + * + * Bandwidth's Communication APIs + * + * The version of the OpenAPI document: 1.0.0 + * Contact: letstalk@bandwidth.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing MFAApi + /// + public class MFAIntegrationTests : IDisposable + { + private MFAApi instance; + private MFAApi unauthorizedInstance; + private MFAApi forbiddenInstance; + private Configuration fakeConfiguration; + private string accountId; + private CodeRequest messagingCodeRequest; + private CodeRequest voiceCodeRequest; + private CodeRequest badCodeRequest; + + public MFAIntegrationTests() + { + // Authorized API Client + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://mfa.bandwidth.com/api/v1"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + instance = new MFAApi(fakeConfiguration); + + // Unauthorized API Client + unauthorizedInstance = new MFAApi(); + + // Forbidden API Client + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + fakeConfiguration.Password = "badPassword"; + forbiddenInstance = new MFAApi(fakeConfiguration); + + // Code Request for generating a messaging code + messagingCodeRequest = new CodeRequest( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + from: Environment.GetEnvironmentVariable("BW_NUMBER"), + applicationId: Environment.GetEnvironmentVariable("BW_MESSAGING_APPLICATION_ID"), + message: "Your temporary {NAME} {SCOPE} code is {CODE}", + scope: "2FA", + digits: 6 + ); + + // Code Request for generating a voice code + voiceCodeRequest = new CodeRequest( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + from: Environment.GetEnvironmentVariable("BW_NUMBER"), + applicationId: Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), + message: "Your temporary {NAME} {SCOPE} code is {CODE}", + scope: "2FA", + digits: 6 + ); + + // Bad Code Request + badCodeRequest = new CodeRequest( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + from: Environment.GetEnvironmentVariable("BW_NUMBER"), + applicationId: "not an application id", + message: "Your temporary {NAME} {SCOPE} code is {CODE}", + scope: "2FA", + digits: 6 + ); + + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of MFAApi + /// + [Fact] + public void InstanceTest() + { + Assert.IsType(instance); + } + + /// + /// Test GenerateMessagingCode + /// + [Fact] + public void GenerateMessagingCodeTest() + { + var response = instance.GenerateMessagingCodeWithHttpInfo(accountId, messagingCodeRequest); + + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test GenerateVoiceCode + /// + [Fact] + public void GenerateVoiceCodeTest() + { + var response = instance.GenerateVoiceCodeWithHttpInfo(accountId, voiceCodeRequest); + + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test VerifyCode + /// + [Fact] + public void VerifyCodeTest() + { + VerifyCodeRequest verifyCodeRequest = new VerifyCodeRequest( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + expirationTimeInMinutes: 3, + code: "123456" + ); + + var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); + + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test failed Generate Messaging Code Request + /// + [Fact] + public void GenerateMessagingCodeBadRequest() + { + ApiException Exception = Assert.Throws(() => instance.GenerateMessagingCode(accountId, badCodeRequest)); + + Assert.Equal(400, Exception.ErrorCode); + } + + /// + /// Test failed Generate Voice Code Request + /// + [Fact] + public void GenerateVoiceCodeBadRequest() + { + ApiException Exception = Assert.Throws(() => instance.GenerateVoiceCode(accountId, badCodeRequest)); + + Assert.Equal(400, Exception.ErrorCode); + } + + /// + /// Test unauthorized Generate Messaging Code Request + /// + [Fact] + public void GenerateMessagingCodeUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GenerateMessagingCode(accountId, messagingCodeRequest)); + + Assert.Equal(401, Exception.ErrorCode); //throwing 403 + } + + /// + /// Test unauthorized Generate Voice Code Request + /// + [Fact] + public void GenerateVoiceCodeUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GenerateVoiceCode(accountId, voiceCodeRequest)); + + Assert.Equal(401, Exception.ErrorCode); //throwing 403 + } + + /// + /// Test forbidden Generate Messaging Code Request + /// + [Fact] + public void GenerateMessagingCodeForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GenerateMessagingCode(accountId, messagingCodeRequest)); + + Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test forbidden Generate Voice Code Request + /// + [Fact] + public void GenerateVoiceCodeForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GenerateVoiceCode(accountId, voiceCodeRequest)); + + Assert.Equal(403, Exception.ErrorCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs new file mode 100644 index 00000000..c41dfc58 --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs @@ -0,0 +1,159 @@ +/* + * Bandwidth + * + * Bandwidth's Communication APIs + * + * The version of the OpenAPI document: 1.0.0 + * Contact: letstalk@bandwidth.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing MediaApi + /// + public class MediaIntegrationTests : IDisposable + { + private MediaApi instance; + private MediaApi unauthorizedInstance; + private Configuration fakeConfiguration; + private string accountId; + private string mediaId; + private System.IO.Stream mediaBody; + private string contentType; + + + public MediaIntegrationTests() + { + + mediaId = $"text-media-id-{Guid.NewGuid()}"; + //API Client + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + instance = new MediaApi(fakeConfiguration); + + + // Unauthorized API Client + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://messaging.bandwidth.com/api/v2"; + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new MediaApi(fakeConfiguration); + + // Create a media file to use for testing + + string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; + string relativePath = "../../../Fixtures/csharp_cat.jpeg"; + string filePath = Path.Combine(baseDirectory, relativePath); + mediaBody = new System.IO.FileStream(filePath, FileMode.Open); + contentType = "image/jpeg"; + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of MediaApi + /// + [Fact] + public void InstanceTest() + { + Assert.IsType(instance); + } + + + /// + /// Test Upload Media + /// + [Fact] + public void UploadMediaTest() + { + var responseWithHttpInfo = instance.UploadMediaWithHttpInfo(accountId, mediaId, mediaBody, contentType); + + Assert.IsType>(responseWithHttpInfo); + Assert.Equal(HttpStatusCode.NoContent, responseWithHttpInfo.StatusCode); + + instance.UploadMedia(accountId, mediaId, mediaBody, contentType); + mediaBody.Close(); + } + + /// + /// Test List Media + /// + [Fact] + public void ListMediaTest() + { + var responseWithHttpInfo = instance.ListMediaWithHttpInfo(accountId); + Assert.Equal(HttpStatusCode.OK, responseWithHttpInfo.StatusCode); + + var response = instance.ListMedia(accountId); + Assert.IsType>(response); + Assert.IsType(response[0]); + } + + /// + /// Test Get Media + /// + [Fact] + public void GetMediaTest() + { + var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, mediaId, mediaBody, contentType); + + var responseWithHttpInfo = instance.GetMediaWithHttpInfo(accountId, mediaId); + Assert.Equal(HttpStatusCode.OK, responseWithHttpInfo.StatusCode); + + var response = instance.GetMedia(accountId, mediaId); + Assert.IsAssignableFrom(response); + mediaBody.Close(); + } + + /// + /// Test Delete Media + /// + [Fact] + public void DeleteMediaTest() + { + var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, mediaId, mediaBody, contentType); + + var responseWithHttpInfo = instance.DeleteMediaWithHttpInfo(accountId, mediaId); + Assert.Equal(HttpStatusCode.NoContent, responseWithHttpInfo.StatusCode); + + instance.DeleteMedia(accountId, mediaId); + mediaBody.Close(); + } + + /// + /// Test Get media with Bandwidth Ids + /// + [Fact] + public void getMediaWithBandwidthIdsTest() + { + // use a nonexistent mediaId - results in a 404 + mediaId = "abcd1234-e5f6-1111-2222-3456ghi7890/image123456.jpg"; + + ApiException exception = Assert.Throws(() => instance.GetMediaWithHttpInfo(accountId, mediaId)); + Assert.Equal(404, exception.ErrorCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs new file mode 100644 index 00000000..b1cd7415 --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs @@ -0,0 +1,199 @@ + + /* Bandwidth + * + * Bandwidth's Communication APIs + * + * The version of the OpenAPI document: 1.0.0 + * Contact: letstalk@bandwidth.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing MessagesApi + /// + public class MessagesIntegrationTests : IDisposable + { + private MessagesApi instance; + private MessagesApi unauthorizedInstance; + private Configuration fakeConfiguration; + private string accountId; + private MessageRequest messageRequest; + + public MessagesIntegrationTests() + { + // API Client + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://messaging.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + instance = new MessagesApi(fakeConfiguration); + + // Unauthorized API Client + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://messaging.bandwidth.com/api/v2"; + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new MessagesApi(fakeConfiguration); + + // Message Request + messageRequest = new MessageRequest( + applicationId: Environment.GetEnvironmentVariable("BW_MESSAGING_APPLICATION_ID"), + to: new List {Environment.GetEnvironmentVariable("USER_NUMBER") }, + from: Environment.GetEnvironmentVariable("BW_NUMBER"), + text: "c# integration test", + media: new List { "https://cdn2.thecatapi.com/images/MTY3ODIyMQ.jpg" }, + tag: "c# integration test", + priority: PriorityEnum.Default + ); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of MessagesApi + /// + [Fact] + public void InstanceTest() + { + Assert.IsType(instance); + } + + /// + /// Test CreateMessage + /// + [Fact] + public void CreateMessageTest() + { + var response = instance.CreateMessageWithHttpInfo(accountId, messageRequest); + Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + + var message = response.Data; + + Assert.NotNull(message.ApplicationId); + Assert.NotNull(message.To); + Assert.NotNull(message.From); + Assert.NotNull(message.Owner); + Assert.NotNull(message.Text); + Assert.NotNull(message.Media); + Assert.NotNull(message.Tag); + Assert.IsType(message.Priority); + Assert.NotNull(message.Priority); + Assert.Equal(1, message.SegmentCount); + Assert.IsType(message.Time); + + } + + /// + /// Test failed CreateMessage Request + /// + [Fact] + public void CreateMessageBadRequest() + { + messageRequest.ApplicationId = null; // Bad Request + + ApiException Exception = Assert.Throws(() => instance.CreateMessage(accountId, messageRequest)); + Assert.Equal(400, Exception.ErrorCode); // no exception thrown + } + + /// + /// Test Unauthorized CreateMessage Request + /// + [Fact] + public void CreateMessageUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.CreateMessage(accountId, messageRequest)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Create Message invalid media + /// + [Fact] + public void CreateMessageInvalidMedia() + { + messageRequest.Media = new List { "not media" }; // Bad Request + + ApiException Exception = Assert.Throws(() => instance.CreateMessageWithHttpInfo(accountId, messageRequest)); + Assert.Equal(400, Exception.ErrorCode); + } + + /// + /// Test ListMessages + /// + [Fact] + public void ListMessagesTest() + { + var response = instance.ListMessagesWithHttpInfo( + accountId: accountId, + messageDirection: ListMessageDirectionEnum.OUTBOUND, + messageStatus: MessageStatusEnum.DELIVERED, + messageType: MessageTypeEnum.Sms + ); + + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + Assert.NotEqual(0, response.Data.TotalCount); + Assert.IsType>(response.Data.Messages); + Assert.IsType(response.Data.Messages[0]); + + var message = response.Data.Messages[0]; + + Assert.Equal(accountId, message.AccountId); + Assert.Matches("^\\+[1-9]\\d{1,14}$", message.DestinationTn); + Assert.Equal(ListMessageDirectionEnum.OUTBOUND, message.MessageDirection); + Assert.Matches("^.+$", message.MessageId); + Assert.IsType(message.MessageStatus); + Assert.IsType(message.MessageType); + Assert.NotEqual(0, message.SegmentCount); + Assert.Matches("^\\+[1-9]\\d{1,14}$", message.SourceTn); + Assert.IsType(message.ReceiveTime); + } + + /// + /// Test failed ListMessages Request + /// + [Fact] + public void ListMessagesBadRequest() + { + ApiException Exception = Assert.Throws(() => instance.ListMessages( + accountId: accountId + )); + + Assert.Equal(400, Exception.ErrorCode); + } + + /// + /// Test Unauthorized ListMessages Request + /// + [Fact] + public void ListMessagesUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListMessages( + accountId: accountId + )); + + Assert.Equal(401, Exception.ErrorCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs new file mode 100644 index 00000000..daa1889c --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs @@ -0,0 +1,158 @@ +/* + * Bandwidth + * + * Bandwidth's Communication APIs + * + * The version of the OpenAPI document: 1.0.0 + * Contact: letstalk@bandwidth.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using System.Collections.Generic; +using RestSharp; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing PhoneNumberLookupApi + /// + public class PhoneNumberLookupIntegrationTests : IDisposable + { + private PhoneNumberLookupApi instance; + private PhoneNumberLookupApi unauthorizedInstance; + private PhoneNumberLookupApi forbiddenInstance; + private Configuration fakeConfiguration; + private string accountId; + + public PhoneNumberLookupIntegrationTests() + { + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + instance = new PhoneNumberLookupApi(fakeConfiguration); + + // Unauthorized API Client + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new PhoneNumberLookupApi(fakeConfiguration); + + // Forbidden API Client + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); + forbiddenInstance = new PhoneNumberLookupApi(fakeConfiguration); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of PhoneNumberLookupApi + /// + [Fact] + public void InstanceTest() + { + Assert.IsType(instance); + } + + /// + /// Test GetLookupStatus + /// + [Fact] + public void GetLookupStatusTest() + { + + } + + /// + /// Test CreateLookup + /// + [Fact] + public void CreateLookupTest() + { + LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + + var response = instance.CreateLookupWithHttpInfo(accountId, lookupRequest); + + Assert.IsType>(response); + Assert.Equal(LookupStatusEnum.INPROGRESS, response.Data.Status); + Assert.IsType(response.Data.RequestId); + Assert.Matches("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$", response.Data.RequestId); + Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); + + var lookupStatus = instance.GetLookupStatus(accountId, response.Data.RequestId); + + Assert.IsType(lookupStatus); + Assert.Equal(response.Data.RequestId, lookupStatus.RequestId); + Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), lookupStatus.Result[0].E164Format); + + } + + /// + /// Test failed phone number lookup + /// + [Fact] + public void CreateLookupFailedRequest() + { + LookupRequest lookupRequest = new LookupRequest(new List { "not a number" }); + + ApiException exception = Assert.Throws(() => instance.CreateLookup(accountId, lookupRequest)); + var error = new TnLookupRequestError(exception.Message); + Assert.IsType(error); + Assert.Equal(400, exception.ErrorCode); + + } + + /// + /// Test duplicate phone number lookup + /// + [Fact] + public void CreateLookupDuplicateRequest() + { + LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER"), Environment.GetEnvironmentVariable("BW_NUMBER") }); + + ApiException Exception = Assert.Throws(() => instance.CreateLookup(accountId, lookupRequest)); + + Assert.Equal(400, Exception.ErrorCode); + Assert.IsType(Exception.Message); + } + + /// + /// Test Unauthorize request + /// + [Fact] + public void CreateLookupUnauthorizedRequest() + { + LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + + ApiException Exception = Assert.Throws(() => unauthorizedInstance.CreateLookup(accountId, lookupRequest)); + + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Forbidden request + /// + [Fact] + public void CreateLookupForbiddenRequest() + { + LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + + ApiException Exception = Assert.Throws(() => forbiddenInstance.CreateLookup(accountId, lookupRequest)); + + //This API throws a 401 when a user provides valid credentials with the `TN Lookup` role disabled + Assert.Equal(401, Exception.ErrorCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs new file mode 100644 index 00000000..8ff02ae3 --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs @@ -0,0 +1,659 @@ +/* + * Bandwidth + * + * Bandwidth's Communication APIs + * + * The version of the OpenAPI document: 1.0.0 + * Contact: letstalk@bandwidth.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using System.IO; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using RestSharp; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using Moq; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing RecordingsApi + /// + public class RecordingsIntegrationTests : IDisposable + { + private RecordingsApi instance; + private Configuration fakeConfiguration; + + public RecordingsIntegrationTests() + { + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; + fakeConfiguration.Username = "username"; + fakeConfiguration.Password = "password"; + instance = new RecordingsApi(fakeConfiguration); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of RecordingsApi + /// + [Fact] + public void InstanceTest() + { + Assert.IsType(instance); + } + + /// + /// Test DeleteCallTranscription + /// + [Fact] + public void DeleteCallTranscriptionTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + + // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, recordingId); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + } + + /// + /// Test Unauthorized DeleteCallTranscription + /// + [Fact] + public void DeleteCallTranscriptionUnauthorizedRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DeleteCallTranscription: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test Forbidden DeleteCallTranscription + /// + [Fact] + public void DeleteCallTranscriptionForbiddenRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // fakeConfiguration.Username = "ForbiddenUsername"; + // fakeConfiguration.Password = "ForbiddenPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DeleteCallTranscription: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test DeleteRecording + /// + [Fact] + public void DeleteRecordingTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + + // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.DeleteRecordingWithHttpInfo(accountId, callId, recordingId); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + } + + /// + /// Test Unauthorized DeleteRecording + /// + [Fact] + public void DeleteRecordingUnauthorizedRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + + // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DeleteRecording: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test forbidden DeleteRecording + /// + [Fact] + public void DeleteRecordingForbiddenRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // fakeConfiguration.Username = "forbiddenUsername"; + // fakeConfiguration.Password = "forbiddenPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DeleteRecording: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test DeleteRecordingMedia + /// + [Fact] + public void DeleteRecordingMediaTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + + // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.DeleteRecordingMediaWithHttpInfo(accountId, callId, recordingId); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + } + + /// + /// Test Unauthorized DeleteRecordingMedia + /// + [Fact] + public void DeleteRecordingMediaUnauthorizedRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingMediaWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DeleteRecordingMedia: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test forbidden DeleteRecordingMedia + /// + [Fact] + public void DeleteRecordingMediaForbiddenRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingMediaWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DeleteRecordingMedia: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test DownloadCallRecording + /// + [Fact] + public void DownloadCallRecordingTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; + // string relativePath = "../../../Fixtures/csharp_test_recording.wav"; + // string filePath = Path.Combine(baseDirectory, relativePath); + // System.IO.Stream body = new System.IO.FileStream(filePath, FileMode.Open); + + // var apiResponse = new ApiResponse(HttpStatusCode.OK, body); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.DownloadCallRecordingWithHttpInfo(accountId, callId, recordingId); + + // Assert.IsAssignableFrom>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + // body.Close(); + } + + /// + /// Test Unauthorized DownloadCallRecording + /// + [Fact] + public void DownloadCallRecordingUnauthorizedRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b21-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b21-b22865662d85"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DownloadCallRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DownloadCallRecording: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + + /// + /// Test forbidden DownloadCallRecording + /// + [Fact] + public void DownloadCallRecordingForbiddenRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a-b215-b22865662d85"; + // fakeConfiguration.Username = "forbiddenUsername"; + // fakeConfiguration.Password = "forbiddenPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.DownloadCallRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling DownloadCallRecording: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test GetCallRecording + /// + [Fact] + public void GetCallRecordingTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // CallRecordingMetadata callRecordingMetadata = new CallRecordingMetadata( + // applicationId: "04e88489-df02-4e34-a0ee-27a91849555f", + // accountId: "920012", + // callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", + // parentCallId: "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", + // recordingId: "r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833", + // to: "+15555555555", + // from: "+15555555555", + // transferCallerId: "+15555555555", + // transferTo: "+15555555555", + // duration: "PT13.67S", + // direction: CallDirectionEnum.Inbound, + // channels: 1, + // startTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), + // endTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), + // fileFormat: FileFormatEnum.Wav, + // status: "completed", + // mediaUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-fe23a767-a75a5b77-20c5-4cca-b581-cbbf0776eca9/recordings/r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833/media", + // transcription: new TranscriptionMetadata( + // id: "t-387bd648-18f3-4823-9d16-746bca0003c9", + // status: "completed", + // completedTime: "2022-06-13T18:46:29.715Z", + // url: "https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcription" + // ) + // ); + + // var apiResponse = new ApiResponse(HttpStatusCode.OK, callRecordingMetadata); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test GetCallRecording not Found + /// + [Fact] + public void GetCallRecordingNotFound() + { + // string accountId = "9900000"; + // string callId = "not a call id"; + // string recordingId = "not a recording id"; + + // var apiResponse = new ApiResponse(HttpStatusCode.NotFound, null); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling GetCallRecording: ", Exception.Message); + // Assert.Equal(404, Exception.ErrorCode); + } + + /// + /// Test Unauthorized GetCallRecording + /// + [Fact] + public void GetCallRecordingUnauthorizedRequestTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling GetCallRecording: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test forbidden GetCallRecording + /// + [Fact] + public void GetCallRecordingForbiddenRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // fakeConfiguration.Username = "forbiddenUsername"; + // fakeConfiguration.Password = "forbiddenPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId)); + + // Assert.Equal("Error calling GetCallRecording: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test GetCallTranscription + /// + [Fact] + public void GetCallTranscriptionTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // Transcription transcription = new Transcription(text: "Nice talking to you, friend!", confidence: .9); + // TranscriptionList transcriptionList = new TranscriptionList(transcripts: new List { transcription } ); + + // var apiResponse = new ApiResponse(HttpStatusCode.OK, transcriptionList); + // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.GetCallTranscriptionWithHttpInfo(accountId, callId, recordingId); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test ListAccountCallRecordings + /// + [Fact] + public void ListAccountCallRecordingsTest() + { + // string accountId = "9900000"; + // CallRecordingMetadata callRecordingMetadata = new CallRecordingMetadata( + // applicationId: "04e88489-df02-4e34-a0ee-27a91849555f", + // accountId: "920012", + // callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", + // parentCallId: "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", + // recordingId: "r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833", + // to: "+15555555555", + // from: "+15555555555", + // transferCallerId: "+15555555555", + // transferTo: "+15555555555", + // duration: "PT13.67S", + // direction: CallDirectionEnum.Inbound, + // channels: 1, + // startTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), + // endTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), + // fileFormat: FileFormatEnum.Wav, + // status: "completed", + // mediaUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-fe23a767-a75a5b77-20c5-4cca-b581-cbbf0776eca9/recordings/r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833/media", + // transcription: new TranscriptionMetadata( + // id: "t-387bd648-18f3-4823-9d16-746bca0003c9", + // status: "completed", + // completedTime: "2022-06-13T18:46:29.715Z", + // url:"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcription" + // ) + // ); + + // var apiResponse = new ApiResponse>(HttpStatusCode.OK, new List() { callRecordingMetadata }); + // mockClient.Setup(x => x.Get>("/accounts/{accountId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.ListAccountCallRecordingsWithHttpInfo( + // accountId: accountId, + // to: "+19195551234", + // from: "+19195554321", + // minStartTime: "2022-06-21T19:13:21Z", + // maxStartTime: "2022-06-21T19:13:21Z" + // ); + + // Assert.IsType>>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + + /// + /// Test Unauthorized ListAccountCallRecordings + /// + [Fact] + public void ListAccountCallRecordingsUnauthorizedRequestTest() + { + // string accountId = "9900000"; + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse>(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Get>("/accounts/{accountId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.ListAccountCallRecordingsWithHttpInfo( + // accountId: accountId, + // to: "+19195551234", + // from: "+19195554321", + // minStartTime: "2022-06-21T19:13:21Z", + // maxStartTime: "2022-06-21T19:13:21Z" + // )); + + // Assert.Equal("Error calling ListAccountCallRecordings: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test forbidden ListAccountCallRecordings + /// + [Fact] + public void ListAccountCallRecordingsForbiddenRequestTest() + { + // string accountId = "9900000"; + + // var apiResponse = new ApiResponse>(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Get>("/accounts/{accountId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.ListAccountCallRecordingsWithHttpInfo( + // accountId: accountId, + // to: "+19195551234", + // from: "+19195554321", + // minStartTime: "2022-06-21T19:13:21Z", + // maxStartTime: "2022-06-21T19:13:21Z" + // )); + + // Assert.Equal("Error calling ListAccountCallRecordings: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + + /// + /// Test ListCallRecordings + /// + [Fact] + public void ListCallRecordingsTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // CallRecordingMetadata callRecordingMetadata = new CallRecordingMetadata( + // applicationId: "04e88489-df02-4e34-a0ee-27a91849555f", + // accountId: "920012", + // callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", + // parentCallId: "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", + // recordingId: "r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833", + // to: "+15555555555", + // from: "+15555555555", + // transferCallerId: "+15555555555", + // transferTo: "+15555555555", + // duration: "PT13.67S", + // direction: CallDirectionEnum.Inbound, + // channels: 1, + // startTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), + // endTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), + // fileFormat: FileFormatEnum.Wav, + // status: "completed", + // mediaUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-fe23a767-a75a5b77-20c5-4cca-b581-cbbf0776eca9/recordings/r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833/media", + // transcription: new TranscriptionMetadata( + // id: "t-387bd648-18f3-4823-9d16-746bca0003c9", + // status: "completed", + // completedTime: "2022-06-13T18:46:29.715Z", + // url: "https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcription" + // ) + // ); + + // var apiResponse = new ApiResponse>(HttpStatusCode.OK, new List() { callRecordingMetadata }); + // mockClient.Setup(x => x.Get>("/accounts/{accountId}/calls/{callId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.ListCallRecordingsWithHttpInfo(accountId, callId); + + // Assert.IsType>>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + + } + + /// + /// Test TranscribeCallRecording + /// + [Fact] + public void TranscribeCallRecordingTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // TranscribeRecording transcribeRecording = new TranscribeRecording( + // callbackUrl: "https://myServer.example/bandwidth/webhooks/transcriptionAvailable", + // callbackMethod: CallbackMethodEnum.POST, + // username: "mySecretUsername", + // password: "mySecretPassword", + // tag: "exampleTag", + // callbackTimeout: 15, + // detectLanguage: true + // ); + + // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); + // mockClient.Setup(x => x.Post("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.TranscribeCallRecordingWithHttpInfo(accountId, callId, recordingId, transcribeRecording); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + } + + /// + /// Test Unauthorized TranscribeCallRecording + /// + [Fact] + public void TranscribeCallRecordingUnauthorizedRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // TranscribeRecording transcribeRecording = new TranscribeRecording( + // callbackUrl: "https://myServer.example/bandwidth/webhooks/transcriptionAvailable", + // callbackMethod: CallbackMethodEnum.POST, + // username: "mySecretUsername", + // password: "mySecretPassword", + // tag: "exampleTag", + // callbackTimeout: 15, + // detectLanguage: true + // ); + // fakeConfiguration.Username = "badUsername"; + // fakeConfiguration.Password = "badPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); + // mockClient.Setup(x => x.Post("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.TranscribeCallRecordingWithHttpInfo(accountId, callId, recordingId, transcribeRecording)); + + // Assert.Equal("Error calling TranscribeCallRecording: ", Exception.Message); + // Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test forbidden TranscribeCallRecording + /// + [Fact] + public void TranscribeCallRecordingForbiddenRequest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // TranscribeRecording transcribeRecording = new TranscribeRecording( + // callbackUrl: "https://myServer.example/bandwidth/webhooks/transcriptionAvailable", + // callbackMethod: CallbackMethodEnum.POST, + // username: "mySecretUsername", + // password: "mySecretPassword", + // tag: "exampleTag", + // callbackTimeout: 15, + // detectLanguage: true + // ); + // fakeConfiguration.Username = "forbiddenUsername"; + // fakeConfiguration.Password = "forbiddenPassword"; + + // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); + // mockClient.Setup(x => x.Post("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // ApiException Exception = Assert.Throws(() => instance.TranscribeCallRecordingWithHttpInfo(accountId, callId, recordingId, transcribeRecording)); + + // Assert.Equal("Error calling TranscribeCallRecording: ", Exception.Message); + // Assert.Equal(403, Exception.ErrorCode); + } + + /// + /// Test UpdateCallRecordingState + /// + [Fact] + public void UpdateCallRecordingStateTest() + { + // string accountId = "9900000"; + // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + // UpdateCallRecording updateCallRecording = new UpdateCallRecording(RecordingStateEnum.Paused); + + // var apiResponse = new ApiResponse(HttpStatusCode.OK, null); + // mockClient.Setup(x => x.Put("/accounts/{accountId}/calls/{callId}/recording", It.IsAny(), fakeConfiguration)).Returns(apiResponse); + // var response = instance.UpdateCallRecordingStateWithHttpInfo(accountId, callId, updateCallRecording); + + // Assert.IsType>(response); + // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + } +} diff --git a/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs new file mode 100644 index 00000000..15cb0752 --- /dev/null +++ b/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs @@ -0,0 +1,67 @@ +/* + * Bandwidth + * + * Bandwidth's Communication APIs + * + * The version of the OpenAPI document: 1.0.0 + * Contact: letstalk@bandwidth.com + * Generated by: https://github.com/openapitools/openapi-generator.git + */ + +using System; +using Xunit; + +using Bandwidth.Standard.Client; +using Bandwidth.Standard.Api; +using Bandwidth.Standard.Model; +using System.Net; + +namespace Bandwidth.Standard.Test.Integration +{ + /// + /// Class for testing StatisticsApi + /// + public class StatisticsIntegrationTests : IDisposable + { + private StatisticsApi instance; + private Configuration fakeConfiguration; + private string accountId; + + public StatisticsIntegrationTests() + { + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); + instance = new StatisticsApi(fakeConfiguration); + + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + } + + public void Dispose() + { + // Cleanup when everything is done. + } + + /// + /// Test an instance of StatisticsApi + /// + [Fact] + public void InstanceTest() + { + Assert.IsType(instance); + } + + /// + /// Test GetStatistics + /// + [Fact] + public void GetStatisticsTest() + { + var response = instance.GetStatisticsWithHttpInfo(accountId); + + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + } + } +} From cddf9d9225206336c449bd8b72e24c873a10a9d3 Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Fri, 6 Oct 2023 16:33:59 -0400 Subject: [PATCH 2/8] SWI-1632: Finished integration tests --- .../Integration/CallsIntegrationTests.cs | 123 ++- .../ConferencesIntegrationTests.cs | 343 ++++--- .../Integration/MFAIntegrationTests.cs | 122 +-- .../Integration/MediaIntegrationTests.cs | 162 +++- .../Integration/MessagesIntegrationTests.cs | 119 +-- .../PhoneNumberLookupIntegrationTests.cs | 75 +- .../Integration/RecordingsIntegrationTests.cs | 905 +++++++++--------- .../Integration/StatisticsIntegrationTests.cs | 42 +- 8 files changed, 1016 insertions(+), 875 deletions(-) diff --git a/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs index 67f67ac3..06916a00 100644 --- a/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs @@ -1,16 +1,9 @@ using System; -using System.IO; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; namespace Bandwidth.Standard.Test.Integration @@ -20,17 +13,24 @@ namespace Bandwidth.Standard.Test.Integration /// public class CallsIntegrationTests : IDisposable { - private CallsApi instance; - private CallsApi unauthorizedInstance; - private CallsApi forbiddenInstance; - private Configuration fakeConfiguration; + private string accountId; private CreateCall createCallBody; - private CreateCall mantecaCallBody; + private Configuration fakeConfiguration; private UpdateCall fakeUpdateCall; - private string accountId; + private CallsApi forbiddenInstance; + private CallsApi instance; + private CreateCall mantecaCallBody; + private string testCallId; + private int testSleep; + private CallsApi unauthorizedInstance; public CallsIntegrationTests() { + // Test Constants accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + testSleep = 5000; + testCallId = "testCallId"; + + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); @@ -47,8 +47,6 @@ public CallsIntegrationTests() fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); forbiddenInstance = new CallsApi(fakeConfiguration); - - createCallBody = new CreateCall( to: Environment.GetEnvironmentVariable("USER_NUMBER"), from: Environment.GetEnvironmentVariable("BW_NUMBER"), @@ -114,7 +112,7 @@ public void Dispose() } /// - /// Test CreateCall + /// Test successful CreateCall request /// [Fact] public void CreateCallTest() @@ -122,17 +120,17 @@ public void CreateCallTest() ApiResponse response = instance.CreateCallWithHttpInfo(accountId, createCallBody); Assert.Equal(HttpStatusCode.Created, response.StatusCode); Assert.IsType(response.Data.CallId); - Assert.Equal(Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"), response.Data.AccountId); + Assert.Equal(accountId, response.Data.AccountId); Assert.Equal(Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), response.Data.ApplicationId); Assert.Equal(Environment.GetEnvironmentVariable("USER_NUMBER"), response.Data.To); Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), response.Data.From); } /// - /// Test Create Call bad request + /// Test CreateCall with a bad phone number /// [Fact] - public void CreateCallBadRequestTest() + public void CreateCallBadRequest() { createCallBody.To = "not a phone number"; ApiException Exception = Assert.Throws(() => instance.CreateCallWithHttpInfo(accountId, createCallBody)); @@ -140,7 +138,7 @@ public void CreateCallBadRequestTest() } /// - /// Test Create Call unauthorized request + /// Test CreateCall with an unauthorized client /// [Fact] public void CreateCallUnauthorizedRequest() @@ -150,7 +148,7 @@ public void CreateCallUnauthorizedRequest() } /// - /// Test Create Call forbidden request + /// Test CreateCall with a forbidden client /// [Fact] public void CreateCallForbiddenRequest() @@ -160,7 +158,7 @@ public void CreateCallForbiddenRequest() } /// - /// Test Get Call State + /// Test successful GetCallState request /// [Fact] public void GetCallStateTest() @@ -168,7 +166,7 @@ public void GetCallStateTest() CreateCallResponse createCallResponse = instance.CreateCall(accountId, createCallBody); var callId = createCallResponse.CallId; - System.Threading.Thread.Sleep(5000); + System.Threading.Thread.Sleep(testSleep); ApiResponse response = instance.GetCallStateWithHttpInfo(accountId, callId); Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -181,37 +179,37 @@ public void GetCallStateTest() } /// - /// Test Get Call State unauthorized request + /// Test GetCallState with an unauthorized client /// [Fact] public void GetCallStateUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetCallStateWithHttpInfo(accountId, "Call-Id")); + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetCallStateWithHttpInfo(accountId, testCallId)); Assert.Equal(401, Exception.ErrorCode); } /// - /// Test Get Call State forbidden request + /// Test GetCallState with a forbidden client /// [Fact] public void GetCallStateForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.GetCallStateWithHttpInfo(accountId, "Call-Id")); + ApiException Exception = Assert.Throws(() => forbiddenInstance.GetCallStateWithHttpInfo(accountId, testCallId)); Assert.Equal(403, Exception.ErrorCode); } /// - /// Test Get Call State not found request + /// Test GetCallState with a fake call-id /// [Fact] public void GetCallStateNotFoundRequest() { - ApiException Exception = Assert.Throws(() => instance.GetCallStateWithHttpInfo(accountId, "Call-Id")); + ApiException Exception = Assert.Throws(() => instance.GetCallStateWithHttpInfo(accountId, testCallId)); Assert.Equal(404, Exception.ErrorCode); } /// - /// Test Update Call + /// Test successful UpdateCall request /// [Fact] public void UpdateCallTest() @@ -232,11 +230,13 @@ public void UpdateCallTest() tag: "My Custom Tag" ); - System.Threading.Thread.Sleep(5000); + System.Threading.Thread.Sleep(testSleep); + ApiResponse response = instance.UpdateCallWithHttpInfo(accountId, callId, updateCallBody); Assert.Equal(HttpStatusCode.OK, response.StatusCode); - System.Threading.Thread.Sleep(5000); + System.Threading.Thread.Sleep(testSleep); + //Hanging up the call updateCallBody.State = CallStateEnum.Completed; response = instance.UpdateCallWithHttpInfo(accountId, callId, updateCallBody); @@ -244,7 +244,7 @@ public void UpdateCallTest() } /// - /// Test Update Call bad request + /// Test UpdateCall with a bad request /// [Fact] public void UpdateCallBadRequest() @@ -252,7 +252,7 @@ public void UpdateCallBadRequest() CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); string callId = createCallResponse.CallId; - System.Threading.Thread.Sleep(5000); + System.Threading.Thread.Sleep(testSleep); fakeUpdateCall.State = null; ApiException Exception = Assert.Throws(() => instance.UpdateCall(accountId, callId, fakeUpdateCall)); @@ -265,125 +265,124 @@ public void UpdateCallBadRequest() } /// - /// Test Update Call unauthorized request + /// Test UpdateCall with an unauthorized client /// [Fact] public void UpdateCallUnauthorizedRequest() { fakeUpdateCall.State = CallStateEnum.Completed; - - ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateCallWithHttpInfo(accountId, "Call-Id", fakeUpdateCall)); + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateCallWithHttpInfo(accountId, testCallId, fakeUpdateCall)); Assert.Equal(401, Exception.ErrorCode); } /// - /// Test Update Call forbidden request + /// Test UpdateCall with a forbidden client /// [Fact] public void UpdateCallForbiddenRequest() { CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); - string callId = createCallResponse.CallId; - System.Threading.Thread.Sleep(5000); + + System.Threading.Thread.Sleep(testSleep); + fakeUpdateCall.State = CallStateEnum.Completed; - ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateCall(accountId, callId, fakeUpdateCall)); Assert.Equal(403, Exception.ErrorCode); - System.Threading.Thread.Sleep(5000); + System.Threading.Thread.Sleep(testSleep); ApiResponse response = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } /// - /// Test Update Call not found request + /// Test UpdateCall with a fake call-id /// [Fact] public void UpdateCallNotFoundRequest() { fakeUpdateCall.State = CallStateEnum.Completed; - - ApiException Exception = Assert.Throws(() => instance.UpdateCallWithHttpInfo(accountId, "Call-Id", fakeUpdateCall)); - + ApiException Exception = Assert.Throws(() => instance.UpdateCallWithHttpInfo(accountId, testCallId, fakeUpdateCall)); Assert.Equal(404, Exception.ErrorCode); } /// - /// Test Update Call BXML + /// Test successful UpdateCallBxml request /// [Fact] public void UpdateCallBxml() { CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); - string callId = createCallResponse.CallId; - System.Threading.Thread.Sleep(5000); + + System.Threading.Thread.Sleep(testSleep); ApiResponse updateCallBxmlResponse = instance.UpdateCallBxmlWithHttpInfo(accountId, callId, " This is a test sentence."); Assert.Equal(HttpStatusCode.NoContent, updateCallBxmlResponse.StatusCode); - System.Threading.Thread.Sleep(5000); - + System.Threading.Thread.Sleep(testSleep); + + // hangup call fakeUpdateCall.State = CallStateEnum.Completed; ApiResponse updateCallResponse = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); Assert.Equal(HttpStatusCode.OK, updateCallResponse.StatusCode); } /// - /// Test Update Call BXML bad request + /// Test UpdateCallBxml with invalid BXML /// [Fact] public void UpdateCallBxmlBadRequest() { ApiResponse createCallResponse = instance.CreateCallWithHttpInfo(accountId, mantecaCallBody); - string callId = createCallResponse.Data.CallId; - System.Threading.Thread.Sleep(5000); + + System.Threading.Thread.Sleep(testSleep); ApiException Exception = Assert.Throws(() => instance.UpdateCallBxmlWithHttpInfo(accountId, callId, "invalid BXML")); Assert.Equal(400, Exception.ErrorCode); - System.Threading.Thread.Sleep(5000); + System.Threading.Thread.Sleep(testSleep); + // hangup call fakeUpdateCall.State = CallStateEnum.Completed; ApiResponse updateCallResponse = instance.UpdateCallWithHttpInfo(accountId, callId, fakeUpdateCall); Assert.Equal(HttpStatusCode.OK, updateCallResponse.StatusCode); } /// - /// Test Update Call BXML unauthorized request + /// Test UpdateCallBxml with an unauthorized client /// [Fact] public void UpdateCallBxmlUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateCallBxmlWithHttpInfo(accountId, "Call-Id", " This is a test sentence.")); + ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateCallBxmlWithHttpInfo(accountId, testCallId, " This is a test sentence.")); Assert.Equal(401, Exception.ErrorCode); } /// - /// Test Update Call BXML forbidden request + /// Test UpdateCallBxml with a forbidden client /// [Fact] public void UpdateCallBxmlForbiddenRequest() { CreateCallResponse createCallResponse = instance.CreateCall(accountId, mantecaCallBody); - string callId = createCallResponse.CallId; - System.Threading.Thread.Sleep(5000); + + System.Threading.Thread.Sleep(testSleep); ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateCallBxmlWithHttpInfo(accountId, callId, " This is a test sentence.")); Assert.Equal(403, Exception.ErrorCode); } /// - /// Test Update Call BXML not found request + /// Test UpdateCallBxml with a fake call-id /// [Fact] public void UpdateCallBxmlNotFoundRequest() { - ApiException Exception = Assert.Throws(() => instance.UpdateCallBxmlWithHttpInfo(accountId, "Call-Id", " This is a test sentence.")); + ApiException Exception = Assert.Throws(() => instance.UpdateCallBxmlWithHttpInfo(accountId, testCallId, " This is a test sentence.")); Assert.Equal(404, Exception.ErrorCode); } } diff --git a/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs index 999ced1d..595eea51 100644 --- a/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs @@ -1,17 +1,12 @@ using System; -using System.IO; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; +using System.Text.Json; +using Newtonsoft.Json.Linq; namespace Bandwidth.Standard.Test.Integration { @@ -27,7 +22,6 @@ public class ConferencesIntegrationTests : IDisposable private UpdateConference updateConferenceBody; private CallsApi callsApiInstance; private Configuration fakeConfiguration; - private CreateCall createCallBody; private CreateCall mantecaCallBody; private UpdateConferenceMember updateConferenceMember; private string accountId; @@ -38,12 +32,15 @@ public class ConferencesIntegrationTests : IDisposable public ConferencesIntegrationTests() { + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); conferenceApiInstance = new ConferencesApi(fakeConfiguration); - + callsApiInstance = new CallsApi(fakeConfiguration); // Unauthorized API Client fakeConfiguration.Username = "badUsername"; @@ -55,7 +52,6 @@ public ConferencesIntegrationTests() fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); forbiddenInstance = new ConferencesApi(fakeConfiguration); - accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); restClient = new ApiClient(basePath: "https://voice.bandwidth.com/api/v2"); @@ -71,53 +67,13 @@ public ConferencesIntegrationTests() fallbackPassword: "mySecretPassword!" ); - createCallBody = new CreateCall( - to: Environment.GetEnvironmentVariable("USER_NUMBER"), - from: Environment.GetEnvironmentVariable("BW_NUMBER"), - displayName: "Test Call", - applicationId: Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), - answerUrl: Environment.GetEnvironmentVariable("BASE_CALLBACK_URL"), - answerMethod: CallbackMethodEnum.POST, - username: "mySecretUsername", - password: "mySecretPassword!", - answerFallbackUrl: "https://www.myFallbackServer.com/webhooks/answer", - answerFallbackMethod: CallbackMethodEnum.POST, - fallbackUsername: "mySecretUsername", - fallbackPassword: "mySecretPassword!", - disconnectUrl: "https://myServer.com/bandwidth/webhooks/disconnectUrl", - disconnectMethod: CallbackMethodEnum.POST, - callTimeout: 30, - callbackTimeout: 15, - machineDetection: new MachineDetectionConfiguration( - mode: MachineDetectionModeEnum.Async, - detectionTimeout: 15, - silenceTimeout: 10, - speechThreshold: 10, - speechEndThreshold: 5, - machineSpeechEndThreshold: 5, - delayResult: false, - callbackUrl: "https://myServer.com/bandwidth/webhooks/machineDetectionComplete", - callbackMethod: CallbackMethodEnum.POST, - username: "MySecretUsername", - password: "MySecretPassword!", - fallbackUrl: "https://myFallbackServer.com/bandwidth/webhooks/machineDetectionComplete", - fallbackMethod: CallbackMethodEnum.POST, - fallbackUsername: "MySecretUsername", - fallbackPassword: "MySecretPassword!" - ), - priority: 5, - tag: "tag Example" - ); - mantecaCallBody = new CreateCall( to: Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"), from: Environment.GetEnvironmentVariable("MANTECA_ACTIVE_NUMBER"), applicationId: Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"), - answerUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/joinConferencePause", - tag: "testID" + answerUrl: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/bxml/joinConferencePause" ); - callsApiInstance = new CallsApi(fakeConfiguration); updateConferenceMember = new UpdateConferenceMember(mute: false); testConferenceId = "Conf-Id"; testMemberId = "Member-Id"; @@ -131,29 +87,43 @@ public void Dispose() } /// - /// + /// Create and validate a call between two bandwidth numbers. Initializes the call with the Manteca + /// system. /// + /// + /// A tuple containing the test id created in Manteca to track this call, as well as the conference and call id for the created call. + /// [Fact] - public void CreateConferenceTest() + public Tuple CreateConferenceTest() { // set up request options for creating a call - var options = new RequestOptions(); - options.HeaderParameters.Add("os", Environment.GetEnvironmentVariable("OPERATING_SYSTEM")); - options.HeaderParameters.Add("language", "csharp" + Environment.GetEnvironmentVariable("CSHARP_VERSION")); - options.HeaderParameters.Add("type", "CONFERENCE"); + var jsonBody = JsonSerializer.Serialize(new + { + os = Environment.GetEnvironmentVariable("OPERATING_SYSTEM"), + language = "csharp" + Environment.GetEnvironmentVariable("CSHARP_VERSION"), + type = "CONFERENCE" + }); + var options = new RequestOptions + { + Data = jsonBody, + HeaderParameters = new Multimap + { + { "Content-Type", "application/json" } + } + }; // initialize call with Manteca - var response = restClient.Post( - path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "tests", + var response = restClient.Post( + path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/tests", options: options ); - - var testId = response.Data.ToString(); + var testId = response.RawContent; mantecaCallBody.Tag = testId; CreateCallResponse callResponse = callsApiInstance.CreateCall(accountId, mantecaCallBody); + var callId = callResponse.CallId; - Assert.IsType(callResponse.CallId); + Assert.IsType(callId); Assert.Equal(Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"), callResponse.AccountId); Assert.Equal(Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"), callResponse.ApplicationId); Assert.Equal(Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"), callResponse.To); @@ -166,50 +136,165 @@ public void CreateConferenceTest() name: testId ); Assert.Equal(HttpStatusCode.OK, listConferencesResponse.StatusCode); + + // TODO: This is not deterministic; our latest conference may not always be the one we just created due to parallelism. + // This new solution should guarantee the right conference id is grabbed. + var conferenceId = listConferencesResponse.Data[0].Id; + + var getConferenceResponse = conferenceApiInstance.GetConferenceWithHttpInfo( + accountId: accountId, + conferenceId: conferenceId + ); + Assert.Equal(HttpStatusCode.OK, getConferenceResponse.StatusCode); + Assert.Equal(conferenceId, getConferenceResponse.Data.Id); + Assert.Equal(testId, getConferenceResponse.Data.Name); + + + return Tuple.Create(testId, conferenceId); } /// - /// Test List Conferences Unauthorized + /// Get the status of the specified test by its id value from Manteca services. + /// + /// The test id associated with the test to get the status of. + /// + /// A string containing the status of the test requested. + /// + + public string GetTestStatus(string testId) + { + var options = new RequestOptions + { + HeaderParameters = new Multimap + { + { "Content-Type", "text/plain" } + } + }; + + // get test status from Manteca + var response = restClient.Get( + path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/tests/" + testId, + options: options + ); + + return response.Content.ToString(); + } + + /// + /// Tests a successful flow of creating and ending a conference. /// [Fact] - public void ListConferencesUnauthorizedRequest() + public void testConferenceAndMembers() { - // string accountId = "9900000"; - // string name = "my-custom-name"; - // string minCreatedTime = "2022-06-21T19:13:21Z"; - // string maxCreatedTime = "2022-06-21T19:13:21Z"; - // int? pageSize = 500; + Tuple createCoferenceResponse = CreateConferenceTest(); + var testId = createCoferenceResponse.Item1; + var conferenceId = createCoferenceResponse.Item2; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; + var listConferencesResponse = conferenceApiInstance.ListConferencesWithHttpInfo(accountId); + Assert.Equal(HttpStatusCode.OK, listConferencesResponse.StatusCode); + Assert.IsType(listConferencesResponse.Data[0].Name); + Assert.IsType(listConferencesResponse.Data[0].Id); - // ApiException Exception = Assert.Throws(() => conferenceApiInstance.ListConferencesWithHttpInfo(accountId, name, minCreatedTime, maxCreatedTime, pageSize)); + var getConferenceResponse = conferenceApiInstance.GetConferenceWithHttpInfo(accountId, conferenceId); + Assert.Equal(HttpStatusCode.OK, getConferenceResponse.StatusCode); + Assert.Equal(conferenceId, getConferenceResponse.Data.Id); + Assert.IsType(getConferenceResponse.Data.Name); + + var callId = getConferenceResponse.Data.ActiveMembers[0].CallId; - // Assert.Equal("Error calling ListConferences: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); - } + var GetConferenceMemberResponse = conferenceApiInstance.GetConferenceMemberWithHttpInfo(accountId, conferenceId, callId); + Assert.Equal(HttpStatusCode.OK, GetConferenceMemberResponse.StatusCode); + Assert.Equal(conferenceId, GetConferenceMemberResponse.Data.ConferenceId); + Assert.Equal(callId, GetConferenceMemberResponse.Data.CallId); + + var updateConferenceMemberResponse = conferenceApiInstance.UpdateConferenceMemberWithHttpInfo(accountId, conferenceId, callId, updateConferenceMember); + Assert.Equal(HttpStatusCode.NoContent, updateConferenceMemberResponse.StatusCode); + + var updateConferenceResponse = conferenceApiInstance.UpdateConferenceWithHttpInfo(accountId, conferenceId, updateConferenceBody); + Assert.Equal(HttpStatusCode.NoContent, updateConferenceResponse.StatusCode); + + testUpdateBxml = "This is a test bxml response"; + + var updateConferenceBxmlResponse = conferenceApiInstance.UpdateConferenceBxmlWithHttpInfo(accountId, conferenceId, testUpdateBxml); + Assert.Equal(HttpStatusCode.NoContent, updateConferenceBxmlResponse.StatusCode); + + var updateCall = new UpdateCall( + state: CallStateEnum.Completed + ); + // hang up call + callsApiInstance.UpdateCall(accountId, callId, updateCall); + } /// - /// Test List Conferences Forbidden + /// Test Conference Recordings + /// Tests a successful flow of creating a call with a recording. /// [Fact] - public void ListConferenceForbiddenRequest() + public void testConferenceRecordings() { - // string accountId = "9900000"; - // string name = "my-custom-name"; - // string minCreatedTime = "2022-06-21T19:13:21Z"; - // string maxCreatedTime = "2022-06-21T19:13:21Z"; - // int? pageSize = 500; + Tuple createCoferenceResponse = CreateConferenceTest(); + var testId = createCoferenceResponse.Item1; + var conferenceId = createCoferenceResponse.Item2; + var listConferencesResponse = conferenceApiInstance.ListConferencesWithHttpInfo(accountId); + Assert.Equal(HttpStatusCode.OK, listConferencesResponse.StatusCode); - // fakeConfiguration.Username = "forbiddenUsername"; - // fakeConfiguration.Password = "forbiddenPassword"; + testUpdateBxml = "This should be a conference recording."; + + var updateConferenceBxmlResponse = conferenceApiInstance.UpdateConferenceBxmlWithHttpInfo(accountId, conferenceId, testUpdateBxml); + Assert.Equal(HttpStatusCode.NoContent, updateConferenceBxmlResponse.StatusCode); + + var callStatus = GetTestStatus(testId); + var retryCounter = 0; + JObject callStatusJson = JObject.Parse(callStatus); + + while (!(Boolean)callStatusJson["callRecorded"] && retryCounter < 10) + { + System.Threading.Thread.Sleep(5000); + callStatus = GetTestStatus(testId); + callStatusJson = JObject.Parse(callStatus); + retryCounter++; + } + Assert.True((Boolean)callStatusJson["callRecorded"]); + + var listConferenceRecordingsResponse = conferenceApiInstance.ListConferenceRecordingsWithHttpInfo(accountId, conferenceId); + Assert.Equal(HttpStatusCode.OK, listConferenceRecordingsResponse.StatusCode); + Assert.NotEmpty(listConferenceRecordingsResponse.Data); + + ConferenceRecordingMetadata firstRecording = listConferenceRecordingsResponse.Data[0]; + Assert.Equal("complete", firstRecording.Status); + Assert.Equal(FileFormatEnum.Wav, firstRecording.FileFormat); + + var firstRecordingId = firstRecording.RecordingId; + var getConferenceRecordingResponse = conferenceApiInstance.GetConferenceRecordingWithHttpInfo(accountId, conferenceId, firstRecordingId); + Assert.Equal(HttpStatusCode.OK, getConferenceRecordingResponse.StatusCode); + Assert.Equal(conferenceId, getConferenceRecordingResponse.Data.ConferenceId); + Assert.Equal(firstRecordingId, getConferenceRecordingResponse.Data.RecordingId); + Assert.IsType(getConferenceRecordingResponse.Data.Name); + Assert.Equal("complete", getConferenceRecordingResponse.Data.Status); + Assert.Equal(FileFormatEnum.Wav, getConferenceRecordingResponse.Data.FileFormat); + + var recordingMediaResponse = conferenceApiInstance.DownloadConferenceRecordingWithHttpInfo(accountId, conferenceId, firstRecordingId); + Assert.Equal(HttpStatusCode.OK, recordingMediaResponse.StatusCode); + } - // var apiResponse = new ApiResponse>(HttpStatusCode.OK, null); - // mockClient.Setup(x => x.Get>("/accounts/{accountId}/conferences", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = conferenceApiInstance.ListConferencesWithHttpInfo(accountId, name, minCreatedTime, maxCreatedTime, pageSize); + /// + /// Test List Conferences Unauthorized + /// + [Fact] + public void ListConferencesUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListConferencesWithHttpInfo(accountId)); + Assert.Equal(401, Exception.ErrorCode); + } - // Assert.IsType>>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + /// + /// Test List Conferences Forbidden + /// + [Fact] + public void ListConferenceForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.ListConferencesWithHttpInfo(accountId)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -218,8 +303,8 @@ public void ListConferenceForbiddenRequest() [Fact] public void GetConferencesUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListConferencesWithHttpInfo(accountId)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.ListConferencesWithHttpInfo(accountId)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -228,8 +313,8 @@ public void GetConferencesUnauthorizedRequest() [Fact] public void GetConferencesForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.GetConferenceWithHttpInfo(accountId, testConferenceId)); - Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.GetConferenceWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -238,8 +323,8 @@ public void GetConferencesForbiddenRequest() [Fact] public void GetConferencesNotFound() { - ApiException Exception = Assert.Throws(() => conferenceApiInstance.GetConferenceWithHttpInfo(accountId, testConferenceId)); - Assert.Equal(404, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => conferenceApiInstance.GetConferenceWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(404, exception.ErrorCode); } /// @@ -248,8 +333,8 @@ public void GetConferencesNotFound() [Fact] public void GetConferenceMemberUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -258,8 +343,8 @@ public void GetConferenceMemberUnauthorizedRequest() [Fact] public void GetConferenceMemberForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); - Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -268,8 +353,8 @@ public void GetConferenceMemberForbiddenRequest() [Fact] public void GetConferenceMemberNotFoundRequest() { - ApiException Exception = Assert.Throws(() => conferenceApiInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); - Assert.Equal(404, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => conferenceApiInstance.GetConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId)); + Assert.Equal(404, exception.ErrorCode); } /// @@ -278,8 +363,8 @@ public void GetConferenceMemberNotFoundRequest() [Fact] public void ListConferenceRecordingsUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListConferenceRecordingsWithHttpInfo(accountId, testConferenceId)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.ListConferenceRecordingsWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -288,8 +373,8 @@ public void ListConferenceRecordingsUnauthorizedRequest() [Fact] public void ListConferenceRecordingsForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.ListConferenceRecordingsWithHttpInfo(accountId, testConferenceId)); - Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.ListConferenceRecordingsWithHttpInfo(accountId, testConferenceId)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -298,8 +383,8 @@ public void ListConferenceRecordingsForbiddenRequest() [Fact] public void GetConferenceRecordingUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -308,8 +393,8 @@ public void GetConferenceRecordingUnauthorizedRequest() [Fact] public void GetConferenceRecordingForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); - Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -318,8 +403,8 @@ public void GetConferenceRecordingForbiddenRequest() [Fact(Skip = "Actually throws a 500 error and needs to be fixed by the voice team")] public void GetConferenceRecordingNotFound() { - ApiException Exception = Assert.Throws(() => conferenceApiInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); - Assert.Equal(404, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => conferenceApiInstance.GetConferenceRecordingWithHttpInfo(accountId, testConferenceId, testRecordingId)); + Assert.Equal(404, exception.ErrorCode); } /// @@ -328,8 +413,8 @@ public void GetConferenceRecordingNotFound() [Fact] public void UpdateConferenceUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -338,8 +423,8 @@ public void UpdateConferenceUnauthorizedRequest() [Fact] public void UpdateConferenceForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); - Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -348,9 +433,9 @@ public void UpdateConferenceForbiddenRequest() [Fact] public void UpdateConferenceNotFoundRequest() { - ApiException Exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); + ApiException exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceWithHttpInfo(accountId, testConferenceId, updateConferenceBody)); - Assert.Equal(404, Exception.ErrorCode); + Assert.Equal(404, exception.ErrorCode); } /// @@ -359,8 +444,8 @@ public void UpdateConferenceNotFoundRequest() [Fact] public void UpdateConferenceBxmlUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -369,8 +454,8 @@ public void UpdateConferenceBxmlUnauthorizedRequest() [Fact] public void UpdateConferenceBxmlForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); - Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); + Assert.Equal(403, exception.ErrorCode); } /// @@ -379,8 +464,8 @@ public void UpdateConferenceBxmlForbiddenRequest() [Fact] public void UpdateConferenceBxmlNotFoundRequest() { - ApiException Exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); - Assert.Equal(404, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceBxmlWithHttpInfo(accountId, testConferenceId, testUpdateBxml)); + Assert.Equal(404, exception.ErrorCode); } /// @@ -389,8 +474,8 @@ public void UpdateConferenceBxmlNotFoundRequest() [Fact] public void UpdateConferenceMemberUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId, updateConferenceMember)); - Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.UpdateConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId, updateConferenceMember)); + Assert.Equal(401, exception.ErrorCode); } /// @@ -399,8 +484,8 @@ public void UpdateConferenceMemberUnauthorizedRequest() [Fact] public void UpdateConferenceMemberForbiddenRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId, updateConferenceMember)); - Assert.Equal(403, Exception.ErrorCode); // not erroring out + ApiException exception = Assert.Throws(() => forbiddenInstance.UpdateConferenceMemberWithHttpInfo(accountId, testConferenceId, testMemberId, updateConferenceMember)); + Assert.Equal(403, exception.ErrorCode); // not erroring out } /// @@ -409,8 +494,8 @@ public void UpdateConferenceMemberForbiddenRequest() [Fact] public void UpdateConferenceMemberNotFoundRequest() { - ApiException Exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceMember(accountId, testConferenceId, testMemberId, updateConferenceMember)); - Assert.Equal(404, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => conferenceApiInstance.UpdateConferenceMember(accountId, testConferenceId, testMemberId, updateConferenceMember)); + Assert.Equal(404, exception.ErrorCode); } } } diff --git a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs index 65be72ea..e1f79238 100644 --- a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs @@ -1,20 +1,9 @@ -/* - * Bandwidth - * - * Bandwidth's Communication APIs - * - * The version of the OpenAPI document: 1.0.0 - * Contact: letstalk@bandwidth.com - * Generated by: https://github.com/openapitools/openapi-generator.git - */ - using System; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; namespace Bandwidth.Standard.Test.Integration @@ -24,14 +13,15 @@ namespace Bandwidth.Standard.Test.Integration /// public class MFAIntegrationTests : IDisposable { - private MFAApi instance; - private MFAApi unauthorizedInstance; - private MFAApi forbiddenInstance; - private Configuration fakeConfiguration; private string accountId; + private CodeRequest badCodeRequest; + private Configuration fakeConfiguration; + private MFAApi forbiddenInstance; + private MFAApi instance; private CodeRequest messagingCodeRequest; + private MFAApi unauthorizedInstance; + private VerifyCodeRequest verifyCodeRequest; private CodeRequest voiceCodeRequest; - private CodeRequest badCodeRequest; public MFAIntegrationTests() { @@ -80,6 +70,13 @@ public MFAIntegrationTests() digits: 6 ); + // Verify Code Request + verifyCodeRequest = new VerifyCodeRequest( + to: Environment.GetEnvironmentVariable("USER_NUMBER"), + expirationTimeInMinutes: 3, + code: "123456" + ); + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); } @@ -98,110 +95,115 @@ public void InstanceTest() } /// - /// Test GenerateMessagingCode + /// Test a successful GenerateMessagingCode request /// [Fact] public void GenerateMessagingCodeTest() { var response = instance.GenerateMessagingCodeWithHttpInfo(accountId, messagingCodeRequest); - Assert.IsType>(response); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } /// - /// Test GenerateVoiceCode + /// Test GenerateMessagingCode with a bad code request /// [Fact] - public void GenerateVoiceCodeTest() + public void GenerateMessagingCodeBadRequest() { - var response = instance.GenerateVoiceCodeWithHttpInfo(accountId, voiceCodeRequest); - - Assert.IsType>(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); + ApiException Exception = Assert.Throws(() => instance.GenerateMessagingCode(accountId, badCodeRequest)); + Assert.Equal(400, Exception.ErrorCode); } /// - /// Test VerifyCode + /// Test GenerateMessagingCode with an unauthorized client /// [Fact] - public void VerifyCodeTest() + public void GenerateMessagingCodeUnauthorizedRequest() { - VerifyCodeRequest verifyCodeRequest = new VerifyCodeRequest( - to: Environment.GetEnvironmentVariable("USER_NUMBER"), - expirationTimeInMinutes: 3, - code: "123456" - ); - - var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); - - Assert.IsType>(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GenerateMessagingCode(accountId, messagingCodeRequest)); + Assert.Equal(401, Exception.ErrorCode); } /// - /// Test failed Generate Messaging Code Request + /// Test GenerateMessagingCode with a forbidden client /// [Fact] - public void GenerateMessagingCodeBadRequest() + public void GenerateMessagingCodeForbiddenRequest() { - ApiException Exception = Assert.Throws(() => instance.GenerateMessagingCode(accountId, badCodeRequest)); + ApiException Exception = Assert.Throws(() => forbiddenInstance.GenerateMessagingCode(accountId, messagingCodeRequest)); + Assert.Equal(403, Exception.ErrorCode); + } - Assert.Equal(400, Exception.ErrorCode); + /// + /// Test a successful GenerateVoiceCode request + /// + [Fact] + public void GenerateVoiceCodeTest() + { + var response = instance.GenerateVoiceCodeWithHttpInfo(accountId, voiceCodeRequest); + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } /// - /// Test failed Generate Voice Code Request + /// Test GenerateVoiceCode with a bad code request /// [Fact] public void GenerateVoiceCodeBadRequest() { ApiException Exception = Assert.Throws(() => instance.GenerateVoiceCode(accountId, badCodeRequest)); - Assert.Equal(400, Exception.ErrorCode); } /// - /// Test unauthorized Generate Messaging Code Request + /// Test GenerateVoiceCode with an unauthorized client /// [Fact] - public void GenerateMessagingCodeUnauthorizedRequest() + public void GenerateVoiceCodeUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.GenerateMessagingCode(accountId, messagingCodeRequest)); - - Assert.Equal(401, Exception.ErrorCode); //throwing 403 + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GenerateVoiceCode(accountId, voiceCodeRequest)); + Assert.Equal(401, Exception.ErrorCode); } /// - /// Test unauthorized Generate Voice Code Request + /// Test GenerateVoiceCode with a forbidden client /// [Fact] - public void GenerateVoiceCodeUnauthorizedRequest() + public void GenerateVoiceCodeForbiddenRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.GenerateVoiceCode(accountId, voiceCodeRequest)); - - Assert.Equal(401, Exception.ErrorCode); //throwing 403 + ApiException Exception = Assert.Throws(() => forbiddenInstance.GenerateVoiceCode(accountId, voiceCodeRequest)); + Assert.Equal(403, Exception.ErrorCode); } /// - /// Test forbidden Generate Messaging Code Request + /// Test a successful VerifyCode request /// [Fact] - public void GenerateMessagingCodeForbiddenRequest() + public void VerifyCodeTest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.GenerateMessagingCode(accountId, messagingCodeRequest)); - - Assert.Equal(403, Exception.ErrorCode); + var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); + Assert.IsType>(response); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); } /// - /// Test forbidden Generate Voice Code Request + /// Test VerifyCode with an unauthorized client /// [Fact] - public void GenerateVoiceCodeForbiddenRequest() + public void VerifyCodeUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => forbiddenInstance.GenerateVoiceCode(accountId, voiceCodeRequest)); + ApiException Exception = Assert.Throws(() => unauthorizedInstance.VerifyCode(accountId, verifyCodeRequest)); + Assert.Equal(401, Exception.ErrorCode); + } + /// + /// Test VerifyCode with a forbidden client + /// + [Fact] + public void VerifyCodeForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.VerifyCode(accountId, verifyCodeRequest)); Assert.Equal(403, Exception.ErrorCode); } } diff --git a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs index c41dfc58..5ee64fec 100644 --- a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs @@ -1,26 +1,11 @@ -/* - * Bandwidth - * - * Bandwidth's Communication APIs - * - * The version of the OpenAPI document: 1.0.0 - * Contact: letstalk@bandwidth.com - * Generated by: https://github.com/openapitools/openapi-generator.git - */ - using System; using System.IO; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; namespace Bandwidth.Standard.Test.Integration @@ -30,28 +15,25 @@ namespace Bandwidth.Standard.Test.Integration /// public class MediaIntegrationTests : IDisposable { + private string accountId; + private Configuration fakeConfiguration; private MediaApi instance; + private System.IO.Stream testMediaBody; + private string testMediaId; + private string testContentType; private MediaApi unauthorizedInstance; - private Configuration fakeConfiguration; - private string accountId; - private string mediaId; - private System.IO.Stream mediaBody; - private string contentType; public MediaIntegrationTests() { - - mediaId = $"text-media-id-{Guid.NewGuid()}"; - //API Client accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); instance = new MediaApi(fakeConfiguration); - // Unauthorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://messaging.bandwidth.com/api/v2"; @@ -60,12 +42,12 @@ public MediaIntegrationTests() unauthorizedInstance = new MediaApi(fakeConfiguration); // Create a media file to use for testing - + testMediaId = $"test-media-id-{Guid.NewGuid()}"; string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string relativePath = "../../../Fixtures/csharp_cat.jpeg"; string filePath = Path.Combine(baseDirectory, relativePath); - mediaBody = new System.IO.FileStream(filePath, FileMode.Open); - contentType = "image/jpeg"; + testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); + testContentType = "image/jpeg"; } public void Dispose() @@ -82,24 +64,40 @@ public void InstanceTest() Assert.IsType(instance); } - /// - /// Test Upload Media + /// Test successful UploadMedia Request /// [Fact] public void UploadMediaTest() { - var responseWithHttpInfo = instance.UploadMediaWithHttpInfo(accountId, mediaId, mediaBody, contentType); - + var responseWithHttpInfo = instance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType); Assert.IsType>(responseWithHttpInfo); Assert.Equal(HttpStatusCode.NoContent, responseWithHttpInfo.StatusCode); + testMediaBody.Close(); + } + + /// + /// Test UploadMedia with an unauthorized client + /// /// + [Fact] + public void UploadMediaUnauthorized() + { + ApiException exception = Assert.Throws(() => unauthorizedInstance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType)); + Assert.Equal(401, exception.ErrorCode); + } - instance.UploadMedia(accountId, mediaId, mediaBody, contentType); - mediaBody.Close(); + /// + /// Test UploadMedia with a forbidden client + /// + [Fact] + public void UploadMediaForbidden() + { + ApiException exception = Assert.Throws(() => instance.UploadMediaWithHttpInfo("not-an-account-id", testMediaId, testMediaBody, testContentType)); + Assert.Equal(403, exception.ErrorCode); } /// - /// Test List Media + /// Test successful ListMedia Request /// [Fact] public void ListMediaTest() @@ -113,46 +111,112 @@ public void ListMediaTest() } /// - /// Test Get Media + /// Test ListMedia with an unauthorized client + /// + [Fact] + public void ListMediaUnauthorized() + { + ApiException exception = Assert.Throws(() => unauthorizedInstance.ListMediaWithHttpInfo(accountId)); + Assert.Equal(401, exception.ErrorCode); + } + + /// + /// Test ListMedia with a forbidden client + /// + [Fact] + public void ListMediaForbidden() + { + ApiException exception = Assert.Throws(() => instance.ListMediaWithHttpInfo("not-an-account-id")); + Assert.Equal(403, exception.ErrorCode); + } + + /// + /// Test successful GetMedia Request /// [Fact] public void GetMediaTest() { - var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, mediaId, mediaBody, contentType); + var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType); - var responseWithHttpInfo = instance.GetMediaWithHttpInfo(accountId, mediaId); + var responseWithHttpInfo = instance.GetMediaWithHttpInfo(accountId, testMediaId); Assert.Equal(HttpStatusCode.OK, responseWithHttpInfo.StatusCode); - var response = instance.GetMedia(accountId, mediaId); + var response = instance.GetMedia(accountId, testMediaId); Assert.IsAssignableFrom(response); - mediaBody.Close(); + testMediaBody.Close(); + } + + /// + /// Test GetMedia with an unauthorized client + /// + [Fact] + public void GetMediaUnauthorized() + { + ApiException exception = Assert.Throws(() => unauthorizedInstance.GetMediaWithHttpInfo(accountId, testMediaId)); + Assert.Equal(401, exception.ErrorCode); + } + + /// + /// Test GetMedia with a forbidden client + /// + [Fact] + public void GetMediaForbidden() + { + ApiException exception = Assert.Throws(() => instance.GetMediaWithHttpInfo("not-an-account-id", testMediaId)); + Assert.Equal(403, exception.ErrorCode); + } + + /// + /// Test GetMedia with a fake media id + /// + [Fact] + public void GetMediaNotFound() + { + ApiException exception = Assert.Throws(() => instance.GetMediaWithHttpInfo(accountId, "not-a-media-id.jpg")); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test Delete Media + /// Test successful DeleteMedia Request /// [Fact] public void DeleteMediaTest() { - var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, mediaId, mediaBody, contentType); + var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType); - var responseWithHttpInfo = instance.DeleteMediaWithHttpInfo(accountId, mediaId); + var responseWithHttpInfo = instance.DeleteMediaWithHttpInfo(accountId, testMediaId); Assert.Equal(HttpStatusCode.NoContent, responseWithHttpInfo.StatusCode); + testMediaBody.Close(); + } - instance.DeleteMedia(accountId, mediaId); - mediaBody.Close(); + /// + /// Test DeleteMedia with an unauthorized client + /// + [Fact] + public void DeleteMediaUnauthorized() + { + ApiException exception = Assert.Throws(() => unauthorizedInstance.DeleteMediaWithHttpInfo(accountId, testMediaId)); + Assert.Equal(401, exception.ErrorCode); } /// - /// Test Get media with Bandwidth Ids + /// Test DeleteMedia with a forbidden client /// [Fact] - public void getMediaWithBandwidthIdsTest() + public void DeleteMediaForbidden() { - // use a nonexistent mediaId - results in a 404 - mediaId = "abcd1234-e5f6-1111-2222-3456ghi7890/image123456.jpg"; + ApiException exception = Assert.Throws(() => instance.DeleteMediaWithHttpInfo("not-an-account-id", testMediaId)); + Assert.Equal(403, exception.ErrorCode); + } - ApiException exception = Assert.Throws(() => instance.GetMediaWithHttpInfo(accountId, mediaId)); + /// + /// Test DeleteMedia with a fake media id + /// API does not throw an exception + /// + [Fact (Skip = "API does not throw an exception")] + public void DeleteMediaNotFound() + { + ApiException exception = Assert.Throws(() => instance.DeleteMediaWithHttpInfo(accountId, "not-a-media-id.jpg")); Assert.Equal(404, exception.ErrorCode); } } diff --git a/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs index b1cd7415..6f3fcbb8 100644 --- a/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MessagesIntegrationTests.cs @@ -1,26 +1,10 @@ - - /* Bandwidth - * - * Bandwidth's Communication APIs - * - * The version of the OpenAPI document: 1.0.0 - * Contact: letstalk@bandwidth.com - * Generated by: https://github.com/openapitools/openapi-generator.git - */ - using System; -using System.IO; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; namespace Bandwidth.Standard.Test.Integration @@ -30,16 +14,18 @@ namespace Bandwidth.Standard.Test.Integration /// public class MessagesIntegrationTests : IDisposable { - private MessagesApi instance; - private MessagesApi unauthorizedInstance; - private Configuration fakeConfiguration; private string accountId; + private Configuration fakeConfiguration; + private MessagesApi forbiddenInstance; + private MessagesApi instance; private MessageRequest messageRequest; + private MessagesApi unauthorizedInstance; public MessagesIntegrationTests() { - // API Client accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://messaging.bandwidth.com/api/v2"; fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); @@ -53,6 +39,13 @@ public MessagesIntegrationTests() fakeConfiguration.Password = "badPassword"; unauthorizedInstance = new MessagesApi(fakeConfiguration); + // Forbidden API Client + fakeConfiguration = new Configuration(); + fakeConfiguration.BasePath = "https://messaging.bandwidth.com/api/v2"; + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); + forbiddenInstance = new MessagesApi(fakeConfiguration); + // Message Request messageRequest = new MessageRequest( applicationId: Environment.GetEnvironmentVariable("BW_MESSAGING_APPLICATION_ID"), @@ -87,37 +80,43 @@ public void CreateMessageTest() { var response = instance.CreateMessageWithHttpInfo(accountId, messageRequest); Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); - - var message = response.Data; - - Assert.NotNull(message.ApplicationId); - Assert.NotNull(message.To); - Assert.NotNull(message.From); - Assert.NotNull(message.Owner); - Assert.NotNull(message.Text); - Assert.NotNull(message.Media); - Assert.NotNull(message.Tag); - Assert.IsType(message.Priority); - Assert.NotNull(message.Priority); - Assert.Equal(1, message.SegmentCount); - Assert.IsType(message.Time); - + Assert.NotNull(response.Data.ApplicationId); + Assert.NotNull(response.Data.To); + Assert.NotNull(response.Data.From); + Assert.NotNull(response.Data.Owner); + Assert.NotNull(response.Data.Text); + Assert.NotNull(response.Data.Media); + Assert.NotNull(response.Data.Tag); + Assert.IsType(response.Data.Priority); + Assert.NotNull(response.Data.Priority); + Assert.Equal(1, response.Data.SegmentCount); + Assert.IsType(response.Data.Time); } /// - /// Test failed CreateMessage Request + /// Test CreateMessage with an invalid message request /// [Fact] public void CreateMessageBadRequest() { - messageRequest.ApplicationId = null; // Bad Request - + messageRequest.ApplicationId = null; ApiException Exception = Assert.Throws(() => instance.CreateMessage(accountId, messageRequest)); - Assert.Equal(400, Exception.ErrorCode); // no exception thrown + Assert.Equal(400, Exception.ErrorCode); + } + + /// + /// Test CreateMessage with invalid media + /// + [Fact] + public void CreateMessageInvalidMedia() + { + messageRequest.Media = new List { "not media" }; + ApiException Exception = Assert.Throws(() => instance.CreateMessageWithHttpInfo(accountId, messageRequest)); + Assert.Equal(400, Exception.ErrorCode); } /// - /// Test Unauthorized CreateMessage Request + /// Test CreateMessage with an unauthorized client /// [Fact] public void CreateMessageUnauthorizedRequest() @@ -127,19 +126,18 @@ public void CreateMessageUnauthorizedRequest() } /// - /// Test Create Message invalid media + /// Test create message with a forbidden client + /// API does not throw an error /// - [Fact] - public void CreateMessageInvalidMedia() + [Fact (Skip = "API does not throw an error")] + public void CreateMessageForbiddenRequest() { - messageRequest.Media = new List { "not media" }; // Bad Request - - ApiException Exception = Assert.Throws(() => instance.CreateMessageWithHttpInfo(accountId, messageRequest)); - Assert.Equal(400, Exception.ErrorCode); + ApiException Exception = Assert.Throws(() => forbiddenInstance.CreateMessage(accountId, messageRequest)); + Assert.Equal(401, Exception.ErrorCode); } /// - /// Test ListMessages + /// Test a successful ListMessages request /// [Fact] public void ListMessagesTest() @@ -150,7 +148,6 @@ public void ListMessagesTest() messageStatus: MessageStatusEnum.DELIVERED, messageType: MessageTypeEnum.Sms ); - Assert.IsType>(response); Assert.Equal(HttpStatusCode.OK, response.StatusCode); Assert.NotEqual(0, response.Data.TotalCount); @@ -158,7 +155,6 @@ public void ListMessagesTest() Assert.IsType(response.Data.Messages[0]); var message = response.Data.Messages[0]; - Assert.Equal(accountId, message.AccountId); Assert.Matches("^\\+[1-9]\\d{1,14}$", message.DestinationTn); Assert.Equal(ListMessageDirectionEnum.OUTBOUND, message.MessageDirection); @@ -171,28 +167,33 @@ public void ListMessagesTest() } /// - /// Test failed ListMessages Request + /// Test ListMessages without any messages /// [Fact] public void ListMessagesBadRequest() { - ApiException Exception = Assert.Throws(() => instance.ListMessages( - accountId: accountId - )); - + ApiException Exception = Assert.Throws(() => instance.ListMessages(accountId)); Assert.Equal(400, Exception.ErrorCode); } /// - /// Test Unauthorized ListMessages Request + /// Test ListMessages with an unauthorized client /// [Fact] public void ListMessagesUnauthorizedRequest() { - ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListMessages( - accountId: accountId - )); + ApiException Exception = Assert.Throws(() => unauthorizedInstance.ListMessages(accountId)); + Assert.Equal(401, Exception.ErrorCode); + } + /// + /// Test ListMessages with a forbidden client + /// API throws a 400 rather than a 401 + /// + [Fact (Skip = "API throws a 400 rather than a 401")] + public void ListMessagesForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.ListMessages(accountId)); Assert.Equal(401, Exception.ErrorCode); } } diff --git a/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs index daa1889c..6ba2d971 100644 --- a/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs @@ -1,22 +1,10 @@ -/* - * Bandwidth - * - * Bandwidth's Communication APIs - * - * The version of the OpenAPI document: 1.0.0 - * Contact: letstalk@bandwidth.com - * Generated by: https://github.com/openapitools/openapi-generator.git - */ - using System; using System.Collections.Generic; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; namespace Bandwidth.Standard.Test.Integration @@ -26,15 +14,19 @@ namespace Bandwidth.Standard.Test.Integration /// public class PhoneNumberLookupIntegrationTests : IDisposable { + private string accountId; + private Configuration fakeConfiguration; + private PhoneNumberLookupApi forbiddenInstance; private PhoneNumberLookupApi instance; + private string testRequestId; private PhoneNumberLookupApi unauthorizedInstance; - private PhoneNumberLookupApi forbiddenInstance; - private Configuration fakeConfiguration; - private string accountId; public PhoneNumberLookupIntegrationTests() { accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + testRequestId = "test-request-id"; + + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); @@ -67,24 +59,50 @@ public void InstanceTest() } /// - /// Test GetLookupStatus + /// Test successful GetLookupStatus request /// [Fact] public void GetLookupStatusTest() { + LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + var response = instance.CreateLookupWithHttpInfo(accountId, lookupRequest); + var lookupStatus = instance.GetLookupStatus(accountId, response.Data.RequestId); + Assert.IsType(lookupStatus); + Assert.Equal(response.Data.RequestId, lookupStatus.RequestId); + Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), lookupStatus.Result[0].E164Format); } /// - /// Test CreateLookup + /// Test GetLookupStatus with an unauthorized client + /// + [Fact] + public void GetLookupStatusUnauthorizedRequest() + { + ApiException Exception = Assert.Throws(() => unauthorizedInstance.GetLookupStatus(accountId, testRequestId)); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test GetLookupStatus with a forbidden client + /// API throws a 401 rather than the expected 403 + /// + [Fact] + public void GetLookupStatusForbiddenRequest() + { + ApiException Exception = Assert.Throws(() => forbiddenInstance.GetLookupStatus(accountId, testRequestId)); + // Assert.Equal(403, Exception.ErrorCode); + Assert.Equal(401, Exception.ErrorCode); + } + + /// + /// Test successful CreateLookup request /// [Fact] public void CreateLookupTest() { LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); - var response = instance.CreateLookupWithHttpInfo(accountId, lookupRequest); - Assert.IsType>(response); Assert.Equal(LookupStatusEnum.INPROGRESS, response.Data.Status); Assert.IsType(response.Data.RequestId); @@ -92,7 +110,6 @@ public void CreateLookupTest() Assert.Equal(HttpStatusCode.Accepted, response.StatusCode); var lookupStatus = instance.GetLookupStatus(accountId, response.Data.RequestId); - Assert.IsType(lookupStatus); Assert.Equal(response.Data.RequestId, lookupStatus.RequestId); Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), lookupStatus.Result[0].E164Format); @@ -100,13 +117,12 @@ public void CreateLookupTest() } /// - /// Test failed phone number lookup + /// Test CreateLookup with a bad request /// [Fact] - public void CreateLookupFailedRequest() + public void CreateLookupBadRequest() { LookupRequest lookupRequest = new LookupRequest(new List { "not a number" }); - ApiException exception = Assert.Throws(() => instance.CreateLookup(accountId, lookupRequest)); var error = new TnLookupRequestError(exception.Message); Assert.IsType(error); @@ -115,43 +131,38 @@ public void CreateLookupFailedRequest() } /// - /// Test duplicate phone number lookup + /// Test CreateLookup with a duplicate phone number lookup /// [Fact] public void CreateLookupDuplicateRequest() { LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER"), Environment.GetEnvironmentVariable("BW_NUMBER") }); - ApiException Exception = Assert.Throws(() => instance.CreateLookup(accountId, lookupRequest)); - Assert.Equal(400, Exception.ErrorCode); Assert.IsType(Exception.Message); } /// - /// Test Unauthorize request + /// Test CreateLookup with an unauthorized client /// [Fact] public void CreateLookupUnauthorizedRequest() { LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); - ApiException Exception = Assert.Throws(() => unauthorizedInstance.CreateLookup(accountId, lookupRequest)); - Assert.Equal(401, Exception.ErrorCode); } /// - /// Test Forbidden request + /// Test CreateLookup with a forbidden client /// [Fact] public void CreateLookupForbiddenRequest() { LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); - ApiException Exception = Assert.Throws(() => forbiddenInstance.CreateLookup(accountId, lookupRequest)); - //This API throws a 401 when a user provides valid credentials with the `TN Lookup` role disabled + // Assert.Equal(403, Exception.ErrorCode); Assert.Equal(401, Exception.ErrorCode); } } diff --git a/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs index 8ff02ae3..bfd3a232 100644 --- a/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs @@ -1,27 +1,13 @@ -/* - * Bandwidth - * - * Bandwidth's Communication APIs - * - * The version of the OpenAPI document: 1.0.0 - * Contact: letstalk@bandwidth.com - * Generated by: https://github.com/openapitools/openapi-generator.git - */ - using System; -using System.IO; using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Reflection; -using RestSharp; using Xunit; using Bandwidth.Standard.Client; using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; -using Moq; using System.Net; +using System.Text.Json; +using Newtonsoft.Json.Linq; namespace Bandwidth.Standard.Test.Integration { @@ -30,16 +16,72 @@ namespace Bandwidth.Standard.Test.Integration /// public class RecordingsIntegrationTests : IDisposable { - private RecordingsApi instance; + private RecordingsApi recordingApiInstance; + private CallsApi callsApiInstance; + private RecordingsApi unauthorizedInstance; + private RecordingsApi forbiddenInstance; private Configuration fakeConfiguration; + private ApiClient restClient; + private CreateCall mantecaCallBody; + private TranscribeRecording testTranscribeRecording; + private string accountId; + private string testCallId; + private string testRecordingId; + private string BW_USERNAME; + private string BW_PASSWORD; + private string MANTECA_ACTIVE_NUMBER; + private string MANTECA_IDLE_NUMBER; + private string MANTECA_APPLICATION_ID; + private string MANTECA_BASE_URL; + private string BW_FORBIDDEN_USERNAME; + private string BW_FORBIDDEN_PASSWORD; public RecordingsIntegrationTests() { + //Constants + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + testCallId = "callId"; + testRecordingId = "recordingId"; + BW_USERNAME = Environment.GetEnvironmentVariable("BW_USERNAME"); + BW_PASSWORD = Environment.GetEnvironmentVariable("BW_PASSWORD"); + MANTECA_ACTIVE_NUMBER = Environment.GetEnvironmentVariable("MANTECA_ACTIVE_NUMBER"); + MANTECA_IDLE_NUMBER = Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"); + MANTECA_APPLICATION_ID = Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"); + MANTECA_BASE_URL = Environment.GetEnvironmentVariable("MANTECA_BASE_URL"); + BW_FORBIDDEN_USERNAME = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + BW_FORBIDDEN_PASSWORD = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); + + //API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; - fakeConfiguration.Username = "username"; - fakeConfiguration.Password = "password"; - instance = new RecordingsApi(fakeConfiguration); + fakeConfiguration.Username = BW_USERNAME; + fakeConfiguration.Password = BW_PASSWORD; + recordingApiInstance = new RecordingsApi(fakeConfiguration); + callsApiInstance = new CallsApi(fakeConfiguration); + + // Unauthorized API Client + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new RecordingsApi(fakeConfiguration); + + // Forbidden API Client + fakeConfiguration.Username = BW_FORBIDDEN_USERNAME; + fakeConfiguration.Password = BW_FORBIDDEN_PASSWORD; + forbiddenInstance = new RecordingsApi(fakeConfiguration); + + restClient = new ApiClient(basePath: "https://voice.bandwidth.com/api/v2"); + + mantecaCallBody = new CreateCall( + to: MANTECA_IDLE_NUMBER, + from: MANTECA_ACTIVE_NUMBER, + applicationId: MANTECA_APPLICATION_ID, + answerUrl: MANTECA_BASE_URL + "/bxml/joinConferencePause" + ); + + testTranscribeRecording = new TranscribeRecording( + callbackUrl: MANTECA_BASE_URL + "/transcriptions", + tag: "test" + ); } public void Dispose() @@ -53,607 +95,512 @@ public void Dispose() [Fact] public void InstanceTest() { - Assert.IsType(instance); + Assert.IsType(recordingApiInstance); } /// - /// Test DeleteCallTranscription + /// Create and validate a call between two bandwidth numbers. Initializes the call with the Manteca system. /// + /// + /// A tuple containing the test id created in Manteca to track this call, as well as the call id for the created call. + /// [Fact] - public void DeleteCallTranscriptionTest() + public Tuple CreateAndValidateCall() + { + var jsonBody = JsonSerializer.Serialize(new + { + os = Environment.GetEnvironmentVariable("OPERATING_SYSTEM"), + language = "csharp" + Environment.GetEnvironmentVariable("CSHARP_VERSION"), + type = "CALL" + }); + var options = new RequestOptions + { + Data = jsonBody, + HeaderParameters = new Multimap + { + { "Content-Type", "application/json" } + } + }; + + // initialize call with Manteca + var response = restClient.Post( + path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/tests", + options: options + ); + + var testId = response.RawContent; + mantecaCallBody.Tag = testId; + + var createCallResponse = callsApiInstance.CreateCallWithHttpInfo(accountId, mantecaCallBody); + Assert.Equal(47, createCallResponse.Data.CallId.Length); + Assert.Equal(accountId, createCallResponse.Data.AccountId); + Assert.Equal(MANTECA_APPLICATION_ID, createCallResponse.Data.ApplicationId); + Assert.Equal(MANTECA_IDLE_NUMBER, createCallResponse.Data.To); + Assert.Equal(MANTECA_ACTIVE_NUMBER, createCallResponse.Data.From); + Assert.Equal("https://voice.bandwidth.com/api/v2/accounts/" + accountId + "/calls/" + createCallResponse.Data.CallId, createCallResponse.Data.CallUrl); + + return new Tuple(testId, createCallResponse.Data.CallId); + } + + /// + /// Creates and completes an entire recorded call lifecycle. A call should be completed and fully recorded. + /// + /// + /// A tuple containing the test id to track this call in the Manteca system and the call id associated with the call in Bandwidth services. + /// + public Tuple CompleteRecordedCall() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + mantecaCallBody.AnswerUrl = MANTECA_BASE_URL + "/bxml/startRecording"; + Tuple createCallResponse = CreateAndValidateCall(); + var testId = createCallResponse.Item1; + var callId = createCallResponse.Item2; + + System.Threading.Thread.Sleep(12000); + var callStatus = GetTestStatus(testId); + JObject callStatusJson = JObject.Parse(callStatus); + var retryCounter = 0; + + while(!(Boolean)callStatusJson["callRecorded"] && retryCounter < 40) + { + System.Threading.Thread.Sleep(5000); + callStatus = GetTestStatus(testId); + callStatusJson = JObject.Parse(callStatus); + retryCounter++; + } - // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, recordingId); + Assert.True((Boolean)callStatusJson["callRecorded"]); + + return(new Tuple (testId,callId)); - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); } /// - /// Test Unauthorized DeleteCallTranscription + /// Get the status of the specified test by its id value from Manteca services. /// - [Fact] - public void DeleteCallTranscriptionUnauthorizedRequest() + /// The test id associated with the test to get the status of. + /// + /// A string containing the status of the test requested. + /// + public string GetTestStatus(string testId) { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DeleteCallTranscription: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); + var options = new RequestOptions + { + HeaderParameters = new Multimap + { + { "Content-Type", "text/plain" } + } + }; + + // get test status from Manteca + var response = restClient.Get( + path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/tests/" + testId, + options: options + ); + + return response.Content.ToString(); } /// - /// Test Forbidden DeleteCallTranscription + /// Tests a successful flow of creating a call with a recording. /// [Fact] - public void DeleteCallTranscriptionForbiddenRequest() + public void TestSuccessfulCallRecording() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // fakeConfiguration.Username = "ForbiddenUsername"; - // fakeConfiguration.Password = "ForbiddenPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DeleteCallTranscription: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); + Tuple recordedCallResponse = CompleteRecordedCall(); + var testId = recordedCallResponse.Item1; + var callId = recordedCallResponse.Item2; + + var listCallResponse = recordingApiInstance.ListCallRecordingsWithHttpInfo(accountId,callId); + Assert.Equal(HttpStatusCode.OK, listCallResponse.StatusCode); + + List callRecording = listCallResponse.Data; + Assert.Single(callRecording); + + var firstRecording = callRecording[0]; + Assert.Equal(accountId, firstRecording.AccountId); + Assert.Equal(callId, firstRecording.CallId); + Assert.Equal(MANTECA_APPLICATION_ID, firstRecording.ApplicationId); + Assert.Equal("complete", firstRecording.Status); + Assert.Equal(FileFormatEnum.Wav, firstRecording.FileFormat); + + var firstRecordingId = firstRecording.RecordingId; + + var getCallRecordingResponse = recordingApiInstance.GetCallRecordingWithHttpInfo(accountId, callId, firstRecordingId); + Assert.Equal(HttpStatusCode.OK, getCallRecordingResponse.StatusCode); + + var recording = getCallRecordingResponse.Data; + Assert.Equal(firstRecordingId, recording.RecordingId); + Assert.Equal(accountId, recording.AccountId); + Assert.Equal(callId, recording.CallId); + Assert.Equal(MANTECA_APPLICATION_ID, recording.ApplicationId); + Assert.Equal("complete", recording.Status); + Assert.Equal(FileFormatEnum.Wav, recording.FileFormat); + + var downloadCallRecordingResponse = recordingApiInstance.DownloadCallRecordingWithHttpInfo(accountId, callId, firstRecordingId); + var transcribeRecordingRequest = new TranscribeRecording( + callbackUrl: MANTECA_BASE_URL + "/transcriptions", + tag: testId + ); + var transcribeCallRecording = recordingApiInstance.TranscribeCallRecordingWithHttpInfo(accountId, callId, firstRecordingId, transcribeRecordingRequest); + Assert.Equal(HttpStatusCode.NoContent, transcribeCallRecording.StatusCode); + + var callStatus = GetTestStatus(testId); + var retries = 0; + JObject callStatusJson = JObject.Parse(callStatus); + while(!(Boolean)callStatusJson["callTranscribed"] && retries < 40) + { + System.Threading.Thread.Sleep(5000); + callStatus = GetTestStatus(testId); + callStatusJson = JObject.Parse(callStatus); + retries++; + } + Assert.True((Boolean)callStatusJson["callTranscribed"]); + var transcriptionResponse = recordingApiInstance.GetCallTranscriptionWithHttpInfo(accountId, callId, firstRecordingId); + Assert.Equal(HttpStatusCode.OK, transcriptionResponse.StatusCode); + + var transcription = transcriptionResponse.Data; + Assert.Single(transcription.Transcripts); + + var firstTranscript = transcription.Transcripts[0]; + Assert.IsType(firstTranscript); + Assert.IsType(firstTranscript.Text); + Assert.IsType(firstTranscript.Confidence); + + // delete transcription + var deleteTranscriptionResponse = recordingApiInstance.DeleteCallTranscriptionWithHttpInfo(accountId, callId, firstRecordingId); + Assert.Equal(HttpStatusCode.NoContent, deleteTranscriptionResponse.StatusCode); + + // making sure transcription is deleted + ApiException exception = Assert.Throws(() => recordingApiInstance.GetCallTranscription(accountId, callId, firstRecordingId)); + Assert.Equal(404, exception.ErrorCode); + + var deleteRecordingMediaResponse = recordingApiInstance.DeleteRecordingMediaWithHttpInfo(accountId, callId, firstRecordingId); + Assert.Equal(HttpStatusCode.NoContent, deleteRecordingMediaResponse.StatusCode); + + // Delete recording + var deleteRecordingResponse = recordingApiInstance.DeleteRecordingWithHttpInfo(accountId, callId, firstRecordingId); + Assert.Equal(HttpStatusCode.NoContent, deleteRecordingResponse.StatusCode); + var callRecordings = recordingApiInstance.ListCallRecordings(accountId, callId); + Assert.Empty(callRecordings); } /// - /// Test DeleteRecording + /// Tests a successful UpdateCallRecordingState request /// [Fact] - public void DeleteRecordingTest() + public void TestSuccessfulUpdateActiveRecording() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; + mantecaCallBody.AnswerUrl = MANTECA_BASE_URL + "/bxml/startLongRecording"; + Tuple createCallResponse = CreateAndValidateCall(); + var testId = createCallResponse.Item1; + var callId = createCallResponse.Item2; + + + var callStatus = GetTestStatus(testId); + JObject callStatusJson = JObject.Parse(callStatus); + var retryCounter = 0; + + while((string)callStatusJson["status"] == "DEAD" && retryCounter < 40) + { + System.Threading.Thread.Sleep(5000); + callStatus = GetTestStatus(testId); + callStatusJson = JObject.Parse(callStatus); + retryCounter++; + } + + Assert.Equal("ALIVE", (string)callStatusJson["status"]); + + System.Threading.Thread.Sleep(5000); + + var updateCallRecording = new UpdateCallRecording(state: RecordingStateEnum.Paused); + var updateCallRecordingResponse = recordingApiInstance.UpdateCallRecordingStateWithHttpInfo(accountId, callId, updateCallRecording); + Assert.Equal(HttpStatusCode.OK, updateCallRecordingResponse.StatusCode); - // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.DeleteRecordingWithHttpInfo(accountId, callId, recordingId); + // Update the call to resume the recording + updateCallRecording.State = RecordingStateEnum.Recording; + updateCallRecordingResponse = recordingApiInstance.UpdateCallRecordingStateWithHttpInfo(accountId, callId, updateCallRecording); + Assert.Equal(HttpStatusCode.OK, updateCallRecordingResponse.StatusCode); - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + // End the call + var updateCallBody = new UpdateCall(state: CallStateEnum.Completed); + callsApiInstance.UpdateCall(accountId, callId, updateCallBody); } /// - /// Test Unauthorized DeleteRecording + /// Test ListCallRecordings with an unauthorized client /// [Fact] - public void DeleteRecordingUnauthorizedRequest() + public void ListCallRecordingsUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - - // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DeleteRecording: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); - } + ApiException exception = Assert.Throws(() => unauthorizedInstance.ListCallRecordingsWithHttpInfo(accountId, testCallId)); + Assert.Equal(401, exception.ErrorCode); + } /// - /// Test forbidden DeleteRecording + /// Test ListCallRecordings with a forbidden client /// [Fact] - public void DeleteRecordingForbiddenRequest() + public void ListCallRecordingsForbiddenRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // fakeConfiguration.Username = "forbiddenUsername"; - // fakeConfiguration.Password = "forbiddenPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DeleteRecording: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); - } + ApiException exception = Assert.Throws(() => forbiddenInstance.ListCallRecordingsWithHttpInfo(accountId, testCallId)); + Assert.Equal(403, exception.ErrorCode); + } /// - /// Test DeleteRecordingMedia + /// Test ListCallRecordings with a nonexistent call id + /// The API returns an empty list rather than a 404 /// [Fact] - public void DeleteRecordingMediaTest() + public void listCallRecordingsNotFound() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - - // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.DeleteRecordingMediaWithHttpInfo(accountId, callId, recordingId); - - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + // exception = Assert.Throws(() => recordingApiInstance.ListCallRecordingsWithHttpInfo(accountId, "not-a-call-id")); + // Assert.Equal(404, exception.ErrorCode); + var callRecordings = recordingApiInstance.ListCallRecordings(accountId, "not-a-call-id"); + Assert.Empty(callRecordings); } /// - /// Test Unauthorized DeleteRecordingMedia + /// Test GetCallRecording with an unauthorized client /// [Fact] - public void DeleteRecordingMediaUnauthorizedRequest() + public void GetCallRecordingUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingMediaWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DeleteRecordingMedia: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.GetCallRecordingWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); } /// - /// Test forbidden DeleteRecordingMedia - /// + /// Test GetCallRecording with a forbidden client + /// [Fact] - public void DeleteRecordingMediaForbiddenRequest() - { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d8"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Delete("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DeleteRecordingMediaWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DeleteRecordingMedia: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); + public void GetCallRecordingForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.GetCallRecordingWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); } /// - /// Test DownloadCallRecording + /// Test GetCallRecording with a nonexistent call id /// [Fact] - public void DownloadCallRecordingTest() - { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; - // string relativePath = "../../../Fixtures/csharp_test_recording.wav"; - // string filePath = Path.Combine(baseDirectory, relativePath); - // System.IO.Stream body = new System.IO.FileStream(filePath, FileMode.Open); - - // var apiResponse = new ApiResponse(HttpStatusCode.OK, body); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.DownloadCallRecordingWithHttpInfo(accountId, callId, recordingId); - - // Assert.IsAssignableFrom>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); - // body.Close(); + public void GetCallRecordingNotFound() + { + ApiException exception = Assert.Throws(() => recordingApiInstance.GetCallRecordingWithHttpInfo(accountId, testCallId, "not-a-recording-id")); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test Unauthorized DownloadCallRecording + /// Test DownloadCallRecording with an unauthorized client /// [Fact] public void DownloadCallRecordingUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b21-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b21-b22865662d85"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DownloadCallRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DownloadCallRecording: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.DownloadCallRecordingWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); } - /// - /// Test forbidden DownloadCallRecording + /// Test DownloadCallRecording with a forbidden client /// [Fact] public void DownloadCallRecordingForbiddenRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a-b215-b22865662d85"; - // fakeConfiguration.Username = "forbiddenUsername"; - // fakeConfiguration.Password = "forbiddenPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/media", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.DownloadCallRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling DownloadCallRecording: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => forbiddenInstance.DownloadCallRecordingWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); } /// - /// Test GetCallRecording + /// Test DownloadCallRecording with a nonexistent recording id /// [Fact] - public void GetCallRecordingTest() - { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // CallRecordingMetadata callRecordingMetadata = new CallRecordingMetadata( - // applicationId: "04e88489-df02-4e34-a0ee-27a91849555f", - // accountId: "920012", - // callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", - // parentCallId: "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", - // recordingId: "r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833", - // to: "+15555555555", - // from: "+15555555555", - // transferCallerId: "+15555555555", - // transferTo: "+15555555555", - // duration: "PT13.67S", - // direction: CallDirectionEnum.Inbound, - // channels: 1, - // startTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), - // endTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), - // fileFormat: FileFormatEnum.Wav, - // status: "completed", - // mediaUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-fe23a767-a75a5b77-20c5-4cca-b581-cbbf0776eca9/recordings/r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833/media", - // transcription: new TranscriptionMetadata( - // id: "t-387bd648-18f3-4823-9d16-746bca0003c9", - // status: "completed", - // completedTime: "2022-06-13T18:46:29.715Z", - // url: "https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcription" - // ) - // ); - - // var apiResponse = new ApiResponse(HttpStatusCode.OK, callRecordingMetadata); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId); - - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); - } - - /// - /// Test GetCallRecording not Found - /// - [Fact] - public void GetCallRecordingNotFound() + public void DownloadCallRecordingNotFound() { - // string accountId = "9900000"; - // string callId = "not a call id"; - // string recordingId = "not a recording id"; - - // var apiResponse = new ApiResponse(HttpStatusCode.NotFound, null); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling GetCallRecording: ", Exception.Message); - // Assert.Equal(404, Exception.ErrorCode); - } + ApiException exception = Assert.Throws(() => recordingApiInstance.DownloadCallRecordingWithHttpInfo(accountId, testCallId, "not-a-recording-id")); + Assert.Equal(404, exception.ErrorCode); + } /// - /// Test Unauthorized GetCallRecording + /// Test TranscribeCallRecording with an unauthorized client /// [Fact] - public void GetCallRecordingUnauthorizedRequestTest() + public void TranscribeCallRecordingUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling GetCallRecording: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.TranscribeCallRecordingWithHttpInfo(accountId, testCallId, testRecordingId, testTranscribeRecording)); + Assert.Equal(401, exception.ErrorCode); } /// - /// Test forbidden GetCallRecording + /// Test TranscribeCallRecording with a forbidden client /// [Fact] - public void GetCallRecordingForbiddenRequest() + public void TranscribeCallRecordingForbiddenRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // fakeConfiguration.Username = "forbiddenUsername"; - // fakeConfiguration.Password = "forbiddenPassword"; + ApiException exception = Assert.Throws(() => forbiddenInstance.TranscribeCallRecordingWithHttpInfo(accountId, testCallId, testRecordingId, testTranscribeRecording)); + Assert.Equal(403, exception.ErrorCode); + } - // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.GetCallRecordingWithHttpInfo(accountId, callId, recordingId)); - - // Assert.Equal("Error calling GetCallRecording: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); + /// + /// Test TranscribeCallRecording with a nonexistent recording id + /// The API returns a 500 error rather than a 404 + /// + [Fact(Skip = "This test returns a 500 error rather than a 404")] + public void TranscribeCallRecordingNotFound() + { + ApiException exception = Assert.Throws(() => recordingApiInstance.TranscribeCallRecordingWithHttpInfo(accountId, testCallId, "not-a-recording-id", testTranscribeRecording)); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test GetCallTranscription + /// Test GetCallTranscription with an unauthorized client /// [Fact] - public void GetCallTranscriptionTest() + public void GetCallTranscriptionUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // Transcription transcription = new Transcription(text: "Nice talking to you, friend!", confidence: .9); - // TranscriptionList transcriptionList = new TranscriptionList(transcripts: new List { transcription } ); - - // var apiResponse = new ApiResponse(HttpStatusCode.OK, transcriptionList); - // mockClient.Setup(x => x.Get("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.GetCallTranscriptionWithHttpInfo(accountId, callId, recordingId); - - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.GetCallTranscriptionWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); } /// - /// Test ListAccountCallRecordings + /// Test GetCallTranscription with a forbidden client /// [Fact] - public void ListAccountCallRecordingsTest() - { - // string accountId = "9900000"; - // CallRecordingMetadata callRecordingMetadata = new CallRecordingMetadata( - // applicationId: "04e88489-df02-4e34-a0ee-27a91849555f", - // accountId: "920012", - // callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", - // parentCallId: "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", - // recordingId: "r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833", - // to: "+15555555555", - // from: "+15555555555", - // transferCallerId: "+15555555555", - // transferTo: "+15555555555", - // duration: "PT13.67S", - // direction: CallDirectionEnum.Inbound, - // channels: 1, - // startTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), - // endTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), - // fileFormat: FileFormatEnum.Wav, - // status: "completed", - // mediaUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-fe23a767-a75a5b77-20c5-4cca-b581-cbbf0776eca9/recordings/r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833/media", - // transcription: new TranscriptionMetadata( - // id: "t-387bd648-18f3-4823-9d16-746bca0003c9", - // status: "completed", - // completedTime: "2022-06-13T18:46:29.715Z", - // url:"https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcription" - // ) - // ); - - // var apiResponse = new ApiResponse>(HttpStatusCode.OK, new List() { callRecordingMetadata }); - // mockClient.Setup(x => x.Get>("/accounts/{accountId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.ListAccountCallRecordingsWithHttpInfo( - // accountId: accountId, - // to: "+19195551234", - // from: "+19195554321", - // minStartTime: "2022-06-21T19:13:21Z", - // maxStartTime: "2022-06-21T19:13:21Z" - // ); - - // Assert.IsType>>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); - } - - /// - /// Test Unauthorized ListAccountCallRecordings + public void GetCallTranscriptionForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.GetCallTranscriptionWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); + } + + /// + /// Test GetCallTranscription with a nonexistent recording id /// [Fact] - public void ListAccountCallRecordingsUnauthorizedRequestTest() + public void GetCallTranscriptionNotFound() { - // string accountId = "9900000"; - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; - - // var apiResponse = new ApiResponse>(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Get>("/accounts/{accountId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.ListAccountCallRecordingsWithHttpInfo( - // accountId: accountId, - // to: "+19195551234", - // from: "+19195554321", - // minStartTime: "2022-06-21T19:13:21Z", - // maxStartTime: "2022-06-21T19:13:21Z" - // )); - - // Assert.Equal("Error calling ListAccountCallRecordings: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => recordingApiInstance.GetCallTranscriptionWithHttpInfo(accountId, testCallId, "not-a-recording-id")); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test forbidden ListAccountCallRecordings + /// Test DeleteCallTranscription with an unauthorized client /// [Fact] - public void ListAccountCallRecordingsForbiddenRequestTest() + public void DeleteCallTranscriptionUnauthorizedRequest() { - // string accountId = "9900000"; - - // var apiResponse = new ApiResponse>(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Get>("/accounts/{accountId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.ListAccountCallRecordingsWithHttpInfo( - // accountId: accountId, - // to: "+19195551234", - // from: "+19195554321", - // minStartTime: "2022-06-21T19:13:21Z", - // maxStartTime: "2022-06-21T19:13:21Z" - // )); - - // Assert.Equal("Error calling ListAccountCallRecordings: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); + ApiException exception = Assert.Throws(() => unauthorizedInstance.DeleteCallTranscriptionWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); } - /// - /// Test ListCallRecordings + /// Test DeleteCallTranscription with a forbidden client /// [Fact] - public void ListCallRecordingsTest() - { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // CallRecordingMetadata callRecordingMetadata = new CallRecordingMetadata( - // applicationId: "04e88489-df02-4e34-a0ee-27a91849555f", - // accountId: "920012", - // callId: "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85", - // parentCallId: "c-95ac8d6e-1a31c52e-b38f-4198-93c1-51633ec68f8d", - // recordingId: "r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833", - // to: "+15555555555", - // from: "+15555555555", - // transferCallerId: "+15555555555", - // transferTo: "+15555555555", - // duration: "PT13.67S", - // direction: CallDirectionEnum.Inbound, - // channels: 1, - // startTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), - // endTime: new DateTime(2022, 06, 21, 19, 13, 21, DateTimeKind.Utc), - // fileFormat: FileFormatEnum.Wav, - // status: "completed", - // mediaUrl: "https://voice.bandwidth.com/api/v2/accounts/9900000/conferences/conf-fe23a767-a75a5b77-20c5-4cca-b581-cbbf0776eca9/recordings/r-fbe05094-9fd2afe9-bf5b-4c68-820a-41a01c1c5833/media", - // transcription: new TranscriptionMetadata( - // id: "t-387bd648-18f3-4823-9d16-746bca0003c9", - // status: "completed", - // completedTime: "2022-06-13T18:46:29.715Z", - // url: "https://voice.bandwidth.com/api/v2/accounts/9900000/calls/c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/recordings/r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85/transcription" - // ) - // ); - - // var apiResponse = new ApiResponse>(HttpStatusCode.OK, new List() { callRecordingMetadata }); - // mockClient.Setup(x => x.Get>("/accounts/{accountId}/calls/{callId}/recordings", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.ListCallRecordingsWithHttpInfo(accountId, callId); - - // Assert.IsType>>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); - - } - - /// - /// Test TranscribeCallRecording + public void DeleteCallTranscriptionForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.DeleteCallTranscriptionWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); + } + + /// + /// Test DeleteCallTranscription with a nonexistent recording id /// [Fact] - public void TranscribeCallRecordingTest() + public void DeleteCallTranscriptionNotFound() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // TranscribeRecording transcribeRecording = new TranscribeRecording( - // callbackUrl: "https://myServer.example/bandwidth/webhooks/transcriptionAvailable", - // callbackMethod: CallbackMethodEnum.POST, - // username: "mySecretUsername", - // password: "mySecretPassword", - // tag: "exampleTag", - // callbackTimeout: 15, - // detectLanguage: true - // ); - - // var apiResponse = new ApiResponse(HttpStatusCode.NoContent, null); - // mockClient.Setup(x => x.Post("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.TranscribeCallRecordingWithHttpInfo(accountId, callId, recordingId, transcribeRecording); - - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.NoContent, response.StatusCode); + ApiException exception = Assert.Throws(() => recordingApiInstance.DeleteCallTranscriptionWithHttpInfo(accountId, testCallId, "not-a-recording-id")); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test Unauthorized TranscribeCallRecording + /// Test DeleteRecordingMedia with an unauthorized client /// [Fact] - public void TranscribeCallRecordingUnauthorizedRequest() + public void DeleteRecordingMediaUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // TranscribeRecording transcribeRecording = new TranscribeRecording( - // callbackUrl: "https://myServer.example/bandwidth/webhooks/transcriptionAvailable", - // callbackMethod: CallbackMethodEnum.POST, - // username: "mySecretUsername", - // password: "mySecretPassword", - // tag: "exampleTag", - // callbackTimeout: 15, - // detectLanguage: true - // ); - // fakeConfiguration.Username = "badUsername"; - // fakeConfiguration.Password = "badPassword"; + ApiException exception = Assert.Throws(() => unauthorizedInstance.DeleteRecordingMediaWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); + } - // var apiResponse = new ApiResponse(HttpStatusCode.Unauthorized, null); - // mockClient.Setup(x => x.Post("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.TranscribeCallRecordingWithHttpInfo(accountId, callId, recordingId, transcribeRecording)); + /// + /// Test DeleteRecordingMedia with a forbidden client + /// + [Fact] + public void DeleteRecordingMediaForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.DeleteRecordingMediaWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); + } - // Assert.Equal("Error calling TranscribeCallRecording: ", Exception.Message); - // Assert.Equal(401, Exception.ErrorCode); + /// + /// Test DeleteRecordingMedia with a nonexistent recording id + /// + [Fact] + public void DeleteRecordingMediaNotFound() + { + ApiException exception = Assert.Throws(() => recordingApiInstance.DeleteRecordingMediaWithHttpInfo(accountId, testCallId, "not-a-recording-id")); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test forbidden TranscribeCallRecording + /// Test DeleteRecording with an unauthorized client /// [Fact] - public void TranscribeCallRecordingForbiddenRequest() + public void DeleteRecordingUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // string recordingId = "r-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // TranscribeRecording transcribeRecording = new TranscribeRecording( - // callbackUrl: "https://myServer.example/bandwidth/webhooks/transcriptionAvailable", - // callbackMethod: CallbackMethodEnum.POST, - // username: "mySecretUsername", - // password: "mySecretPassword", - // tag: "exampleTag", - // callbackTimeout: 15, - // detectLanguage: true - // ); - // fakeConfiguration.Username = "forbiddenUsername"; - // fakeConfiguration.Password = "forbiddenPassword"; + ApiException exception = Assert.Throws(() => unauthorizedInstance.DeleteRecordingWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(401, exception.ErrorCode); + } - // var apiResponse = new ApiResponse(HttpStatusCode.Forbidden, null); - // mockClient.Setup(x => x.Post("/accounts/{accountId}/calls/{callId}/recordings/{recordingId}/transcription", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // ApiException Exception = Assert.Throws(() => instance.TranscribeCallRecordingWithHttpInfo(accountId, callId, recordingId, transcribeRecording)); + /// + /// Test DeleteRecording with a forbidden client + /// + [Fact] + public void DeleteRecordingForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.DeleteRecordingWithHttpInfo(accountId, testCallId, testRecordingId)); + Assert.Equal(403, exception.ErrorCode); + } - // Assert.Equal("Error calling TranscribeCallRecording: ", Exception.Message); - // Assert.Equal(403, Exception.ErrorCode); + /// + /// Test DeleteRecording with a nonexistent recording id + /// + [Fact] + public void DeleteRecordingNotFound() + { + ApiException exception = Assert.Throws(() => recordingApiInstance.DeleteRecordingWithHttpInfo(accountId, testCallId, "not-a-recording-id")); + Assert.Equal(404, exception.ErrorCode); } /// - /// Test UpdateCallRecordingState + /// Test UpdateCallRecordingState with an unauthorized client /// [Fact] - public void UpdateCallRecordingStateTest() + public void UpdateCallRecordingStateUnauthorizedRequest() { - // string accountId = "9900000"; - // string callId = "c-15ac29a2-1331029c-2cb0-4a07-b215-b22865662d85"; - // UpdateCallRecording updateCallRecording = new UpdateCallRecording(RecordingStateEnum.Paused); + var updateCallRecording = new UpdateCallRecording(state: RecordingStateEnum.Paused); + ApiException exception = Assert.Throws(() => unauthorizedInstance.UpdateCallRecordingStateWithHttpInfo(accountId, testCallId, updateCallRecording)); + Assert.Equal(401, exception.ErrorCode); + } - // var apiResponse = new ApiResponse(HttpStatusCode.OK, null); - // mockClient.Setup(x => x.Put("/accounts/{accountId}/calls/{callId}/recording", It.IsAny(), fakeConfiguration)).Returns(apiResponse); - // var response = instance.UpdateCallRecordingStateWithHttpInfo(accountId, callId, updateCallRecording); + /// + /// Test UpdateCallRecordingState with a forbidden client + /// + [Fact] + public void UpdateCallRecordingStateForbiddenRequest() + { + var updateCallRecording = new UpdateCallRecording(state: RecordingStateEnum.Paused); + ApiException exception = Assert.Throws(() => forbiddenInstance.UpdateCallRecordingStateWithHttpInfo(accountId, testCallId, updateCallRecording)); + Assert.Equal(403, exception.ErrorCode); + } - // Assert.IsType>(response); - // Assert.Equal(HttpStatusCode.OK, response.StatusCode); + /// + /// Test UpdateCallRecordingState with a nonexistent call id + /// + [Fact] + public void UpdateCallRecordingStateNotFound() + { + var updateCallRecording = new UpdateCallRecording(state: RecordingStateEnum.Paused); + ApiException exception = Assert.Throws(() => recordingApiInstance.UpdateCallRecordingStateWithHttpInfo(accountId, "not-a-call-id", updateCallRecording)); + Assert.Equal(404, exception.ErrorCode); } } } diff --git a/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs index 15cb0752..1aeba693 100644 --- a/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/StatisticsIntegrationTests.cs @@ -23,19 +23,32 @@ namespace Bandwidth.Standard.Test.Integration /// public class StatisticsIntegrationTests : IDisposable { - private StatisticsApi instance; - private Configuration fakeConfiguration; private string accountId; + private Configuration fakeConfiguration; + private StatisticsApi forbiddenInstance; + private StatisticsApi instance; + private StatisticsApi unauthorizedInstance; public StatisticsIntegrationTests() { + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME"); fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD"); instance = new StatisticsApi(fakeConfiguration); - accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + // Unauthorized API Client + fakeConfiguration.Username = "badUsername"; + fakeConfiguration.Password = "badPassword"; + unauthorizedInstance = new StatisticsApi(fakeConfiguration); + + // Forbidden API Client + fakeConfiguration.Username = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); + fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); + forbiddenInstance = new StatisticsApi(fakeConfiguration); } public void Dispose() @@ -53,15 +66,34 @@ public void InstanceTest() } /// - /// Test GetStatistics + /// Test successful GetStatistics /// [Fact] public void GetStatisticsTest() { var response = instance.GetStatisticsWithHttpInfo(accountId); - Assert.IsType>(response); Assert.Equal(HttpStatusCode.OK, response.StatusCode); } + + /// + /// Tests GetStatistics with an unauthorized client + /// + [Fact] + public void GetStatisticsUnauthorizedRequest() + { + ApiException exception = Assert.Throws(() => unauthorizedInstance.GetStatisticsWithHttpInfo(accountId)); + Assert.Equal(401, exception.ErrorCode); + } + + /// + /// Tests GetStatistics with a forbidden client + /// + [Fact] + public void GetStatisticsForbiddenRequest() + { + ApiException exception = Assert.Throws(() => forbiddenInstance.GetStatisticsWithHttpInfo(accountId)); + Assert.Equal(403, exception.ErrorCode); + } } } From 18df254d1b463277a7a387c600f7a0c33997c848 Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Fri, 6 Oct 2023 17:08:57 -0400 Subject: [PATCH 3/8] SWI-1632: Added environment variables to workflows --- .github/workflows/deploy.yml | 6 ++++++ .github/workflows/test.yml | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index d3b8d1a4..66ab3a83 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -28,6 +28,12 @@ jobs: BW_NUMBER: ${{ secrets.BW_NUMBER }} USER_NUMBER: ${{ secrets.USER_NUMBER }} BASE_CALLBACK_URL: ${{ secrets.BASE_CALLBACK_URL }} + MANTECA_ACTIVE_NUMBER: ${{ secrets.MANTECA_ACTIVE_NUMBER }} + MANTECA_APPLICATION_ID: ${{ secrets.MANTECA_APPLICATION_ID }} + MANTECA_BASE_URL: ${{ secrets.MANTECA_BASE_URL }} + MANTECA_IDLE_NUMBER: ${{ secrets.MANTECA_IDLE_NUMBER }} + OPERATING_SYSTEM: ${{ matrix.os }} + CSHARP_VERSION: ${{ matrix.dotnet }} run: dotnet test $BW_PROJECT_TEST_NAME - name: Pack NuGet package run: dotnet pack --configuration Release $BW_PROJECT_NAME -p:PackageVersion=$RELEASE_VERSION diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2093af49..ac0fcc51 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,6 +32,12 @@ jobs: BW_NUMBER: ${{ secrets.BW_NUMBER }} USER_NUMBER: ${{ secrets.USER_NUMBER }} BASE_CALLBACK_URL: ${{ secrets.BASE_CALLBACK_URL }} + MANTECA_ACTIVE_NUMBER: ${{ secrets.MANTECA_ACTIVE_NUMBER }} + MANTECA_APPLICATION_ID: ${{ secrets.MANTECA_APPLICATION_ID }} + MANTECA_BASE_URL: ${{ secrets.MANTECA_BASE_URL }} + MANTECA_IDLE_NUMBER: ${{ secrets.MANTECA_IDLE_NUMBER }} + OPERATING_SYSTEM: ${{ matrix.os }} + CSHARP_VERSION: ${{ matrix.dotnet }} # Required for multiple target frameworks in the StandardTests project. DOTNET: ${{ matrix.dotnet }} run: dotnet test src/Bandwidth.Standard.Test From 2908a5833d78164921c8f971f485b642b73e587e Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Mon, 9 Oct 2023 10:27:27 -0400 Subject: [PATCH 4/8] SWI-1632: Added forbidden user & pass to workflows --- .github/workflows/deploy.yml | 2 ++ .github/workflows/test.yml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 66ab3a83..2588f6a4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -23,6 +23,8 @@ jobs: BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }} BW_USERNAME: ${{ secrets.BW_USERNAME }} BW_PASSWORD: ${{ secrets.BW_PASSWORD }} + BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN}} + BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN}} BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }} BW_MESSAGING_APPLICATION_ID: ${{ secrets.BW_MESSAGING_APPLICATION_ID }} BW_NUMBER: ${{ secrets.BW_NUMBER }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ac0fcc51..07bc97df 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,8 @@ jobs: BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }} BW_USERNAME: ${{ secrets.BW_USERNAME }} BW_PASSWORD: ${{ secrets.BW_PASSWORD }} + BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN}} + BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN}} BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }} BW_MESSAGING_APPLICATION_ID: ${{ secrets.BW_MESSAGING_APPLICATION_ID }} BW_NUMBER: ${{ secrets.BW_NUMBER }} From 097f3a0ef651bae0f432c0533d105e054fa0849e Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Mon, 9 Oct 2023 14:00:36 -0400 Subject: [PATCH 5/8] SWI-1632: Added rate limit test --- .../Integration/MFAIntegrationTests.cs | 69 +++++++++++++++++-- 1 file changed, 62 insertions(+), 7 deletions(-) diff --git a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs index e1f79238..67c0a72d 100644 --- a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs @@ -5,6 +5,8 @@ using Bandwidth.Standard.Api; using Bandwidth.Standard.Model; using System.Net; +using System.Linq; +using System.Diagnostics; namespace Bandwidth.Standard.Test.Integration { @@ -25,6 +27,8 @@ public class MFAIntegrationTests : IDisposable public MFAIntegrationTests() { + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://mfa.bandwidth.com/api/v1"; @@ -70,14 +74,13 @@ public MFAIntegrationTests() digits: 6 ); - // Verify Code Request + // Verify Code Request to a random number verifyCodeRequest = new VerifyCodeRequest( - to: Environment.GetEnvironmentVariable("USER_NUMBER"), + to: "+1", + scope: "2FA", expirationTimeInMinutes: 3, code: "123456" ); - - accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); } public void Dispose() @@ -178,13 +181,22 @@ public void GenerateVoiceCodeForbiddenRequest() /// /// Test a successful VerifyCode request + /// Will always have to test against False codes unless we incorporate the Manteca project into MFA /// [Fact] public void VerifyCodeTest() { - var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); - Assert.IsType>(response); - Assert.Equal(HttpStatusCode.OK, response.StatusCode); + for(int i = 0; i < 10; i++) + { + verifyCodeRequest.To.Concat(new Random().Next(10).ToString()); + } + var responseWithHttpInfo = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); + Assert.Equal(HttpStatusCode.OK, responseWithHttpInfo.StatusCode); + + var response = instance.VerifyCode(accountId, verifyCodeRequest); + Assert.IsType(response); + Assert.IsType(response.Valid); + Assert.False(response.Valid); } /// @@ -206,5 +218,48 @@ public void VerifyCodeForbiddenRequest() ApiException Exception = Assert.Throws(() => forbiddenInstance.VerifyCode(accountId, verifyCodeRequest)); Assert.Equal(403, Exception.ErrorCode); } + + /// + /// Test VerifyCode rate limiting + /// + [Fact] + public void VerifyCodeRateLimiting() + { + for(int i = 0; i < 10; i++) + { + verifyCodeRequest.To.Concat(new Random().Next(10).ToString()); + } + var callCount = 1; + while (true) + { + try + { + Trace.WriteLine($"Testing rate limit, attempt #{callCount}"); + var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); + callCount++; + } + catch (ApiException e) + { + if (e.ErrorCode == 429) + { + Trace.WriteLine($"Rate limit reached"); + System.Threading.Thread.Sleep(35000); + var response = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); + Assert.Equal(HttpStatusCode.OK, response.StatusCode); + break; + } + else + { + throw e; + } + } + catch (Exception) + { + Trace.WriteLine($"Unexpected exception while testing rate limit"); + throw; + } + } + } + } } From 2e642cbc310f6cf76cdb7a0fbf4e3550fae373dd Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Mon, 9 Oct 2023 14:46:21 -0400 Subject: [PATCH 6/8] SWI-1632: Updating request to number --- .../Integration/MFAIntegrationTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs index 67c0a72d..d64a2e73 100644 --- a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs @@ -188,7 +188,7 @@ public void VerifyCodeTest() { for(int i = 0; i < 10; i++) { - verifyCodeRequest.To.Concat(new Random().Next(10).ToString()); + verifyCodeRequest.To = verifyCodeRequest.To + new Random().Next(10).ToString(); } var responseWithHttpInfo = instance.VerifyCodeWithHttpInfo(accountId, verifyCodeRequest); Assert.Equal(HttpStatusCode.OK, responseWithHttpInfo.StatusCode); @@ -227,7 +227,7 @@ public void VerifyCodeRateLimiting() { for(int i = 0; i < 10; i++) { - verifyCodeRequest.To.Concat(new Random().Next(10).ToString()); + verifyCodeRequest.To = verifyCodeRequest.To + new Random().Next(10).ToString(); } var callCount = 1; while (true) From 7d9479d55f31ab2ce67fdc24ced0c276fdc5209a Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Mon, 9 Oct 2023 16:19:40 -0400 Subject: [PATCH 7/8] SWI-1632: Trying to get media tests to work --- .../Integration/MediaIntegrationTests.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs index 5ee64fec..d265d195 100644 --- a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs @@ -18,15 +18,17 @@ public class MediaIntegrationTests : IDisposable private string accountId; private Configuration fakeConfiguration; private MediaApi instance; - private System.IO.Stream testMediaBody; private string testMediaId; private string testContentType; + private string filePath; private MediaApi unauthorizedInstance; public MediaIntegrationTests() { accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + testContentType = "image/jpeg"; + testMediaId = $"test-media-id-{Guid.NewGuid()}"; // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; @@ -42,12 +44,9 @@ public MediaIntegrationTests() unauthorizedInstance = new MediaApi(fakeConfiguration); // Create a media file to use for testing - testMediaId = $"test-media-id-{Guid.NewGuid()}"; string baseDirectory = AppDomain.CurrentDomain.BaseDirectory; string relativePath = "../../../Fixtures/csharp_cat.jpeg"; - string filePath = Path.Combine(baseDirectory, relativePath); - testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); - testContentType = "image/jpeg"; + filePath = Path.Combine(baseDirectory, relativePath); } public void Dispose() @@ -70,6 +69,7 @@ public void InstanceTest() [Fact] public void UploadMediaTest() { + var testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); var responseWithHttpInfo = instance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType); Assert.IsType>(responseWithHttpInfo); Assert.Equal(HttpStatusCode.NoContent, responseWithHttpInfo.StatusCode); @@ -82,8 +82,10 @@ public void UploadMediaTest() [Fact] public void UploadMediaUnauthorized() { + var testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); ApiException exception = Assert.Throws(() => unauthorizedInstance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType)); Assert.Equal(401, exception.ErrorCode); + testMediaBody.Close(); } /// @@ -92,8 +94,10 @@ public void UploadMediaUnauthorized() [Fact] public void UploadMediaForbidden() { + var testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); ApiException exception = Assert.Throws(() => instance.UploadMediaWithHttpInfo("not-an-account-id", testMediaId, testMediaBody, testContentType)); Assert.Equal(403, exception.ErrorCode); + testMediaBody.Close(); } /// @@ -136,6 +140,7 @@ public void ListMediaForbidden() [Fact] public void GetMediaTest() { + var testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType); var responseWithHttpInfo = instance.GetMediaWithHttpInfo(accountId, testMediaId); @@ -182,6 +187,7 @@ public void GetMediaNotFound() [Fact] public void DeleteMediaTest() { + var testMediaBody = new System.IO.FileStream(filePath, FileMode.Open); var uploadResponse = instance.UploadMediaWithHttpInfo(accountId, testMediaId, testMediaBody, testContentType); var responseWithHttpInfo = instance.DeleteMediaWithHttpInfo(accountId, testMediaId); From 89d8d1c8f5f7ad2cdee6480aec8c40bdf97b80eb Mon Sep 17 00:00:00 2001 From: Julia Januchowski Date: Tue, 10 Oct 2023 11:29:49 -0400 Subject: [PATCH 8/8] SWI-1632: General reformatting --- .../Integration/CallsIntegrationTests.cs | 3 +-- .../Integration/ConferencesIntegrationTests.cs | 9 ++++----- .../Integration/MFAIntegrationTests.cs | 16 ++++++++++------ .../Integration/MediaIntegrationTests.cs | 1 + .../PhoneNumberLookupIntegrationTests.cs | 16 +++++++++------- .../Integration/RecordingsIntegrationTests.cs | 1 - 6 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs index 06916a00..d5850758 100644 --- a/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/CallsIntegrationTests.cs @@ -24,8 +24,7 @@ public class CallsIntegrationTests : IDisposable private int testSleep; private CallsApi unauthorizedInstance; public CallsIntegrationTests() - { - // Test Constants + { accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); testSleep = 5000; testCallId = "testCallId"; diff --git a/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs index 595eea51..88e08b4e 100644 --- a/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/ConferencesIntegrationTests.cs @@ -33,6 +33,10 @@ public class ConferencesIntegrationTests : IDisposable public ConferencesIntegrationTests() { accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + testConferenceId = "Conf-Id"; + testMemberId = "Member-Id"; + testRecordingId = "Recording-Id"; + testUpdateBxml = "This is test BXML."; // Authorized API Client fakeConfiguration = new Configuration(); @@ -52,7 +56,6 @@ public ConferencesIntegrationTests() fakeConfiguration.Password = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); forbiddenInstance = new ConferencesApi(fakeConfiguration); - restClient = new ApiClient(basePath: "https://voice.bandwidth.com/api/v2"); updateConferenceBody = new UpdateConference( @@ -75,10 +78,6 @@ public ConferencesIntegrationTests() ); updateConferenceMember = new UpdateConferenceMember(mute: false); - testConferenceId = "Conf-Id"; - testMemberId = "Member-Id"; - testRecordingId = "Recording-Id"; - testUpdateBxml = "This is test BXML."; } public void Dispose() diff --git a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs index d64a2e73..11291990 100644 --- a/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MFAIntegrationTests.cs @@ -17,17 +17,21 @@ public class MFAIntegrationTests : IDisposable { private string accountId; private CodeRequest badCodeRequest; + private string BW_NUMBER; private Configuration fakeConfiguration; private MFAApi forbiddenInstance; private MFAApi instance; private CodeRequest messagingCodeRequest; private MFAApi unauthorizedInstance; + private string USER_NUMBER; private VerifyCodeRequest verifyCodeRequest; private CodeRequest voiceCodeRequest; public MFAIntegrationTests() { accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); + BW_NUMBER = Environment.GetEnvironmentVariable("BW_NUMBER"); + USER_NUMBER = Environment.GetEnvironmentVariable("USER_NUMBER"); // Authorized API Client fakeConfiguration = new Configuration(); @@ -46,8 +50,8 @@ public MFAIntegrationTests() // Code Request for generating a messaging code messagingCodeRequest = new CodeRequest( - to: Environment.GetEnvironmentVariable("USER_NUMBER"), - from: Environment.GetEnvironmentVariable("BW_NUMBER"), + to: USER_NUMBER, + from: BW_NUMBER, applicationId: Environment.GetEnvironmentVariable("BW_MESSAGING_APPLICATION_ID"), message: "Your temporary {NAME} {SCOPE} code is {CODE}", scope: "2FA", @@ -56,8 +60,8 @@ public MFAIntegrationTests() // Code Request for generating a voice code voiceCodeRequest = new CodeRequest( - to: Environment.GetEnvironmentVariable("USER_NUMBER"), - from: Environment.GetEnvironmentVariable("BW_NUMBER"), + to: USER_NUMBER, + from: BW_NUMBER, applicationId: Environment.GetEnvironmentVariable("BW_VOICE_APPLICATION_ID"), message: "Your temporary {NAME} {SCOPE} code is {CODE}", scope: "2FA", @@ -66,8 +70,8 @@ public MFAIntegrationTests() // Bad Code Request badCodeRequest = new CodeRequest( - to: Environment.GetEnvironmentVariable("USER_NUMBER"), - from: Environment.GetEnvironmentVariable("BW_NUMBER"), + to: USER_NUMBER, + from: BW_NUMBER, applicationId: "not an application id", message: "Your temporary {NAME} {SCOPE} code is {CODE}", scope: "2FA", diff --git a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs index d265d195..e23752ed 100644 --- a/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/MediaIntegrationTests.cs @@ -29,6 +29,7 @@ public MediaIntegrationTests() accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); testContentType = "image/jpeg"; testMediaId = $"test-media-id-{Guid.NewGuid()}"; + // Authorized API Client fakeConfiguration = new Configuration(); fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; diff --git a/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs index 6ba2d971..864bdab0 100644 --- a/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/PhoneNumberLookupIntegrationTests.cs @@ -15,6 +15,7 @@ namespace Bandwidth.Standard.Test.Integration public class PhoneNumberLookupIntegrationTests : IDisposable { private string accountId; + private string BW_NUMBER; private Configuration fakeConfiguration; private PhoneNumberLookupApi forbiddenInstance; private PhoneNumberLookupApi instance; @@ -25,6 +26,7 @@ public PhoneNumberLookupIntegrationTests() { accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); testRequestId = "test-request-id"; + BW_NUMBER = Environment.GetEnvironmentVariable("BW_NUMBER"); // Authorized API Client fakeConfiguration = new Configuration(); @@ -64,13 +66,13 @@ public void InstanceTest() [Fact] public void GetLookupStatusTest() { - LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + LookupRequest lookupRequest = new LookupRequest(new List { BW_NUMBER }); var response = instance.CreateLookupWithHttpInfo(accountId, lookupRequest); var lookupStatus = instance.GetLookupStatus(accountId, response.Data.RequestId); Assert.IsType(lookupStatus); Assert.Equal(response.Data.RequestId, lookupStatus.RequestId); - Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), lookupStatus.Result[0].E164Format); + Assert.Equal(BW_NUMBER, lookupStatus.Result[0].E164Format); } /// @@ -101,7 +103,7 @@ public void GetLookupStatusForbiddenRequest() [Fact] public void CreateLookupTest() { - LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + LookupRequest lookupRequest = new LookupRequest(new List { BW_NUMBER }); var response = instance.CreateLookupWithHttpInfo(accountId, lookupRequest); Assert.IsType>(response); Assert.Equal(LookupStatusEnum.INPROGRESS, response.Data.Status); @@ -112,7 +114,7 @@ public void CreateLookupTest() var lookupStatus = instance.GetLookupStatus(accountId, response.Data.RequestId); Assert.IsType(lookupStatus); Assert.Equal(response.Data.RequestId, lookupStatus.RequestId); - Assert.Equal(Environment.GetEnvironmentVariable("BW_NUMBER"), lookupStatus.Result[0].E164Format); + Assert.Equal(BW_NUMBER, lookupStatus.Result[0].E164Format); } @@ -136,7 +138,7 @@ public void CreateLookupBadRequest() [Fact] public void CreateLookupDuplicateRequest() { - LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER"), Environment.GetEnvironmentVariable("BW_NUMBER") }); + LookupRequest lookupRequest = new LookupRequest(new List { BW_NUMBER, BW_NUMBER }); ApiException Exception = Assert.Throws(() => instance.CreateLookup(accountId, lookupRequest)); Assert.Equal(400, Exception.ErrorCode); Assert.IsType(Exception.Message); @@ -148,7 +150,7 @@ public void CreateLookupDuplicateRequest() [Fact] public void CreateLookupUnauthorizedRequest() { - LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + LookupRequest lookupRequest = new LookupRequest(new List { BW_NUMBER }); ApiException Exception = Assert.Throws(() => unauthorizedInstance.CreateLookup(accountId, lookupRequest)); Assert.Equal(401, Exception.ErrorCode); } @@ -159,7 +161,7 @@ public void CreateLookupUnauthorizedRequest() [Fact] public void CreateLookupForbiddenRequest() { - LookupRequest lookupRequest = new LookupRequest(new List { Environment.GetEnvironmentVariable("BW_NUMBER") }); + LookupRequest lookupRequest = new LookupRequest(new List { BW_NUMBER }); ApiException Exception = Assert.Throws(() => forbiddenInstance.CreateLookup(accountId, lookupRequest)); //This API throws a 401 when a user provides valid credentials with the `TN Lookup` role disabled // Assert.Equal(403, Exception.ErrorCode); diff --git a/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs b/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs index bfd3a232..c3bde7f3 100644 --- a/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs +++ b/src/Bandwidth.Standard.Test/Integration/RecordingsIntegrationTests.cs @@ -38,7 +38,6 @@ public class RecordingsIntegrationTests : IDisposable public RecordingsIntegrationTests() { - //Constants accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); testCallId = "callId"; testRecordingId = "recordingId";