public async Task TestHello() { // Instantiate dialog to test IDialog <object> rootDialog = new RootDialog(); // Create in-memory bot environment Func <IDialog <object> > MakeRoot = () => rootDialog; using (new FiberTestBase.ResolveMoqAssembly(rootDialog)) using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog)) { // Create a message to send to bot var toBot = DialogTestBase.MakeTestMessage(); toBot.From.Id = Guid.NewGuid().ToString(); // Act toBot.Text = "hello"; IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); // Assert Assert.AreEqual("請輸入你的名字", toUser.Text); // Act toBot.Text = "Puck"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert Assert.AreEqual("設定名稱為 Puck", toUser.Text); } }
public async Task TestCards() { // Instantiate dialog to test IDialog <object> rootDialog = new RootDialog(); // Create in-memory bot environment Func <IDialog <object> > MakeRoot = () => rootDialog; using (new FiberTestBase.ResolveMoqAssembly(rootDialog)) using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog)) { // Create a message to send to bot var toBot = DialogTestBase.MakeTestMessage(); toBot.From.Id = Guid.NewGuid().ToString(); // Act toBot.Text = "cards"; IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); // Assert HeroCard heroCard = (HeroCard)toUser.Attachments[0].Content; Assert.AreEqual("請選擇卡片類型?", heroCard.Text); Assert.AreEqual("HeroCard", heroCard.Buttons[0].Value); Assert.AreEqual("ReceiptCard", heroCard.Buttons[1].Value); Assert.AreEqual("ThumbnailCard", heroCard.Buttons[2].Value); Assert.AreEqual("SigninCard", heroCard.Buttons[3].Value); Assert.AreEqual("AnimationCard", heroCard.Buttons[4].Value); Assert.AreEqual("AudioCard", heroCard.Buttons[5].Value); Assert.AreEqual("VideoCard", heroCard.Buttons[6].Value); // Act toBot.Text = "HeroCard"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert HeroCard heroCard2 = (HeroCard)toUser.Attachments[0].Content; Assert.AreEqual("請選擇排版類型?", heroCard2.Text); Assert.AreEqual("single", heroCard2.Buttons[0].Value); Assert.AreEqual("list", heroCard2.Buttons[1].Value); Assert.AreEqual("carousel", heroCard2.Buttons[2].Value); // Act toBot.Text = "carousel"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert HeroCard heroCard3 = (HeroCard)toUser.Attachments[0].Content; Assert.AreEqual("carousel", toUser.AttachmentLayout); Assert.AreEqual("Splatoon 2", heroCard3.Title); Assert.AreEqual("Happy New Year. by Puck", heroCard3.Text); Assert.AreEqual(1, heroCard3.Images.Count); Assert.AreEqual("https://imgur.com/hwylGzp.jpg", heroCard3.Images[0].Url); Assert.AreEqual("https://imgur.com/hwylGzp.jpg", heroCard3.Buttons[0].Value); Assert.AreEqual(1, heroCard3.Buttons.Count); Assert.AreEqual("Open", heroCard3.Buttons[0].Title); Assert.AreEqual(ActionTypes.OpenUrl, heroCard3.Buttons[0].Type); } }
public async Task TestOperation() { // Instantiate dialog to test IDialog <object> rootDialog = new RootDialog(); // Create in-memory bot environment Func <IDialog <object> > MakeRoot = () => rootDialog; using (new FiberTestBase.ResolveMoqAssembly(rootDialog)) using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog)) { // Create a message to send to bot var toBot = DialogTestBase.MakeTestMessage(); toBot.From.Id = Guid.NewGuid().ToString(); // Act toBot.Text = "operation"; IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); // Assert Assert.AreEqual("請輸入第一個數字: ", toUser.Text); // Act toBot.Text = "123"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert HeroCard heroCard = (HeroCard)toUser.Attachments[0].Content; Assert.AreEqual("請輸入運算子: ", heroCard.Text); Assert.AreEqual("Add", heroCard.Buttons[0].Value); Assert.AreEqual("Sub", heroCard.Buttons[1].Value); Assert.AreEqual("Mul", heroCard.Buttons[2].Value); Assert.AreEqual("Div", heroCard.Buttons[3].Value); // Act toBot.Text = "Add"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert Assert.AreEqual("請輸入第二個數字: ", toUser.Text); // Act toBot.Text = "456"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert Assert.AreEqual("123 + 456 = 579", toUser.Text); } }
public async Task ShouldReturnEcho() { // Instantiate dialog to test IDialog <object> rootDialog = new RootDialog(); // Create in-memory bot environment Func <IDialog <object> > MakeRoot = () => rootDialog; using (new FiberTestBase.ResolveMoqAssembly(rootDialog)) using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog)) { // Create a message to send to bot var toBot = DialogTestBase.MakeTestMessage(); toBot.From.Id = Guid.NewGuid().ToString(); toBot.Text = "hi!"; // Send message and check the answer. IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); // Verify the result Assert.AreEqual(" 你說了 hi!,總共有 3 個字元", toUser.Text); } }
public async Task TestHelp() { // Instantiate dialog to test IDialog <object> rootDialog = new RootDialog(); // Create in-memory bot environment Func <IDialog <object> > MakeRoot = () => rootDialog; using (new FiberTestBase.ResolveMoqAssembly(rootDialog)) using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, rootDialog)) { // Create a message to send to bot var toBot = DialogTestBase.MakeTestMessage(); toBot.From.Id = Guid.NewGuid().ToString(); // Act toBot.Text = "help"; IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); // Assert HeroCard heroCard = (HeroCard)toUser.Attachments[0].Content; Assert.AreEqual("功能清單", heroCard.Title); Assert.AreEqual("Hello", heroCard.Buttons[0].Value); Assert.AreEqual("Operation", heroCard.Buttons[1].Value); Assert.AreEqual("OperationV2", heroCard.Buttons[2].Value); Assert.AreEqual("Cards", heroCard.Buttons[3].Value); Assert.AreEqual("Post", heroCard.Buttons[4].Value); // Act toBot.Text = "Hello"; toUser = await GetResponse(container, MakeRoot, toBot); // Assert Assert.AreEqual("請輸入你的名字", toUser.Text); } }
private async Task EchoDialogFlow(IDialog <object> echoDialog) { // arrange var toBot = DialogTestBase.MakeTestMessage(); toBot.From.Id = Guid.NewGuid().ToString(); toBot.Text = "Test"; Func <IDialog <object> > MakeRoot = () => echoDialog; using (new FiberTestBase.ResolveMoqAssembly(echoDialog)) using (var container = Build(Options.MockConnectorFactory | Options.ScopedQueue, echoDialog)) { // act: sending the message IMessageActivity toUser = await GetResponse(container, MakeRoot, toBot); // assert: check if the dialog returned the right response Assert.IsTrue(toUser.Text.StartsWith("1")); Assert.IsTrue(toUser.Text.Contains("Test")); // act: send the message 10 times for (int i = 0; i < 10; i++) { // pretend we're the intercom switch, and copy the bot data from message to message toBot.Text = toUser.Text; toUser = await GetResponse(container, MakeRoot, toBot); } // assert: check the counter at the end Assert.IsTrue(toUser.Text.StartsWith("11")); toBot.Text = "reset"; toUser = await GetResponse(container, MakeRoot, toBot); // checking if there is any cards in the attachment and promote the card.text to message.text if (toUser.Attachments != null && toUser.Attachments.Count > 0) { var card = (HeroCard)toUser.Attachments.First().Content; toUser.Text = card.Text; } Assert.IsTrue(toUser.Text.ToLower().Contains("are you sure")); toBot.Text = "yes"; toUser = await GetResponse(container, MakeRoot, toBot); Assert.IsTrue(toUser.Text.ToLower().Contains("reset count")); //send a random message and check count toBot.Text = "test"; toUser = await GetResponse(container, MakeRoot, toBot); Assert.IsTrue(toUser.Text.StartsWith("1")); toBot.Text = "/deleteprofile"; toUser = await GetResponse(container, MakeRoot, toBot); Assert.IsTrue(toUser.Text.ToLower().Contains("deleted")); using (var scope = DialogModule.BeginLifetimeScope(container, toBot)) { var botData = scope.Resolve <IBotData>(); await botData.LoadAsync(default(CancellationToken)); var stack = scope.Resolve <IDialogStack>(); Assert.AreEqual(0, stack.Frames.Count); } } }