public void HandleAlexaRequestTest() { // arrange Word word = new Word { Id = 1, WordName = "test", PartOfSpeech = "noun", Definition = "a test", Example = " a moq uses a test" }; var wordService = new Mock <IWordService>(); wordService.Setup(w => w.GetRandomWord()).Returns(word); Dictionary <WordEnum, string> mockDictionary = new Dictionary <WordEnum, string>(); mockDictionary[WordEnum.Word] = word.WordName; mockDictionary[WordEnum.WordPartOfSpeech] = word.PartOfSpeech; mockDictionary[WordEnum.WordDefinition] = word.Definition; mockDictionary[WordEnum.WordExample] = word.Example; var dictionaryService = new Mock <IDictionaryService>(); dictionaryService.Setup(w => w.GetWordDictionaryFromString(word.WordName)).Returns(mockDictionary); var cacheService = new Mock <ICacheService>(); var wordOfTheDayIntentHandlerStrategy = new WordOfTheDayIntentHandlerStrategy(wordService.Object, dictionaryService.Object, cacheService.Object); AlexaRequestPayload alexaRequestPayload = AlexaSkillProjectTestHelpers.GetAlexaRequestPayload("AlexaRequestPayloadTest.json"); alexaRequestPayload.Request.Type = "IntentRequest"; alexaRequestPayload.Request.Intent.Name = "WordOfTheDayIntent"; // act AlexaResponse alexaResponse = wordOfTheDayIntentHandlerStrategy.HandleAlexaRequest(alexaRequestPayload); // assert Assert.IsTrue(alexaResponse.Response.OutputSpeech.Ssml.Contains("<speak><p>The Word is test</p>")); Assert.AreEqual(alexaRequestPayload.Session.Attributes.LastWord, word.WordName); Assert.AreEqual(alexaRequestPayload.Session.Attributes.LastWordDefinition, word.Definition); }
public void ProcessAlexaRequestTest() { // arrange AlexaRequestPayload alexaRequestPayload = AlexaSkillProjectTestHelpers.GetAlexaRequestPayload("AlexaRequestPayloadTest.json"); var alexaRequestMapper = new Mock <IAlexaRequestMapper>(); var alexaRequestPersistenceService = new Mock <IAlexaRequestPersistenceService>(); Word word = new Word { Id = 1, WordName = "test", PartOfSpeech = "noun", Definition = "a test", Example = " a moq uses a test" }; var wordService = new Mock <IWordService>(); wordService.Setup(w => w.GetRandomWord()).Returns(word); var cacheService = new Mock <ICacheService>(); //cacheService.Setup(c => c.CacheAlexaRequest(alexaRequestPayload)) Dictionary <WordEnum, string> mockDictionary = new Dictionary <WordEnum, string>(); mockDictionary[WordEnum.Word] = word.WordName; mockDictionary[WordEnum.WordPartOfSpeech] = word.PartOfSpeech; mockDictionary[WordEnum.WordDefinition] = word.Definition; mockDictionary[WordEnum.WordExample] = word.Example; var dictionaryService = new Mock <IDictionaryService>(); dictionaryService.Setup(w => w.GetWordDictionaryFromString(word.WordName)).Returns(mockDictionary); var wordOfTheDayIntentHandlerStrategy = new WordOfTheDayIntentHandlerStrategy(wordService.Object, dictionaryService.Object, cacheService.Object); var alexaRequestHandlerStrategyFactory = new Mock <IAlexaRequestHandlerStrategyFactory>(); alexaRequestHandlerStrategyFactory.Setup(x => x.CreateAlexaRequestHandlerStrategy(alexaRequestPayload)).Returns(wordOfTheDayIntentHandlerStrategy); var alexaRequestValidationService = new Mock <IAlexaRequestValidationService>(); alexaRequestValidationService.Setup(x => x.ValidateAlexaRequest(alexaRequestPayload)).Returns(SpeechletRequestValidationResult.OK); var alexaRequestService = new AlexaRequestService( alexaRequestMapper.Object, alexaRequestPersistenceService.Object, alexaRequestHandlerStrategyFactory.Object, alexaRequestValidationService.Object ); alexaRequestPayload.Request.Type = "IntentRequest"; alexaRequestPayload.Request.Intent.Name = "WordOfTheDayIntent"; // act AlexaResponse alexaResponse = alexaRequestService.ProcessAlexaRequest(alexaRequestPayload); // assert Assert.IsTrue(alexaResponse.Response.OutputSpeech.Ssml.Contains("<speak><p>The Word is test</p>")); }