public void PlaceAndRecordCallAsyncSuccess()
        {
            InitializeSecrets();

            string expectedCallSid   = "CA10000000000000000000000000000001";
            string expectedStatus    = "in-progress";
            string numberToCall      = "5555555";
            string twilioLocalNumber = "5555656";

            string expectedResponseContent = TemplateManager.Load(CallResponseTemplatePath, new Dictionary <string, string>()
            {
                { "expectedCallSid", expectedCallSid },
                { "expectedStatus", expectedStatus },
            });

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

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

            httpClient.MessageHandler.RegisterExpectedCallResponse(numberToCall, "call", expectedResponse);

            Uri twiMLUrl = FormatTwiMLUrl(_config[TwiMLTemplateAppSettingName], new Dictionary <string, string>());

            TwilioCallWrapper callWrapper = Container.GetService <ITwilioCallWrapper>() as TwilioCallWrapper;

            callWrapper.InitializeAsync(
                _config[TwilioAccountSidSecretNameAppSettingName],
                _config[TwilioAuthTokenSecretNameAppSettingName],
                _config[AuthorityAppSettingName]).Wait();

            string callSid = callWrapper.PlaceAndRecordCallAsync(
                twiMLUrl,
                numberToCall,
                twilioLocalNumber,
                Log).Result;

            Assert.AreEqual(expectedCallSid, callSid, false);
        }
Example #2
0
        public void DeleteRecordingsHttpTriggerPartialSuccess()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

            string expectedCallSid = "CA10000000000000000000000000000300";

            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>()
                {
                    { "callSid", expectedCallSid },
                    { "recordingSid", recordingSids[0] },
                },
                new Dictionary <string, string>
                {
                    { "callSid", expectedCallSid },
                    { "recordingSid", recordingSids[1] },
                },
            });

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

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

            httpClient.MessageHandler.RegisterExpectedRecordingResponse(expectedCallSid, "recordings", expectedRecordingsResponse);
            httpClient.MessageHandler.RegisterExpectedRecordingResponse(recordingSids[0], "delete", TestHelper.CreateHttpResponseMessage(HttpStatusCode.NoContent, string.Empty));
            httpClient.MessageHandler.RegisterExpectedRecordingResponse(recordingSids[1], "delete", TestHelper.CreateHttpResponseMessage(HttpStatusCode.OK, string.Empty));

            HttpRequest request = CreateHttpPostRequest(expectedCallSid);

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            DeleteRecordingsResponse response = (DeleteRecordingsResponse)okResult.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);
            Assert.IsFalse(response.AreAllRecordingsDeleted);
            Assert.IsFalse(response.HasError);
            Assert.AreEqual(0, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);
        }
        public void DeleteRecordingsAsyncSuccess()
        {
            InitializeSecrets();

            string expectedCallSid = "CA10000000000000000000000000000009";

            string[] recordingSids =
            {
                "RE10000000000000000000000000000003",
                "RE10000000000000000000000000000004",
            };
            string[] recordingUris =
            {
                "https://storage/recordings/234234/file_2015_10_09_10_11_12.wav",
                "https://storage/recordings/212234/file_2016_09_02_01_00_13.wav",
            };

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

            HttpResponseMessage expectedResponse           = TestHelper.CreateHttpResponseMessage(HttpStatusCode.NoContent, string.Empty);
            HttpResponseMessage expectedRecordingsResponse = TestHelper.CreateHttpResponseMessage(HttpStatusCode.OK, expectedResponseContent);

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

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

            foreach (string recordingSid in recordingSids)
            {
                httpClient.MessageHandler.RegisterExpectedRecordingResponse(recordingSid, "delete", expectedResponse);
            }

            TwilioCallWrapper callWrapper = Container.GetService <ITwilioCallWrapper>() as TwilioCallWrapper;

            callWrapper.InitializeAsync(
                _config[TwilioAccountSidSecretNameAppSettingName],
                _config[TwilioAuthTokenSecretNameAppSettingName],
                _config[AuthorityAppSettingName]).Wait();

            bool success = callWrapper.DeleteRecordingsAsync(expectedCallSid, Log).Result;

            Assert.IsTrue(success);
        }
        public void FetchRecordingsAsyncSuccess()
        {
            InitializeSecrets();

            string expectedCallSid = "CA10000000000000000000000000000007";

            string[] recordingSids =
            {
                "RE10000000000000000000000000000001",
                "RE10000000000000000000000000000002",
            };
            string[] recordingUris =
            {
                "https://storage/recordings/234234/file_2015_10_09_10_11_12.wav",
                "https://storage/recordings/212234/file_2016_09_02_01_00_13.wav",
            };

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

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

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

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

            TwilioCallWrapper callWrapper = Container.GetService <ITwilioCallWrapper>() as TwilioCallWrapper;

            callWrapper.InitializeAsync(
                _config[TwilioAccountSidSecretNameAppSettingName],
                _config[TwilioAuthTokenSecretNameAppSettingName],
                _config[AuthorityAppSettingName]).Wait();

            IList <RecordingResource> recordings = callWrapper.FetchRecordingsAsync(expectedCallSid, Log).Result;

            Assert.AreEqual(2, recordings.Count);

            for (int index = 0; index < recordingSids.Length; index++)
            {
                Assert.AreEqual(TestAccountSid, recordings[index].AccountSid);
                Assert.AreEqual(expectedCallSid, recordings[index].CallSid);
                Assert.AreEqual(recordingSids[index], recordings[index].Sid);
                Assert.AreEqual(recordingUris[index], recordings[index].Uri);
            }
        }
Example #5
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);
        }