public async Task Process_ReturnsEmptyRecognitionResult_WhenIntentScoreIsLessThanRequired() { var query = "I'm testing you"; var luisResultModel = CreateTestLuisResultModel(); var recognitionResult = new RecognitionResult { Message = string.Empty }; var settingsMock = new Mock <ISettings>(); settingsMock.Setup(x => x.IntentThreshold).Returns(0.9); var intentServiceMock = new Mock <IIntentService>(); intentServiceMock.Setup(x => x.Execute(string.Empty, null)) .Returns(Task.FromResult(recognitionResult)) .Verifiable(); var luisServiceMock = CreateLuisServiceMock(luisResultModel, query); var loggerMock = new Mock <ILogger <RecognitionService> >(); var recognitionService = new RecognitionService(settingsMock.Object, intentServiceMock.Object, luisServiceMock.Object, loggerMock.Object); var result = await recognitionService.Process(query); luisServiceMock.Verify(); intentServiceMock.Verify(); Assert.IsNotNull(result); Assert.AreEqual(result, recognitionResult); }
public async Task Process_ReturnsNonEmptyRecognitionResult_WhenIntentHasRequiredScore() { var query = "I'm testing you"; var luisResultModel = CreateTestLuisResultModel(); var recognitionResult = new RecognitionResult { Message = "I will pass your test" }; var settingsMock = new Mock <ISettings>(); settingsMock.Setup(x => x.IntentThreshold).Returns(0.75); var intentServiceMock = new Mock <IIntentService>(); var intentWithHighestScore = luisResultModel.Intents.OrderByDescending(x => x.Score).FirstOrDefault(); intentServiceMock.Setup(x => x.Execute(intentWithHighestScore.Name, luisResultModel.Entities)) .Returns(Task.FromResult(recognitionResult)) .Verifiable(); var luisServiceMock = CreateLuisServiceMock(luisResultModel, query); var loggerMock = new Mock <ILogger <RecognitionService> >(); var recognitionService = new RecognitionService(settingsMock.Object, intentServiceMock.Object, luisServiceMock.Object, loggerMock.Object); var result = await recognitionService.Process(query); luisServiceMock.Verify(); intentServiceMock.Verify(); Assert.IsNotNull(result); Assert.AreEqual(result, recognitionResult); }