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);
        }
        public void GetTwilioUriSuccess()
        {
            string uriFromRecording = "/recording/234234234.mp3";
            string expectedResult   = $"https://api.twilio.com{uriFromRecording}";

            InitializeSecrets();

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

            Assert.AreEqual(expectedResult, callWrapper.GetTwilioUri(uriFromRecording).AbsoluteUri, false);
        }
        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);
        }
        public void DeleteCallAsyncSuccess()
        {
            InitializeSecrets();

            string expectedCallSid = "CA10000000000000000000000000000008";

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

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

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

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

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

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

            Assert.IsTrue(success);
        }
        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);
            }
        }