Ejemplo n.º 1
0
        /// <summary>
        /// Runner for testing DeleteRecordingsHttpTrigger.Run() implementation runs correctly.
        /// </summary>
        public void DeleteRecordingsRunnerLocal()
        {
            HttpRequest request = CreateHttpPostRequest("Yes");

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            DeleteAccountRecordingsResponse response = (DeleteAccountRecordingsResponse)okResult.Value;

            Assert.IsTrue(response.AreAllRecordingsDeleted);

            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);
        }
        public void DeleteAccountRecordingsHttpTriggerRunTwilioGenericException()
        {
            InitializeWithTwilioMock();

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

            HttpRequest request = CreateHttpPostRequest("Yes");

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            DeleteAccountRecordingsResponse response = (DeleteAccountRecordingsResponse)okResult.Value;

            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);
        }
        public void DeleteAccountRecordingsHttpTriggerInvalidConfirmation()
        {
            InitializeWithNoTwilioMock();

            HttpRequest request = CreateHttpPostRequest("What?");

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

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

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

            BadRequestObjectResult badRequestResult = (BadRequestObjectResult)result;

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

            DeleteAccountRecordingsResponse response = (DeleteAccountRecordingsResponse)badRequestResult.Value;

            Assert.IsFalse(response.AreAllRecordingsDeleted);
            Assert.IsTrue(response.HasError);
            Assert.AreEqual((int)DeleteAccountRecordingsErrorCode.RequestMissingConfirmDelete, response.ErrorCode);
            Assert.AreEqual($"You must specify a value for the key '{DeleteAccountRecordingsRequest.ConfirmDeleteKeyName}' in the request body!", response.ErrorDetails);
        }
        public void DeleteAccountRecordingsHttpTriggerNoRecordings()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

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

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

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

            httpClient.MessageHandler.RegisterExpectedRecordingResponse(TestAccountSid, "recordings", expectedRecordingsResponse);

            HttpRequest request = CreateHttpPostRequest("Yes");

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

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

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

            OkObjectResult okRequestObject = (OkObjectResult)result;

            Assert.AreEqual(200, okRequestObject.StatusCode);
            Assert.IsInstanceOfType(okRequestObject.Value, typeof(DeleteAccountRecordingsResponse));

            DeleteAccountRecordingsResponse response = (DeleteAccountRecordingsResponse)okRequestObject.Value;

            Assert.IsTrue(response.AreAllRecordingsDeleted);
            Assert.IsFalse(response.HasError);
            Assert.AreEqual(0, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);
        }
        public void DeleteAccountRecordingsHttpTriggerFullSuccess()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

            string[] recordingSids =
            {
                "RE10000000000000000000000000000001",
                "RE10000000000000000000000000000002",
            };

            string expectedResponseContent = TemplateManager.LoadWithComposites(
                RecordingResponseTemplatePath,
                RecordingCompositesKey,
                RecordingCompositeTemplatePath,
                new Dictionary <string, string>()
            {
                { "pageSize", "2" },
            },
                new List <Dictionary <string, string> >()
            {
                new Dictionary <string, string>()
                {
                    { "accountSid", TestAccountSid },
                    { "recordingSid", recordingSids[0] },
                },
                new Dictionary <string, string>
                {
                    { "accountSid", TestAccountSid },
                    { "recordingSid", recordingSids[1] },
                },
            });

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

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

            httpClient.MessageHandler.RegisterExpectedRecordingResponse(TestAccountSid, "recordings", expectedRecordingsResponse);

            foreach (string recordingSid in recordingSids)
            {
                httpClient.MessageHandler.RegisterExpectedRecordingResponse(recordingSid, "delete", TestHelper.CreateHttpResponseMessage(HttpStatusCode.NoContent, string.Empty));
            }

            HttpRequest request = CreateHttpPostRequest("Yes");

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            DeleteAccountRecordingsResponse response = (DeleteAccountRecordingsResponse)okResult.Value;

            Assert.IsTrue(response.AreAllRecordingsDeleted);
            Assert.IsFalse(response.HasError);
            Assert.AreEqual(0, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);
        }