2018-03-28 22:08:49 +00:00
|
|
|
|
using BotSharp.Core.Agents;
|
|
|
|
|
|
using BotSharp.Core.Engines;
|
|
|
|
|
|
using BotSharp.Core.Models;
|
|
|
|
|
|
using EntityFrameworkCore.BootKit;
|
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BotSharp.UnitTest
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
|
public class AgentTest : TestEssential
|
|
|
|
|
|
{
|
|
|
|
|
|
[TestMethod]
|
2018-04-30 03:09:32 +00:00
|
|
|
|
public void CreateAgentTest()
|
2018-03-28 22:08:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
var agent = new Agent
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = BOT_ID,
|
|
|
|
|
|
Name = BOT_NAME,
|
2018-05-07 00:48:10 +00:00
|
|
|
|
Language = "en",
|
|
|
|
|
|
UserId = Guid.NewGuid().ToString()
|
2018-03-28 22:08:49 +00:00
|
|
|
|
};
|
|
|
|
|
|
var rasa = new RasaAi(dc);
|
|
|
|
|
|
|
2018-05-22 00:39:33 +00:00
|
|
|
|
int row = dc.DbTran(() => rasa.agent.SaveAgent(dc));
|
2018-03-28 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2018-04-06 22:39:30 +00:00
|
|
|
|
public void UpdateAgentTest()
|
2018-03-28 22:08:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
var agent = new Agent
|
|
|
|
|
|
{
|
|
|
|
|
|
Id = BOT_ID,
|
|
|
|
|
|
Name = BOT_NAME,
|
|
|
|
|
|
Language = "en"
|
|
|
|
|
|
};
|
|
|
|
|
|
var rasa = new RasaAi(dc);
|
|
|
|
|
|
|
2018-05-22 00:39:33 +00:00
|
|
|
|
int row = dc.DbTran(() => rasa.agent.SaveAgent(dc));
|
2018-03-28 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2018-04-06 22:39:30 +00:00
|
|
|
|
public void RestoreAgentTest()
|
2018-03-28 22:08:49 +00:00
|
|
|
|
{
|
|
|
|
|
|
var rasa = new RasaAi(dc);
|
|
|
|
|
|
var importer = new AgentImporterInDialogflow();
|
|
|
|
|
|
|
2018-05-06 17:41:36 +00:00
|
|
|
|
string dataDir = $"{Database.ContentRootPath}\\App_Data\\DbInitializer\\Agents\\";
|
|
|
|
|
|
var agent = rasa.RestoreAgent(importer, BOT_NAME, dataDir);
|
2018-03-28 22:08:49 +00:00
|
|
|
|
agent.Id = BOT_ID;
|
|
|
|
|
|
agent.ClientAccessToken = BOT_CLIENT_TOKEN;
|
|
|
|
|
|
agent.DeveloperAccessToken = BOT_DEVELOPER_TOKEN;
|
2018-05-07 00:48:10 +00:00
|
|
|
|
agent.UserId = Guid.NewGuid().ToString();
|
2018-05-22 00:39:33 +00:00
|
|
|
|
rasa.agent = agent;
|
2018-03-28 22:08:49 +00:00
|
|
|
|
|
2018-05-22 00:39:33 +00:00
|
|
|
|
int row = dc.DbTran(() => rasa.agent.SaveAgent(dc));
|
2018-03-28 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
2018-04-06 22:39:30 +00:00
|
|
|
|
public void TrainAgentTest()
|
2018-03-28 22:08:49 +00:00
|
|
|
|
{
|
2018-04-06 22:39:30 +00:00
|
|
|
|
var config = new AIConfiguration(BOT_CLIENT_TOKEN, SupportedLanguage.English);
|
|
|
|
|
|
config.SessionId = Guid.NewGuid().ToString();
|
|
|
|
|
|
|
|
|
|
|
|
var rasa = new RasaAi(dc, config);
|
2018-05-22 00:39:33 +00:00
|
|
|
|
rasa.agent = rasa.LoadAgent(dc, config);
|
2018-04-30 03:09:32 +00:00
|
|
|
|
string msg = rasa.Train(dc);
|
|
|
|
|
|
|
|
|
|
|
|
Assert.IsTrue(!String.IsNullOrEmpty(msg));
|
2018-03-28 22:08:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|