public async Task ValidContentAssistantRequest_ShouldSucceedAsync() { //Arrange var minimumIntentScore = 0.5; var settings = new ProcessContentAssistantSettings { Text = "Test case", OutputVariable = "responseVariable", Score = 55 }; Context.Flow.BuilderConfiguration.MinimumIntentScore = minimumIntentScore; var contentAssistantResource = new AnalysisRequest { Text = settings.Text, Score = settings.Score.Value / 100 }; var contentResult = new ContentResult { Combinations = new ContentCombination[] { new ContentCombination { Entities = new string[] { "teste" }, Intent = "Teste" }, }, Name = "Name", Result = new Message { Content = "Answer" } }; var contentResultResponse = JsonConvert.SerializeObject(new ContentAssistantActionResponse { HasCombination = true, Entities = contentResult.Combinations.First().Entities.ToList(), Intent = contentResult.Combinations.First().Intent, Value = contentResult.Result.Content.ToString() }); //Act _artificialIntelligenceExtension.GetContentResultAsync(Arg.Is <AnalysisRequest>( ar => ar.Score == contentAssistantResource.Score && ar.Text == contentAssistantResource.Text), Arg.Any <CancellationToken>()).Returns(contentResult); await _processContentAssistantAction.ExecuteAsync(Context, JObject.FromObject(settings), CancellationToken); //Assert await Context.Received(1).SetVariableAsync(settings.OutputVariable, contentResultResponse, CancellationToken); }
public async Task ValidContentAssistantRequestWithoutText_ShouldFailAsync() { //Arrange var minimumIntentScore = 0.5; var settings = new ProcessContentAssistantSettings(); Context.Flow.BuilderConfiguration.MinimumIntentScore = minimumIntentScore; //Act System.Action functionCall = () => _processContentAssistantAction.ExecuteAsync(Context, JObject.FromObject(settings), CancellationToken); //Assert Assert.Throws <ArgumentException>(functionCall); }
public async Task ValidContentAssistantRequestWithoutCombinationFound_ShouldSuccceedAsync() { var minimumIntentScore = 0.5; Context.Flow.BuilderConfiguration.MinimumIntentScore = minimumIntentScore; var settings = new ProcessContentAssistantSettings { Text = "Test case", OutputVariable = "responseVariable" }; var contentAssistantResource = new AnalysisRequest { Text = settings.Text, Score = minimumIntentScore }; var contentAssistantResult = new ContentResult { Combinations = new ContentCombination[] {}, Name = string.Empty, Result = new Message { Content = string.Empty } }; var contentAssistantActionResponse = JsonConvert.SerializeObject(new ContentAssistantActionResponse { HasCombination = true, Entities = new List <string>(), Intent = string.Empty, Value = string.Empty }); //act _artificialIntelligenceExtension.GetContentResultAsync( Arg.Is <AnalysisRequest>( ar => ar.Score == contentAssistantResource.Score && ar.Text == contentAssistantResource.Text), CancellationToken). Returns(contentAssistantResult); await _processContentAssistantAction.ExecuteAsync(Context, settings, CancellationToken); //assert await Context.Received(1).SetVariableAsync(settings.OutputVariable, contentAssistantActionResponse, CancellationToken); }