BotSharp/Bot.UnitTest/AgentTest.cs

56 lines
1.5 KiB
C#
Raw Normal View History

2017-12-18 05:30:20 +00:00
using Bot.Rasa;
using Bot.Rasa.Agents;
using Bot.Rasa.Console;
using EntityFrameworkCore.BootKit;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Bot.UnitTest
{
[TestClass]
2017-12-30 20:26:35 +00:00
public class AgentTest : TestEssential
2017-12-18 05:30:20 +00:00
{
public static String PIZZA_BOT_ID = "2b6a288e-d891-40c6-96ce-6a0cf324545c";
2017-12-30 20:26:35 +00:00
2017-12-18 05:30:20 +00:00
[TestMethod]
public void CreateAgent()
{
2017-12-30 20:26:35 +00:00
var rasa = new RasaConsole(dc);
2017-12-18 05:30:20 +00:00
2017-12-30 20:26:35 +00:00
var agent = rasa.RestoreAgent(PIZZA_BOT_ID);
2017-12-18 05:30:20 +00:00
2017-12-18 13:31:15 +00:00
int row = dc.DbTran(() => rasa.CreateAgent(agent));
2017-12-30 20:26:35 +00:00
2017-12-18 13:31:15 +00:00
if(row > 0)
{
2018-01-02 18:05:35 +00:00
var result = rasa.Train(dc, agent.Id);
2017-12-18 13:31:15 +00:00
}
2017-12-30 20:26:35 +00:00
var loadedAgent = rasa.LoadAgent(agent.Id);
Assert.IsTrue(loadedAgent.Intents.Count == agent.Intents.Count);
var response = rasa.TextRequest(agent.Id, "weather in Chicago tomorrow");
Assert.IsTrue(response.Intent.Name == "weather");
2017-12-18 05:30:20 +00:00
}
[TestMethod]
public void TextRequest()
{
2017-12-30 20:26:35 +00:00
var rasa = new RasaConsole(dc);
2017-12-18 05:30:20 +00:00
var response = rasa.TextRequest(PIZZA_BOT_ID, "how old are you");
2018-01-02 18:05:35 +00:00
response = rasa.TextRequest(PIZZA_BOT_ID, "where are you from");
2017-12-18 05:30:20 +00:00
response = rasa.TextRequest(PIZZA_BOT_ID, "would you like some cookie");
}
[TestMethod]
public void Train()
{
2017-12-30 20:26:35 +00:00
var rasa = new RasaConsole(dc);
2017-12-18 13:31:15 +00:00
rasa.Train(dc, PIZZA_BOT_ID);
2017-12-18 05:30:20 +00:00
}
}
}