예제 #1
0
        public void DeleteRecordingsVerify()
        {
            HttpRequest request = CreatePullHttpPostRequest(_config.InputId, _config.CallSid);

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)okResult.Value;

            Assert.AreEqual(_config.CallSid, response.CallSid);
            Assert.IsNull(response.RecordingUri);

            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.TwilioCallNoRecordings, response.ErrorCode);
            Assert.AreEqual("No recording", response.ErrorDetails);
        }
예제 #2
0
        public void PullRecordingHttpTriggerMissingCallSid()
        {
            InitializeWithNoTwilioMock();

            string expectedInputId = "A012345678"; // Example pulled from https://citizenpath.com/faq/find-alien-registration-number/

            HttpRequest request = CreateHttpPostRequest(expectedInputId, null);

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

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

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

            BadRequestObjectResult badRequestResult = (BadRequestObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)badRequestResult.Value;

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

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

            Assert.IsTrue(response.HasError);
            Assert.AreEqual((int)PullRecordingErrorCode.RequestMissingCallSid, response.ErrorCode);
            Assert.AreEqual($"You must specify a value for the key '{PullRecordingRequest.CallSidKeyName}' in the request body!", response.ErrorDetails);
        }
예제 #3
0
        public void PullRecordingHttpTriggerNoRecording()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

            string expectedInputId = "A012345678"; // Example pulled from https://citizenpath.com/faq/find-alien-registration-number/
            string expectedCallSid = "CA10000000000000000000000000000001";

            string expectedResponseContent = TemplateManager.Load(RecordingResponseTemplatePath, new Dictionary <string, string>()
            {
                { "pageSize", "0" },
            })
                                             .Replace($"{{{RecordingCompositesKey}}}", string.Empty);

            HttpResponseMessage expectedResponse = TestHelper.CreateHttpResponseMessage(HttpStatusCode.OK, expectedResponseContent);

            HttpClientMock httpClient = PullRecordingHttpTrigger.Container.GetService <IHttpClientWrapper>() as HttpClientMock;

            httpClient.MessageHandler.RegisterExpectedRecordingResponse(expectedCallSid, "recordings", expectedResponse);

            HttpRequest request = CreateHttpPostRequest(expectedInputId, expectedCallSid);

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)okResult.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);
            Assert.IsNull(response.RecordingUri);
            Assert.AreEqual(0, response.RecordingLength);
            Assert.IsNull(response.FullRecordingUrl);

            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.TwilioCallNoRecordings, response.ErrorCode);
            Assert.AreEqual("No recording", response.ErrorDetails);
        }
        /// <summary>
        /// Runner for ensuring PullRecordingHttpTrigger.Run() implementation runs correctly for concurrent executions.
        /// </summary>
        /// <param name="queue">The queue of tests to run.</param>
        public void PullRecordingRunnerLocal(ConcurrentQueue <TestConfiguration> queue)
        {
            TestConfiguration nextTestConfiguration = null;

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

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

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

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

                    OkObjectResult okResult = (OkObjectResult)result;

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

                    PullRecordingResponse response = (PullRecordingResponse)okResult.Value;

                    Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid);
                    Assert.IsNotNull(response.RecordingUri);

                    // Assert.IsTrue(response.RecordingLength > 600000); // Recording size should be ~800KB
                    Assert.IsNotNull(response.FullRecordingUrl);

                    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 recording uri to test configuration...");
                    nextTestConfiguration.RecordingUri = response.RecordingUri;
                }

                TH.Thread.Sleep(2000);
            }

            _concurrentConfig.Save(GlobalTestConstants.ConcurrentTestConfigurationFilePath);
        }
        public void PullRecordingHttpTriggerRun()
        {
            HttpRequest request = CreateHttpPostRequest(_config.InputId, _config.CallSid);

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

            string expectedStorageContainerName  = _functionConfig[StorageContainerNameAppSettingName];
            string expectedDestinationPathPrefix = $"{_config.InputId}/file_";
            string expectedBlobEndpoint          = GetBlobEndpoint(_functionConfig[StorageAccessConnectionStringAppSettingName]);
            string expectedFullPathPrefix        = $"{expectedBlobEndpoint}{expectedStorageContainerName}/{expectedDestinationPathPrefix}";

            ISecretStore secretStore = PullRecordingHttpTrigger.Container.GetService <ISecretStore>();

            Secret expectedStorageReadAccessKey = secretStore.GetSecretAsync(_functionConfig[StorageReadAccessKeySecretNameAppSettingName], _functionConfig[AuthorityAppSettingName]).Result;

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)okResult.Value;

            Assert.AreEqual(_config.CallSid, response.CallSid);
            Assert.IsNotNull(response.RecordingUri);
            Assert.IsTrue(response.RecordingUri.StartsWith(expectedDestinationPathPrefix));
            Assert.IsTrue(response.FullRecordingUrl.StartsWith(expectedFullPathPrefix));
            Assert.IsTrue(response.FullRecordingUrl.EndsWith($"?{expectedStorageReadAccessKey.Value}"));
            Assert.IsTrue(response.RecordingLength > 600000); // Recording size should be ~800KB
            Assert.IsNotNull(response.FullRecordingUrl);

            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 recording URI to test configuration...");
            _config.RecordingUri = response.RecordingUri;
            _config.Save(GlobalTestConstants.TestConfigurationFilePath);
        }
예제 #6
0
        public void PullRecordingHttpTriggerRunTwilioGenericException()
        {
            InitializeWithTwilioMock();
            InitializeSecrets();

            string expectedInputId = "A012345678"; // Example pulled from https://citizenpath.com/faq/find-alien-registration-number/
            string expectedCallSid = "CA10000000000000000000000000000001";

            InitializeTwilioExceptions(new Dictionary <string, Exception>()
            {
                { expectedCallSid, new TwilioEx.TwilioException("TestException") },
            });

            HttpRequest request = CreateHttpPostRequest(expectedInputId, expectedCallSid);

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)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.TwilioGenericFailure, response.ErrorCode);
            Assert.AreEqual(CommonErrorMessage.TwilioGenericFailureMessage, response.ErrorDetails);
        }
예제 #7
0
        public void PullRecordingHttpTriggerMissingInputId()
        {
            InitializeWithNoTwilioMock();

            string expectedCallSid = "CA10000000000000000000000000000001";

            HttpRequest request = CreateHttpPostRequest(null, expectedCallSid);

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

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

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

            BadRequestObjectResult badRequestResult = (BadRequestObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)badRequestResult.Value;

            Assert.IsNull(response.CallSid);
            Assert.IsNull(response.RecordingUri);
            Assert.AreEqual(0, response.RecordingLength);
            Assert.IsNull(response.FullRecordingUrl);

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

            Assert.IsTrue(response.HasError);
            Assert.AreEqual((int)PullRecordingErrorCode.RequestMissingInputId, response.ErrorCode);
            Assert.AreEqual($"You must specify a value for the key '{PullRecordingRequest.InputIdKeyName}' in the request body!", response.ErrorDetails);
        }
예제 #8
0
        public void PullRecordingHttpTriggerRunStorageClientException()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

            string expectedInputId = "A012345678"; // Example pulled from https://citizenpath.com/faq/find-alien-registration-number/
            string expectedCallSid = "CA10000000000000000000000000000001";
            string recordingSid    = "RE10000000000000000000000000000001";
            string recordingUri    = $"/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings/{recordingSid}.json";
            string expectedStorageContainerName = _config[ExpectedStorageContainerNameAppSettingName];

            string expectedResponseContent = TemplateManager.LoadWithComposites(
                RecordingResponseTemplatePath,
                RecordingCompositesKey,
                RecordingCompositeTemplatePath,
                new Dictionary <string, string>()
            {
                { "pageSize", "2" },
            },
                new List <Dictionary <string, string> >()
            {
                new Dictionary <string, string>()
                {
                    { "callSid", expectedCallSid },
                    { "recordingSid", recordingSid },
                    { "recordingUri", recordingUri },
                },
            });

            HttpClientMock httpClient = PullRecordingHttpTrigger.Container.GetService <IHttpClientWrapper>() as HttpClientMock;

            HttpResponseMessage expectedResponse = TestHelper.CreateHttpResponseMessage(HttpStatusCode.OK, expectedResponseContent);

            httpClient.MessageHandler.RegisterExpectedRecordingResponse(expectedCallSid, "recordings", expectedResponse);

            httpClient.RegisterExpectedRequestMessage($"{TwilioBaseUrl}{recordingUri.Replace(".json", string.Empty)}", null);

            string expectedDestinationPathPrefix = $"{expectedInputId}/file_"; // We will just check to make sure the remaining is a datetime

            AzureBlobStorageClientMock blobClient = PullRecordingHttpTrigger.Container.GetService <IStorageClient>() as AzureBlobStorageClientMock;

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

            HttpRequest request = CreateHttpPostRequest(expectedInputId, expectedCallSid);

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            PullRecordingResponse response = (PullRecordingResponse)okResult.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);
            Assert.IsNull(response.RecordingUri);
            Assert.AreEqual(0, response.RecordingLength);
            Assert.IsNull(response.FullRecordingUrl);

            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);
        }