public void WhatsMyNameIntentRespondsWithName()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(WhatsMyNameIntentMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });


            speechlet.DoSessionManagement((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);
            var speechletResponse = speechlet.OnIntent((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);

            Assert.Equal("Your name is John, goodbye", ((PlainTextOutputSpeech)speechletResponse.OutputSpeech).Text);
        }
        public void WhatsMyNameIntentLeavesSessionOpenWithoutProperSessionValue()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(WhatsMyNameIntentWithoutNameMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });

            speechlet.DoSessionManagement((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);
            var speechletResponse = speechlet.OnIntent((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);

            Assert.False(speechletResponse.ShouldEndSession);
        }
        public void WhatsMyNameIntentNoSessionAttributesFound()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(WhatsMyNameIntentWithoutAnySessionAttributesMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });

            speechlet.DoSessionManagement((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);
            var speechletResponse = speechlet.OnIntent((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);

            Assert.Equal("I'm sorry, you seem to be new here. You can tell me your name by saying, my name is Sam", ((PlainTextOutputSpeech)speechletResponse.OutputSpeech).Text);
        }
        public void WhatsMyNameIntentIsExistingSession()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(WhatsMyNameIntentMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });

            Assert.False(response.AlexaRequest.Session.IsNew);
        }
        public void WhatsMyNameIntentSessionIntentSequenceMatches()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(WhatsMyNameIntentMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });

            var intentSequence = response.AlexaRequest.Session.Attributes[Session.INTENT_SEQUENCE];

            Assert.Equal("MyNameIsIntent", intentSequence);
        }
        public void MyNameIsIntentSlotsExistButNotNameRequestsRetry()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(MyNameIntentMissingNameSlotMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });


            speechlet.DoSessionManagement((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);
            var speechletResponse = speechlet.OnIntent((IntentRequest)response.AlexaRequest.Request, response.AlexaRequest.Session);

            Assert.Equal("I'm not sure what your name is, please try again", ((PlainTextOutputSpeech)speechletResponse.OutputSpeech).Text);
        }
        public void MyNameIsIntentNameSlotMatches()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(MyNameIntentMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });

            var intentRequest = response.AlexaRequest.Request as IntentRequest;

            if (intentRequest == null)
                throw new NullReferenceException("intentRequest is null");

            var slots = intentRequest.Intent.Slots;

            if (slots == null)
                throw new NullReferenceException("slots is null");
            
            Assert.Equal("John", slots["Name"]?.Value);
        }
        public void MyNameIsIntentContainsNameSlot()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(MyNameIntentMessage)
            };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.OnRequestValidation(new ValidationRequest { HttpRequest = request, RequestTime = DateTime.UtcNow });

            var intentRequest = response.AlexaRequest.Request as IntentRequest;

            Assert.True(intentRequest?.Intent.Slots.ContainsKey("Name"));
        }
        public void InvalidIntentThrowsException()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
            {
                Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                Content = new StringContent(UnknownIntentMessage)
            };

            var speechlet = new SampleNameSpeechlet();

            Exception ex = Assert.Throws<SpeechletException>(() => speechlet.GetResponse(request));

            Assert.Equal("Invalid Intent", ex.Message);
        }
        public void MyNameIsIntentIsFound()
        {
            SessionId = new Guid().ToString().ToLower();
            RequestId = new Guid().ToString().ToLower();

            var request = new HttpRequestMessage
                {
                    Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } },
                    Headers =
                        {
                            { Sdk.SIGNATURE_CERT_URL_REQUEST_HEADER, "TestSignatureCertChainUrlValue" },
                            { Sdk.SIGNATURE_REQUEST_HEADER, "TestSignatureValue" }
                        },
                    Content = new StringContent(MyNameIntentMessage)
                };

            var speechlet = new SampleNameSpeechlet();
            var response = speechlet.GetResponse(request);

            Assert.True(response.IsSuccessStatusCode);
        }