public void GetFullRecordingUriSuccess()
        {
            InitializeSecrets();

            string expectedCallSid              = "CA10000000000000000000000000000010";
            string expectedRecordingSid         = "RE10000000000000000000000000000005";
            string expectedRecordingRelativeUri = $"/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Recordings/{expectedRecordingSid}";
            string expectedRecordingUri         = $"{TwilioCallWrapper.TwilioUriBase}{expectedRecordingRelativeUri}";

            RecordingResource recording = RecordingResource.FromJson(
                TemplateManager.Load(RecordingCompositeTemplatePath, new Dictionary <string, string>()
            {
                { "accountSid", TestAccountSid },
                { "callSid", expectedCallSid },
                { "recordingSid", expectedRecordingSid },
                { "recordingUri", expectedRecordingRelativeUri },
            }));

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

            Uri recordingUri = callWrapper.GetFullRecordingUri(recording, Log);

            Assert.IsNotNull(recordingUri);
            Assert.AreEqual(expectedRecordingUri, recordingUri.AbsoluteUri);
        }
        public void HangupCallAsyncQueued()
        {
            InitializeSecrets();

            string expectedCallSid    = "CA10000000000000000000000000000006";
            string expectedStatusText = "queued";

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

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

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

            httpClient.MessageHandler.RegisterExpectedCallResponse(expectedCallSid, "status", expectedResponse);

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

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

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

            Assert.AreEqual(true, success);
        }
        public void FetchStatusAsyncSuccess()
        {
            InitializeSecrets();

            string expectedCallSid    = "CA10000000000000000000000000000003";
            string expectedStatusText = "in-progress";

            CallResource.StatusEnum expectedStatus = CallResource.StatusEnum.InProgress;

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

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

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

            httpClient.MessageHandler.RegisterExpectedCallResponse(expectedCallSid, "status", expectedResponse);

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

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

            CallResource.StatusEnum status = callWrapper.FetchStatusAsync(expectedCallSid, Log).Result;

            Assert.AreEqual(expectedStatus, status);
        }
Ejemplo n.º 4
0
        public void InitiateCallHttpTriggerSuccessWithDtmf()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

            string expectedInputId      = "012345678"; // Example pulled from https://citizenpath.com/faq/find-alien-registration-number/
            string expectedCallSid      = "CA10000000000000000000000000000001";
            string expectedStatus       = "in-progress";
            string expectedNumberToCall = _config[ExpectedNumberToCallAppSetting];

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

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

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

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

            HttpRequest request = CreateHttpPostRequest(
                expectedInputId,
                new DtmfRequest()
            {
                Dtmf       = "1ww012345678ww1ww1ww1",
                InitPause  = 0,
                FinalPause = 60,
            });

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

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

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

            OkObjectResult okResult = (OkObjectResult)result;

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

            InitiateCallResponse response = (InitiateCallResponse)okResult.Value;

            Assert.AreEqual(expectedInputId, response.InputId);
            Assert.AreEqual(expectedInputId, response.AcceptedInputId);
            Assert.AreEqual(expectedCallSid, 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);
        }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        public void DeleteRecordingsHttpTriggerNoRecordings()
        {
            InitializeWithNoTwilioMock();
            InitializeSecrets();

            string expectedCallSid = "CA10000000000000000000000000000300";

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

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

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

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

            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 okRequestObject = (OkObjectResult)result;

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

            DeleteRecordingsResponse response = (DeleteRecordingsResponse)okRequestObject.Value;

            Assert.AreEqual(expectedCallSid, response.CallSid);
            Assert.IsTrue(response.AreAllRecordingsDeleted);
            Assert.IsFalse(response.HasError);
            Assert.AreEqual(0, response.ErrorCode);
            Assert.IsNull(response.ErrorDetails);
        }
        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);
        }