public async Task SendsSmsAndReturnsQueryUrlWhenCallerStartsSessionWithoutClientUrl()
        {
            var smsBodyNumber = connectEventWithoutClientUrl.SelectToken("Details.ContactData.CustomerEndpoint.Address")
                                .Value <string>()
                                .Substring(1);
            var lookupsMock = new Mock <ITwilioLookupsApi>(MockBehavior.Strict);

            lookupsMock.Setup(api => api.NumberInfo(It.IsAny <string>(), It.IsAny <string>(), "carrier"))
            .ReturnsAsync((string phoneNumber, string countryCode, string type) =>
                          JObject.Parse($"{{\"url\": \"https://lookups.twilio.com/v1/PhoneNumbers/{phoneNumber}?Type=carrier\",\"carrier\": {{ \"type\": \"mobile\" }},\"phone_number\": \"{phoneNumber}\",\"country_code\": \"{countryCode}\"}}"));

            var messagingMock = new Mock <ITwilioMessagingApi>(MockBehavior.Strict);

            messagingMock.Setup(api => api.SendSMS(It.IsAny <string>(), It.Is <Dictionary <string, string> >(
                                                       args => args["From"].Equals(SmsNumber) && args["Body"].Contains($"={IVRWorkflow.SwitchCallerId(smsBodyNumber)}"))))
            .ReturnsAsync((string accountSid, Dictionary <string, string> args) =>
                          JObject.Parse($"{{\"account_sid\": \"{accountSid}\",\"api_version\": \"2010-04-01\",\"body\": \"{args["Body"]}\",\"from\": \"{args["From"]}\",\"status\": \"sent\",\"to\": \"{args["To"]}\"}}"));

            var twilioApi = new TwilioApi(lookupsMock.Object, messagingMock.Object, "ACxxxxxxxxxxxxxx", SmsNumber);

            var smsWorkflow = new SmsWorkflow(twilioApi);

            using (var testClient = new HttpClient(new SuccessfulCreateSessionImmediateReturn())
            {
                BaseAddress = new Uri("https://cvnet2.radishsystems.com/ivr/api/")
            })
            {
                try
                {
                    Environment.SetEnvironmentVariable("TWILIO_PHONENUMBER", SmsNumber);
                    var workflow = new CreateSessionWorkflow(testClient, smsWorkflow);
                    var response = await workflow.Process(connectEventWithoutClientUrl, context);

                    Assert.Equal(JTokenType.Boolean, response["LambdaResult"].Type);
                    Assert.True((bool)response["LambdaResult"]);
                    Assert.Equal(QueryUrl, response["QueryUrl"].Value <string>());
                    Assert.False(response.TryGetValue("SessionStatus", out var value));
                    Assert.False(response.TryGetValue("SessionUrl", out value));
                    Assert.False(response.TryGetValue("PropertiesUrl", out value));
                    Assert.False(response.TryGetValue("ControlMessageUrl", out value));
                    Assert.True(response.TryGetValue("ConnectStartTime", out value));
                    Assert.Equal(JTokenType.Date, value.Type);
                }
                finally
                {
                    Environment.SetEnvironmentVariable("TWILIO_PHONENUMBER", null);
                }
            }

            lookupsMock.VerifyAll();
            messagingMock.VerifyAll();
        }
        public async Task TimesOutWhenCallerDoesNotStartsSession()
        {
            using (var testClient = new HttpClient(new TimeoutCreateSession())
            {
                BaseAddress = new Uri("https://cvnet2.radishsystems.com/ivr/api/")
            })
            {
                var workflow = new CreateSessionWorkflow(testClient);
                var response = await workflow.Process(connectEvent, context);

                Assert.True(response["LambdaResult"].Type == JTokenType.Boolean);
                Assert.False((bool)response["LambdaResult"]);
                Assert.True(response["StatusCode"].Type == JTokenType.Integer);
                Assert.True(HttpStatusCode.RequestTimeout == (HttpStatusCode)(int)response["StatusCode"]);
                Assert.True(response["Timeout"].Type == JTokenType.Boolean);
                Assert.True((bool)response["Timeout"]);
                Assert.True(response["FailureReason"].Type == JTokenType.String);
            }
        }
        public async Task ReturnsQueryUrlWhenCallerStartsSession()
        {
            using (var testClient = new HttpClient(new SuccessfulCreateSessionImmediateReturn())
            {
                BaseAddress = new Uri("https://cvnet2.radishsystems.com/ivr/api/")
            })
            {
                var workflow = new CreateSessionWorkflow(testClient);
                var response = await workflow.Process(connectEvent, context);

                Assert.Equal(JTokenType.Boolean, response["LambdaResult"].Type);
                Assert.True((bool)response["LambdaResult"]);
                Assert.Equal(QueryUrl, (string)response["QueryUrl"]);
                Assert.False(response.TryGetValue("SessionStatus", out var value));
                Assert.False(response.TryGetValue("SessionUrl", out value));
                Assert.False(response.TryGetValue("PropertiesUrl", out value));
                Assert.False(response.TryGetValue("ControlMessageUrl", out value));
                Assert.True(response.TryGetValue("ConnectStartTime", out value));
                Assert.Equal(JTokenType.Date, value.Type);
            }
        }