public async Task Given_ManyLuisServices_When_GetResultWithStrongestTopScoringIntentIsCalled_Then_ResultWithStrongerTopScoringIntentIsReturned(string queryText)
        {
            // Arrange
            var request = new LuisRequest(queryText);
            var token   = CancellationToken.None;

            var luisServiceMock1 = new Mock <ILuisServiceWrapper>();

            luisServiceMock1.Setup(m => m.ModifyRequest(It.Is <LuisRequest>(lr => lr.Query == queryText))).Returns(request);
            var luisResult = new LuisResult(queryText, new List <EntityRecommendation>(), new IntentRecommendation("IntentA", score: 0.95));

            luisServiceMock1.Setup(m => m.QueryAsync(request, token)).ReturnsAsync(luisResult);

            var luisServiceMock2 = new Mock <ILuisServiceWrapper>();

            luisServiceMock2.Setup(m => m.ModifyRequest(It.Is <LuisRequest>(lr => lr.Query == queryText))).Returns(request);
            var strongerLuisResult = new LuisResult(queryText, new List <EntityRecommendation>(), new IntentRecommendation("IntentB", score: 0.96));

            luisServiceMock2.Setup(m => m.QueryAsync(request, token)).ReturnsAsync(strongerLuisResult);

            // Act
            var result = await LuisQueryHelper.GetResultWithStrongestTopScoringIntent(new[] { luisServiceMock1.Object, luisServiceMock2.Object }, queryText, token);

            // Assert
            result.Should().BeEquivalentTo(strongerLuisResult);
        }
        public void Given_QueryTextIsNullOrWhitespace_When_GetResultWithStrongestTopScoringIntentIsCalled_Then_ArgumentExceptionIsThrown(string queryText)
        {
            Func <Task> act = async() =>
                              await LuisQueryHelper.GetResultWithStrongestTopScoringIntent(new[] { new Mock <ILuisServiceWrapper>().Object }, queryText, CancellationToken.None);

            act.Should().Throw <ArgumentException>("queryText");
        }
Example #3
0
        private async Task UseLuis(IDialogContext context, IMessageActivity response)
        {
            var luisresult = await LuisQueryHelper.GetResultWithStrongestTopScoringIntent(this.luisServices.ToLuisServiceWrappers(), response.Text, context.CancellationToken);

            LuisPromptResult luisPromptResult = new LuisPromptResult {
                ResultType = LuisPromptResultType.LuisResult
            };

            var isUnkownReponse =
                string.IsNullOrEmpty(luisresult.TopScoringIntent.Intent) ||
                luisresult.TopScoringIntent.Intent == Intents.None ||
                !this.luisIntents?.Contains(luisresult.TopScoringIntent.Intent) == true;

            if (!isUnkownReponse)
            {
                luisPromptResult.LuisResult = luisresult;
                context.Done(luisPromptResult);
                return;
            }

            if (!this.isLuisUsedFirst)
            {
                var noneEntityRecommendation = new EntityRecommendation(Intents.None);
                luisPromptResult.LuisResult = new LuisResult(
                    luisresult.Query,
                    new List <EntityRecommendation> {
                    noneEntityRecommendation
                },
                    new IntentRecommendation(Intents.None, 1));
                context.Done(luisPromptResult);
            }
            else
            {
                await this.UseRegularPrompt(context, response);
            }
        }
        public void Given_ServicesCollectionIsEmpty_When_GetResultWithStrongestTopScoringIntentIsCalled_Then_ArgumentExceptionIsThrown()
        {
            Func <Task> act = async() => await LuisQueryHelper.GetResultWithStrongestTopScoringIntent(Enumerable.Empty <ILuisServiceWrapper>(), "query", CancellationToken.None);

            act.Should().Throw <ArgumentException>("luisServices");
        }
        public void Given_ServicesCollectionIsNull_When_GetResultWithStrongestTopScoringIntentIsCalled_Then_NullReferenceExceptionIsThrown()
        {
            Func <Task> act = async() => await LuisQueryHelper.GetResultWithStrongestTopScoringIntent(null, "query", CancellationToken.None);

            act.Should().Throw <NullReferenceException>("luisServices");
        }