|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using Xunit; |
| 4 | + |
| 5 | +using Bandwidth.Standard.Client; |
| 6 | +using Bandwidth.Standard.Api; |
| 7 | +using Bandwidth.Standard.Model; |
| 8 | +using System.Net; |
| 9 | +using System.Text.Json; |
| 10 | +using Newtonsoft.Json.Linq; |
| 11 | + |
| 12 | +namespace Bandwidth.Standard.Test.Integration |
| 13 | +{ |
| 14 | + /// <summary> |
| 15 | + /// Class for testing TranscriptionsApi |
| 16 | + /// </summary> |
| 17 | + public class TranscriptionsIntegrationTests : IDisposable |
| 18 | + { |
| 19 | + private TranscriptionsApi transcriptionsApiInstance; |
| 20 | + private CallsApi callsApiInstance; |
| 21 | + |
| 22 | + private TranscriptionsApi unauthorizedInstance; |
| 23 | + private TranscriptionsApi forbiddenInstance; |
| 24 | + private Configuration fakeConfiguration; |
| 25 | + private ApiClient restClient; |
| 26 | + private CreateCall mantecaCallBody; |
| 27 | + private string accountId; |
| 28 | + private string testCallId; |
| 29 | + private string testRecordingId; |
| 30 | + private string BW_USERNAME; |
| 31 | + private string BW_PASSWORD; |
| 32 | + private string MANTECA_ACTIVE_NUMBER; |
| 33 | + private string MANTECA_IDLE_NUMBER; |
| 34 | + private string MANTECA_APPLICATION_ID; |
| 35 | + private string MANTECA_BASE_URL; |
| 36 | + private string BW_FORBIDDEN_USERNAME; |
| 37 | + private string BW_FORBIDDEN_PASSWORD; |
| 38 | + |
| 39 | + public TranscriptionsIntegrationTests() |
| 40 | + { |
| 41 | + accountId = Environment.GetEnvironmentVariable("BW_ACCOUNT_ID"); |
| 42 | + testCallId = "callId"; |
| 43 | + testRecordingId = "recordingId"; |
| 44 | + BW_USERNAME = Environment.GetEnvironmentVariable("BW_USERNAME"); |
| 45 | + BW_PASSWORD = Environment.GetEnvironmentVariable("BW_PASSWORD"); |
| 46 | + MANTECA_ACTIVE_NUMBER = Environment.GetEnvironmentVariable("MANTECA_ACTIVE_NUMBER"); |
| 47 | + MANTECA_IDLE_NUMBER = Environment.GetEnvironmentVariable("MANTECA_IDLE_NUMBER"); |
| 48 | + MANTECA_APPLICATION_ID = Environment.GetEnvironmentVariable("MANTECA_APPLICATION_ID"); |
| 49 | + MANTECA_BASE_URL = Environment.GetEnvironmentVariable("MANTECA_BASE_URL"); |
| 50 | + BW_FORBIDDEN_USERNAME = Environment.GetEnvironmentVariable("BW_USERNAME_FORBIDDEN"); |
| 51 | + BW_FORBIDDEN_PASSWORD = Environment.GetEnvironmentVariable("BW_PASSWORD_FORBIDDEN"); |
| 52 | + |
| 53 | + //API Client |
| 54 | + fakeConfiguration = new Configuration(); |
| 55 | + fakeConfiguration.BasePath = "https://voice.bandwidth.com/api/v2"; |
| 56 | + fakeConfiguration.Username = BW_USERNAME; |
| 57 | + fakeConfiguration.Password = BW_PASSWORD; |
| 58 | + transcriptionsApiInstance = new TranscriptionsApi(fakeConfiguration); |
| 59 | + callsApiInstance = new CallsApi(fakeConfiguration); |
| 60 | + |
| 61 | + // Unauthorized API Client |
| 62 | + fakeConfiguration.Username = "badUsername"; |
| 63 | + fakeConfiguration.Password = "badPassword"; |
| 64 | + unauthorizedInstance = new TranscriptionsApi(fakeConfiguration); |
| 65 | + |
| 66 | + // Forbidden API Client |
| 67 | + fakeConfiguration.Username = BW_FORBIDDEN_USERNAME; |
| 68 | + fakeConfiguration.Password = BW_FORBIDDEN_PASSWORD; |
| 69 | + forbiddenInstance = new TranscriptionsApi(fakeConfiguration); |
| 70 | + |
| 71 | + restClient = new ApiClient(basePath: "https://voice.bandwidth.com/api/v2"); |
| 72 | + |
| 73 | + mantecaCallBody = new CreateCall( |
| 74 | + to: MANTECA_IDLE_NUMBER, |
| 75 | + from: MANTECA_ACTIVE_NUMBER, |
| 76 | + applicationId: MANTECA_APPLICATION_ID, |
| 77 | + answerUrl: MANTECA_BASE_URL + "/bxml/idle" |
| 78 | + ); |
| 79 | + |
| 80 | + InitializeManteca(); |
| 81 | + } |
| 82 | + |
| 83 | + public void Dispose() |
| 84 | + { |
| 85 | + // Cleanup when everything is done. |
| 86 | + } |
| 87 | + |
| 88 | + private void InitializeManteca() |
| 89 | + { |
| 90 | + // set up request options for creating a call |
| 91 | + var jsonBody = JsonSerializer.Serialize(new |
| 92 | + { |
| 93 | + os = Environment.GetEnvironmentVariable("OPERATING_SYSTEM"), |
| 94 | + language = "csharp" + Environment.GetEnvironmentVariable("DOTNET_VERSION"), |
| 95 | + type = "REAL_TIME_TRANSCRIPTION" |
| 96 | + }); |
| 97 | + var options = new RequestOptions |
| 98 | + { |
| 99 | + Data = jsonBody, |
| 100 | + HeaderParameters = new Multimap<string, string> |
| 101 | + { |
| 102 | + { "Content-Type", "application/json" } |
| 103 | + } |
| 104 | + }; |
| 105 | + |
| 106 | + // initialize call with Manteca |
| 107 | + var response = restClient.Post<object>( |
| 108 | + path: Environment.GetEnvironmentVariable("MANTECA_BASE_URL") + "/tests", |
| 109 | + options: options |
| 110 | + ); |
| 111 | + var testId = response.RawContent; |
| 112 | + mantecaCallBody.Tag = testId; |
| 113 | + } |
| 114 | + |
| 115 | + /// <summary> |
| 116 | + /// Test an instance of TranscriptionsAPi |
| 117 | + /// </summary> |
| 118 | + [Fact] |
| 119 | + public void InstanceTest() |
| 120 | + { |
| 121 | + Assert.IsType<TranscriptionsApi>(transcriptionsApiInstance); |
| 122 | + } |
| 123 | + |
| 124 | + [Fact] |
| 125 | + public void CreateCallTranscription() |
| 126 | + { |
| 127 | + string startTranscriptionBxml = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StartTranscription name=\"{mantecaCallBody.Tag}\" tracks=\"inbound\"></StartTranscription><Pause duration=\"6\"/></Response>"; |
| 128 | + string stopTranscriptionBxml = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><Response><StopTranscription name=\"{mantecaCallBody.Tag}\"></StopTranscription></Response>"; |
| 129 | + UpdateCall updateCallBody = new UpdateCall(); |
| 130 | + |
| 131 | + // Create the call |
| 132 | + CreateCallResponse createCallResponse = callsApiInstance.CreateCall(accountId, mantecaCallBody); |
| 133 | + testCallId = createCallResponse.CallId; |
| 134 | + |
| 135 | + // Sleep for 3 seconds |
| 136 | + System.Threading.Thread.Sleep(3000); |
| 137 | + |
| 138 | + // Start the Transcription |
| 139 | + callsApiInstance.UpdateCallBxml(accountId, testCallId, startTranscriptionBxml); |
| 140 | + |
| 141 | + // Sleep for 3 seconds |
| 142 | + System.Threading.Thread.Sleep(3000); |
| 143 | + |
| 144 | + // Stop the Transcription |
| 145 | + callsApiInstance.UpdateCallBxml(accountId, testCallId, stopTranscriptionBxml); |
| 146 | + |
| 147 | + // End the call |
| 148 | + callsApiInstance.UpdateCall(accountId, testCallId, updateCallBody); |
| 149 | + |
| 150 | + } |
| 151 | + |
| 152 | + [Fact] |
| 153 | + public void ListRealTimeTranscriptions() |
| 154 | + { |
| 155 | + Assert.True(false); |
| 156 | + } |
| 157 | + |
| 158 | + [Fact] |
| 159 | + public void GetRealTimeTranscription() |
| 160 | + { |
| 161 | + |
| 162 | + } |
| 163 | + |
| 164 | + [Fact] |
| 165 | + public void DeleteRealTimeTranscription() |
| 166 | + { |
| 167 | + |
| 168 | + } |
| 169 | + } |
| 170 | +} |
0 commit comments