public void CheckCallProgressHttpTriggerRun() { HttpRequest request = CreateHttpPostRequest(_config.CallSid); ExecutionContext context = new ExecutionContext() { FunctionAppDirectory = Directory.GetCurrentDirectory(), }; IActionResult result = CheckCallProgressHttpTrigger.Run(request, _log, context).Result; Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okResult = (OkObjectResult)result; Assert.AreEqual(200, okResult.StatusCode); Assert.IsInstanceOfType(okResult.Value, typeof(CheckCallProgressResponse)); CheckCallProgressResponse response = (CheckCallProgressResponse)okResult.Value; Assert.AreEqual(_config.CallSid, response.CallSid); 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); }
public void CheckCallProgressHttpTriggerRunMissingCallSid() { InitializeWithNoTwilioMock(); InitializeSecrets(); HttpRequest request = CreateHttpPostRequest(null); ExecutionContext context = new ExecutionContext() { FunctionAppDirectory = Directory.GetCurrentDirectory(), }; IActionResult result = CheckCallProgressHttpTrigger.Run(request, Log, context).Result; Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); BadRequestObjectResult badRequestResult = (BadRequestObjectResult)result; Assert.AreEqual(400, badRequestResult.StatusCode); Assert.IsInstanceOfType(badRequestResult.Value, typeof(CheckCallProgressResponse)); CheckCallProgressResponse response = (CheckCallProgressResponse)badRequestResult.Value; Assert.IsNull(response.CallSid); Assert.IsNull(response.Status); Assert.IsTrue(response.HasError); Assert.AreEqual((int)CheckCallProgressErrorCode.RequestMissingCallSid, response.ErrorCode); Assert.AreEqual($"You must specify a value for the key '{CheckCallProgressRequest.CallSidKeyName}' in the request body!", response.ErrorDetails); }
public void CheckCallProgressHttpTriggerRunBadRequest() { InitializeWithNoTwilioMock(); string expectedCallSid = $"CA10000000000000000000000000000200"; HttpRequest request = CreateHttpPostRequest(expectedCallSid); ExecutionContext context = new ExecutionContext() { FunctionAppDirectory = Directory.GetCurrentDirectory(), }; IActionResult result = CheckCallProgressHttpTrigger.Run(request, Log, context).Result; Assert.IsInstanceOfType(result, typeof(BadRequestObjectResult)); BadRequestObjectResult badRequestResult = (BadRequestObjectResult)result; Assert.AreEqual(400, badRequestResult.StatusCode); Assert.IsInstanceOfType(badRequestResult.Value, typeof(CheckCallProgressResponse)); CheckCallProgressResponse response = (CheckCallProgressResponse)badRequestResult.Value; Assert.AreEqual(expectedCallSid, response.CallSid); Assert.IsNull(response.Status); Assert.IsTrue(response.HasError); Assert.AreEqual((int)CommonErrorCode.BadRequest, response.ErrorCode); Assert.AreEqual("Bad request.", response.ErrorDetails); }
public void CheckCallProgressHttpTriggerRunInProgressStatuses() { InitializeWithNoTwilioMock(); InitializeSecrets(); HttpClientMock httpClient = CheckCallProgressHttpTrigger.Container.GetService <IHttpClientWrapper>() as HttpClientMock; for (int index = 0; index < InProgressStatuses.Count; index++) { string expectedCallSid = $"CA10000000000000000000000000000{index + 101}"; string expectedStatus = InProgressStatuses[index].ToString(); string expectedCallDuration = "600"; string expectedResponse = TemplateManager.Load(CallResponseTemplatePath, new Dictionary <string, string>() { { "expectedCallSid", expectedCallSid }, { "expectedStatus", expectedStatus }, { "expectedCallDuration", expectedCallDuration }, }); HttpResponseMessage expectedResponseMessage = TestHelper.CreateHttpResponseMessage(HttpStatusCode.OK, expectedResponse); httpClient.MessageHandler.RegisterExpectedCallResponse(expectedCallSid, "status", expectedResponseMessage); HttpRequest request = CreateHttpPostRequest(expectedCallSid); ExecutionContext context = new ExecutionContext() { FunctionAppDirectory = Directory.GetCurrentDirectory(), }; IActionResult result = CheckCallProgressHttpTrigger.Run(request, Log, context).Result; Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okResult = (OkObjectResult)result; Assert.AreEqual(200, okResult.StatusCode); Assert.IsInstanceOfType(okResult.Value, typeof(CheckCallProgressResponse)); CheckCallProgressResponse response = (CheckCallProgressResponse)okResult.Value; Assert.AreEqual(expectedCallSid, response.CallSid); Assert.AreEqual(int.Parse(expectedCallDuration), response.Duration); Assert.AreEqual(expectedStatus, response.Status); Assert.IsFalse(response.HasError); Assert.AreEqual(0, response.ErrorCode); Assert.IsNull(response.ErrorDetails); } }
/// <summary> /// Ensure CheckCallPrgressHttpTrigger.Run() runs correctly against local URL. /// </summary> /// <param name="queue">The queue of tests to run.</param> public void CheckCallProgressRunnerLocal(ConcurrentQueue <TestConfiguration> queue) { TestConfiguration nextTestConfiguration = null; while (!queue.IsEmpty) { if (queue.TryDequeue(out nextTestConfiguration)) { HttpRequest request = CreateHttpPostRequest(nextTestConfiguration.CallSid); ExecutionContext context = new ExecutionContext() { FunctionAppDirectory = Directory.GetCurrentDirectory(), }; IActionResult result = CheckCallProgressHttpTrigger.Run(request, _log, context).Result; Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okResult = (OkObjectResult)result; Assert.AreEqual(200, okResult.StatusCode); Assert.IsInstanceOfType(okResult.Value, typeof(CheckCallProgressResponse)); CheckCallProgressResponse response = (CheckCallProgressResponse)okResult.Value; Assert.AreEqual(nextTestConfiguration.CallSid, response.CallSid); 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); _log.LogInformation("Writing returned call status to test configuration..."); nextTestConfiguration.CallStatus = response.Status; } TH.Thread.Sleep(2000); } _concurrentConfig.Save(GlobalTestConstants.ConcurrentTestConfigurationFilePath); }
public void CheckCallProgressHttpTriggerRunTwilioGenericException() { InitializeWithTwilioMock(); string expectedCallSid = $"CA10000000000000000000000000000200"; InitializeTwilioExceptions(new Dictionary <string, Exception>() { { expectedCallSid, new TwilioEx.TwilioException("TestException") }, }); HttpRequest request = CreateHttpPostRequest(expectedCallSid); ExecutionContext context = new ExecutionContext() { FunctionAppDirectory = Directory.GetCurrentDirectory(), }; IActionResult result = CheckCallProgressHttpTrigger.Run(request, Log, context).Result; Assert.IsInstanceOfType(result, typeof(OkObjectResult)); OkObjectResult okResult = (OkObjectResult)result; Assert.AreEqual(200, okResult.StatusCode); Assert.IsInstanceOfType(okResult.Value, typeof(CheckCallProgressResponse)); CheckCallProgressResponse response = (CheckCallProgressResponse)okResult.Value; Assert.AreEqual(expectedCallSid, response.CallSid); Assert.IsNull(response.Status); 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); }