コード例 #1
0
        public void HandleRequest_InputtingIntentRequestWithMatchingHandlerInFactory_KeepsHandlerContextAsNull()
        {
            IntentRequestHandler intentRequestHandler = new IntentRequestHandler();
            SkillResponse        expectedResponse     = ResponseBuilder.Empty();
            MockIntentHandler    mockIntentHandler    = new MockIntentHandler(expectedResponse);

            IntentRequestHandler.IntentHandlerFactory = new MockIntentHandlerFactory(mockIntentHandler);
            SkillRequest  skillRequest  = new SkillRequest();
            IntentRequest intentRequest = new IntentRequest();

            intentRequest.Intent = new Intent()
            {
                Name = mockIntentHandler.IntentName
            };
            skillRequest.Request = intentRequest;
            intentRequestHandler.RequestContext = new RequestContext(skillRequest, null, null);

            Assert.IsNull(mockIntentHandler.RequestContext);
            Assert.IsNotNull((skillRequest.Request as IntentRequest).Intent);
            Assert.IsTrue(IntentRequestHandler.IntentHandlerFactory.CustomIntentHandlers.Exists(x => x.IsHandlerForIntent(intentRequest.Intent)));

            intentRequestHandler.HandleRequest();

            Assert.IsNull(mockIntentHandler.RequestContext);
        }
コード例 #2
0
        public void IsHandlerForRequest_InputtingIntentRequest_WithNoIntentSet_ReturnsFalse()
        {
            IntentRequestHandler intentRequestHandler = new IntentRequestHandler();
            SkillRequest         skillRequest         = new SkillRequest();
            IntentRequest        intentRequest        = new IntentRequest();

            skillRequest.Request = intentRequest;

            Assert.IsNull(intentRequest.Intent);
            Assert.IsFalse(intentRequestHandler.IsHandlerForRequest(skillRequest));
        }
コード例 #3
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenuserAskedForBeginner_ReturnFirstQuestion_Beginner()
        {
            _request.IsNew = false;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Beginner, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();

            var currentQuestion = _questions.questions.First(x => x.slotIdentifier == "QuestionFive");

            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains(currentQuestion.text));
        }
コード例 #4
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenuserJustStartedTheSkill_ReturnFirstQuestion_Intermediate()
        {
            _request.IsNew = true;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Intermdiate, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();

            var currentQuestion = _questions.questions.First(x => x.slotIdentifier == "QuestionFive");

            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains(currentQuestion.text));
        }
コード例 #5
0
        public void IsHandlerForRequest_InputtingIntentRequest_WithIntentSet_ReturnsTrue()
        {
            IntentRequestHandler intentRequestHandler = new IntentRequestHandler();
            SkillRequest         skillRequest         = new SkillRequest();
            IntentRequest        intentRequest        = new IntentRequest();

            intentRequest.Intent = new Intent();
            skillRequest.Request = intentRequest;

            Assert.IsNotNull((skillRequest.Request as IntentRequest).Intent);
            Assert.IsTrue(intentRequestHandler.IsHandlerForRequest(skillRequest));
        }
コード例 #6
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenUserEnetrsAWrongInput_TellTheUserToPickANumber_Beginner()
        {
            _request.IsNew = false;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Beginner, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();

            var index = _request.SlotsList.FindIndex(x => x.Key == "QuestionFive");

            _request.SlotsList[index] = new KeyValuePair <string, string>("QuestionFive", "five");
            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains("pick a number"));
        }
コード例 #7
0
        public void IsHandlerForRequest_InputtingNonIntentRequest_ReturnsFalse()
        {
            IntentRequestHandler intentRequestHandler = new IntentRequestHandler();
            SkillRequest         skillRequest         = new SkillRequest();

            skillRequest.Request = new SessionEndedRequest();

            Assert.IsFalse(intentRequestHandler.IsHandlerForRequest(skillRequest));

            skillRequest.Request = new LaunchRequest();

            Assert.IsFalse(intentRequestHandler.IsHandlerForRequest(skillRequest));
        }
コード例 #8
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenUserenetrsAWrongAnser_TellUserTheCorrectAnswer_Beginner()
        {
            _request.IsNew = false;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Beginner, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();
            var currentQuestion = _questions.questions.First(x => x.slotIdentifier == "QuestionFive");

            var index = _request.SlotsList.FindIndex(x => x.Key == "QuestionFive");

            _request.SlotsList[index] = new KeyValuePair <string, string>("QuestionFive", (Convert.ToInt32(currentQuestion.correctAnswerIndex) - 1).ToString());
            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains("The correct answer is"));
        }
コード例 #9
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenUserAsksforRepeat_RepeatTheQuestion_Beginner()
        {
            _request.IsNew = false;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Beginner, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();
            var currentQuestion = _questions.questions.First(x => x.slotIdentifier == "QuestionFive");

            var index = _request.SlotsList.FindIndex(x => x.Key == "QuestionFive");

            _request.SlotsList[index] = new KeyValuePair <string, string>("QuestionFive", "repeat");
            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains(currentQuestion.text));
        }
コード例 #10
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenUserEntersThecorrectAnswer_TellUserThatTheAnswerIsCorrect_Intermediate()
        {
            _request.IsNew = false;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Intermdiate, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();
            var currentQuestion = _questions.questions.First(x => x.slotIdentifier == "QuestionFive");

            var index = _request.SlotsList.FindIndex(x => x.Key == "QuestionFive");

            _request.SlotsList[index] = new KeyValuePair <string, string>("QuestionFive", currentQuestion.correctAnswerIndex);
            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains("Your answer is correct"));
        }
コード例 #11
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void WhenUserIsAtTheLastQuestion_TellUserTheCorectScore_Intermediate()
        {
            _request.IsNew = false;
            _intentHandler = new IntentRequestHandler(_request, DifficultyLevelEnum.Intermdiate, filePath);
            _questions     = _intentHandler.GetTheQuestionsForThisWeek();

            _request.SlotsList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("QuestionFive", "1"),
                new KeyValuePair <string, string>("QuestionOne", "2"),
                new KeyValuePair <string, string>("QuestionTwo", "3"),
                new KeyValuePair <string, string>("QuestionThree", "4"),
                new KeyValuePair <string, string>("QuestionFour", "1")
            };

            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains("Your total score is"));
        }
コード例 #12
0
ファイル: AlexaRulesTest.cs プロジェクト: irinasmt/Alexa
        public void TellUserTheLastQuestion_Intermediate()
        {
            _request.IsNew     = false;
            _intentHandler     = new IntentRequestHandler(_request, DifficultyLevelEnum.Intermdiate, filePath);
            _questions         = _intentHandler.GetTheQuestionsForThisWeek();
            _request.SlotsList = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("QuestionFive", "1"),
                new KeyValuePair <string, string>("QuestionOne", "2"),
                new KeyValuePair <string, string>("QuestionTwo", "3"),
                new KeyValuePair <string, string>("QuestionThree", "1"),
                new KeyValuePair <string, string>("QuestionFour", "")
            };

            var questionfour = _questions.questions.First(x => x.slotIdentifier == "QuestionFour");

            var response = _intentHandler.GetQuestion();

            Assert.True(response.Response.OutputSpeech.Ssml.Contains(questionfour.text));
        }
コード例 #13
0
        public void IsHandlerForRequest_InputtingNull_ReturnsFalse()
        {
            IntentRequestHandler intentRequestHandler = new IntentRequestHandler();

            Assert.IsFalse(intentRequestHandler.IsHandlerForRequest(null));
        }