コード例 #1
0
        public void TranscribeCallHttpTriggerRunSecretStoreException()
        {
            string expectedCallSid      = "CA10000000000000000000000000000001";
            string expectedRecordingUri = "https://fakestorage/recordings/A012345678.wav";

            HttpRequest request = CreateHttpPostRequest(expectedCallSid, expectedRecordingUri);

            ExecutionContext context = new ExecutionContext()
            {
                FunctionAppDirectory = Directory.GetCurrentDirectory(),
            };

            InitializeSecretsExceptions();

            IActionResult result = TranscribeCallHttpTrigger.Run(request, Log, context).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            OkObjectResult okResult = (OkObjectResult)result;

            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsInstanceOfType(okResult.Value, typeof(TranscribeCallResponse));

            TranscribeCallResponse response = (TranscribeCallResponse)okResult.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);

            Assert.AreEqual((int)CommonStatusCode.Error, response.StatusCode);
            Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Error), response.StatusDesc);

            Assert.IsTrue(response.HasError);
            Assert.AreEqual((int)CommonErrorCode.SecretStoreGenericFailure, response.ErrorCode);
            Assert.AreEqual(CommonErrorMessage.SecretStoreGenericFailureMessage, response.ErrorDetails);
        }
コード例 #2
0
        public void TranscribeCallHttpTriggerMissingRecordingUri()
        {
            string expectedCallSid = "CA10000000000000000000000000000001";

            HttpRequest request = CreateHttpPostRequest(expectedCallSid, null);

            ExecutionContext context = new ExecutionContext()
            {
                FunctionAppDirectory = Directory.GetCurrentDirectory(),
            };

            IActionResult result = TranscribeCallHttpTrigger.Run(request, Log, context).Result;

            Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult));

            BadRequestObjectResult badRequestResult = (BadRequestObjectResult)result;

            Assert.AreEqual(400, badRequestResult.StatusCode);
            Assert.IsInstanceOfType(badRequestResult.Value, typeof(TranscribeCallResponse));

            TranscribeCallResponse response = (TranscribeCallResponse)badRequestResult.Value;

            Assert.IsNull(response.CallSid);
            Assert.IsNull(response.Text);

            Assert.AreEqual((int)CommonStatusCode.Error, response.StatusCode);
            Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Error), response.StatusDesc);

            Assert.IsTrue(response.HasError);
            Assert.AreEqual((int)TranscribeCallErrorCode.RequestMissingRecordingUri, response.ErrorCode);
            Assert.AreEqual($"You must specify a value for the key '{TranscribeCallRequest.RecordingUriKeyName}' in the request body!", response.ErrorDetails);
        }
コード例 #3
0
        public void TranscribeCallRun()
        {
            HttpRequest request = CreateHttpPostRequest(_config.CallSid, _config.RecordingUri);

            ExecutionContext context = new ExecutionContext()
            {
                FunctionAppDirectory = Directory.GetCurrentDirectory(),
            };

            IActionResult result = TranscribeCallHttpTrigger.Run(request, _log, context).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            OkObjectResult okResult = (OkObjectResult)result;

            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsInstanceOfType(okResult.Value, typeof(TranscribeCallResponse));

            TranscribeCallResponse response = (TranscribeCallResponse)okResult.Value;

            Assert.AreEqual(_config.CallSid, response.CallSid);
            Assert.IsFalse(string.IsNullOrWhiteSpace(response.Text));

            Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode);
            Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc);

            Assert.IsFalse(response.HasError);
            Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);

            _log.LogInformation("Writing returned transcription to test configuration...");
            _config.Transcript = response.Text;
            _config.Save(GlobalTestConstants.TestConfigurationFilePath);
        }
コード例 #4
0
        /// <summary>
        /// Runner for ensuring TranscribeCallHttpTrigger runs correctly for concurrent executions against a remote Azure Function.
        /// </summary>
        /// <param name="httpClient">The HttpClient instance to use.</param>
        /// <param name="functionSettings">Configuration information required to make calls to the Azure Function.</param>
        /// <param name="queue">The queue of tests to run.</param>
        /// <returns>An asynchronous task.</returns>
        public async Task TranscribeCallRunnerAsync(HttpClient httpClient, FunctionSettings functionSettings, ConcurrentQueue <TestConfiguration> queue)
        {
            TestConfiguration nextTestConfiguration = null;

            while (!queue.IsEmpty)
            {
                if (queue.TryDequeue(out nextTestConfiguration))
                {
                    HttpContent requestContent = CreateHttpPostContent(nextTestConfiguration.CallSid, nextTestConfiguration.RecordingUri);

                    HttpResponseMessage httpResponse = await httpClient.PostAsync(functionSettings.TranscribeCallUrl, requestContent);

                    string responseContent = await httpResponse.Content.ReadAsStringAsync();

                    TranscribeCallResponse response = JsonConvert.DeserializeObject <TranscribeCallResponse>(responseContent);

                    Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid);
                    Assert.IsFalse(string.IsNullOrWhiteSpace(response.Text));

                    Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode);
                    Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc);

                    Assert.IsFalse(response.HasError);
                    Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode);
                    Assert.IsNull(response.ErrorDetails);

                    _log.LogInformation($"Transcription returned ({nextTestConfiguration.CallSid}):");
                    _log.LogInformation(response.Text);

                    nextTestConfiguration.Transcript = response.Text;
                }

                TH.Thread.Sleep(2000);
            }
        }
コード例 #5
0
        public void TranscribeCallHttpTriggerSuccess()
        {
            InitializeSecrets();

            string expectedCallSid              = "CA10000000000000000000000000000001";
            string expectedRecordingUri         = "https://fakestorage/recordings/A012345678.wav";
            string expectedStorageContainerName = _config[ExpectedStorageContainerNameAppSettingName];
            string expectedRegion     = _config[ExpectedApiRegionAppSettingName];
            string expectedTranscript = "your next Master hearing date January 19th 2018 at 3 p.m. for Gymboree";

            AzureKeyVaultSecretStoreMock secretStore = TranscribeCallHttpTrigger.Container.GetService <ISecretStore>() as AzureKeyVaultSecretStoreMock;

            string storageAccessConnectionString = _config[StorageAccessConnectionStringAppSettingName];

            Secret storageAccessKey = secretStore.GetSecretAsync(_config[StorageAccessKeySecretNameAppSettingName], _config[AuthorityAppSettingName]).Result;

            Secret fullStorageAccessConnectionString = Utils.GetFullStorageConnectionString(storageAccessConnectionString, storageAccessKey);

            AzureBlobStorageClientMock storageClient = TranscribeCallHttpTrigger.Container.GetService <IStorageClient>() as AzureBlobStorageClientMock;

            storageClient.RegisterExpectedRequestMessage(expectedRecordingUri, fullStorageAccessConnectionString.Value, _config[ExpectedStorageContainerNameAppSettingName], false);

            AzureTranscriberMock transcriber = TranscribeCallHttpTrigger.Container.GetService <ITranscriber>() as AzureTranscriberMock;

            transcriber.RegisterExpectedRequestMessage(expectedRecordingUri, ExpectedApiKey, expectedRegion);
            transcriber.RegisterExpectedResponseMessage(expectedRecordingUri, expectedTranscript);

            HttpRequest request = CreateHttpPostRequest(expectedCallSid, expectedRecordingUri);

            ExecutionContext context = new ExecutionContext()
            {
                FunctionAppDirectory = Directory.GetCurrentDirectory(),
            };

            IActionResult result = TranscribeCallHttpTrigger.Run(request, Log, context).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            OkObjectResult okResult = (OkObjectResult)result;

            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsInstanceOfType(okResult.Value, typeof(TranscribeCallResponse));

            TranscribeCallResponse response = (TranscribeCallResponse)okResult.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);
            Assert.AreEqual(expectedTranscript, response.Text);

            Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode);
            Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc);

            Assert.IsFalse(response.HasError);
            Assert.AreEqual(0, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);
        }
コード例 #6
0
        public void TranscribeCallHttpTriggerRunTranscriberException()
        {
            InitializeSecrets();

            string expectedCallSid      = "CA10000000000000000000000000000001";
            string expectedRecordingUri = "https://fakestorage/recordings/A012345678.wav";
            string expectedRegion       = _config[ExpectedApiRegionAppSettingName];

            InitializeStorageClientExceptions(new Dictionary <string, StorageClientException>()
            {
                { expectedRecordingUri, new StorageClientException("TestException", null) },
            });

            AzureTranscriberMock transcriber = TranscribeCallHttpTrigger.Container.GetService <ITranscriber>() as AzureTranscriberMock;

            transcriber.RegisterExpectedRequestMessage(expectedRecordingUri, ExpectedApiKey, expectedRegion);

            HttpRequest request = CreateHttpPostRequest(expectedCallSid, expectedRecordingUri);

            ExecutionContext context = new ExecutionContext()
            {
                FunctionAppDirectory = Directory.GetCurrentDirectory(),
            };

            IActionResult result = TranscribeCallHttpTrigger.Run(request, Log, context).Result;

            Assert.IsInstanceOfType(result, typeof(OkObjectResult));

            OkObjectResult okResult = (OkObjectResult)result;

            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsInstanceOfType(okResult.Value, typeof(TranscribeCallResponse));

            TranscribeCallResponse response = (TranscribeCallResponse)okResult.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);
            Assert.IsNull(response.Text);

            Assert.AreEqual((int)CommonStatusCode.Error, response.StatusCode);
            Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Error), response.StatusDesc);

            Assert.IsTrue(response.HasError);
            Assert.AreEqual((int)CommonErrorCode.StorageClientGenericFailure, response.ErrorCode);
            Assert.AreEqual(CommonErrorMessage.StorageClientGenericFailureMessage, response.ErrorDetails);
        }
コード例 #7
0
        /// <summary>
        /// Runner for ensuring TranscribeCallHttpTrigger.Run() implementation runs correctly for concurrent executions.
        /// </summary>
        /// <param name="queue">The queue of tests to runs.</param>
        public void TranscribeCallRunnerLocal(ConcurrentQueue <TestConfiguration> queue)
        {
            TestConfiguration nextTestConfiguration = null;

            while (!queue.IsEmpty)
            {
                if (queue.TryDequeue(out nextTestConfiguration))
                {
                    HttpRequest request = CreateHttpPostRequest(nextTestConfiguration.CallSid, nextTestConfiguration.RecordingUri);

                    ExecutionContext context = new ExecutionContext()
                    {
                        FunctionAppDirectory = Directory.GetCurrentDirectory(),
                    };

                    IActionResult result = TranscribeCallHttpTrigger.Run(request, _log, context).Result;

                    Assert.IsInstanceOfType(result, typeof(OkObjectResult));

                    OkObjectResult okResult = (OkObjectResult)result;

                    Assert.AreEqual(200, okResult.StatusCode);
                    Assert.IsInstanceOfType(okResult.Value, typeof(TranscribeCallResponse));

                    TranscribeCallResponse response = (TranscribeCallResponse)okResult.Value;

                    Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid);
                    Assert.IsFalse(string.IsNullOrWhiteSpace(response.Text));

                    Assert.AreEqual((int)CommonStatusCode.Ok, response.StatusCode);
                    Assert.AreEqual(Enum.GetName(typeof(CommonStatusCode), CommonStatusCode.Ok), response.StatusDesc);

                    Assert.IsFalse(response.HasError);
                    Assert.AreEqual((int)CommonErrorCode.NoError, response.ErrorCode);
                    Assert.IsNull(response.ErrorDetails);

                    _log.LogInformation($"Transcription returned ({nextTestConfiguration.CallSid}):");
                    _log.LogInformation(response.Text);

                    nextTestConfiguration.Transcript = response.Text;
                }

                TH.Thread.Sleep(2000);
            }
        }