Skip to content

Commit

Permalink
feat: multi-locale bot file structure (#2164)
Browse files Browse the repository at this point in the history
* reform bot file structure

* update

* update

* client add locale

* crud with locale

* update test sample bot

* update

* update emptybot structure

* update crud test

* auto fix lu referrence

* reform sample bot structure

* clean up

* update dialogId & isBot

* update

* update test

* redirect to root dialog

* update

* update test

* update test entry

* update tests

* handle old bot

* update sample

* update refer

* update

* update

* refer lg lu no locale

* import lg no locale

* update

* fix refer

* import resolve with locale

* set test locale

* get refered lu without locale

* Temporary disable SendConversationUpdate in CSharp test case, for sdk locale issue

* update test

* update test

* update test

* update test

* update

* update test

* use file resolver handle locale

* test

* resolve confilct

* reform test samplebot

* clean

Co-authored-by: Chris Whitten <christopher.whitten@microsoft.com>
  • Loading branch information
zhixzhan and cwhitten authored Mar 24, 2020
1 parent 314d4bf commit 9e1dd65
Show file tree
Hide file tree
Showing 277 changed files with 1,287 additions and 1,124 deletions.
36 changes: 24 additions & 12 deletions BotProject/Templates/CSharp/Tests/ActionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

Expand All @@ -39,11 +40,22 @@ public static void ClassInitialize(TestContext context)

public TestContext TestContext { get; set; }

// Override for locale test
public static IActivity CreateConversationUpdateActivity()
{
return new Activity(ActivityTypes.ConversationUpdate)
{
MembersAdded = new List<ChannelAccount>() { new ChannelAccount(id: "test") },
MembersRemoved = new List<ChannelAccount>(),
Locale = "en-us"
};
}

[TestMethod]
public async Task Actions_01Actions()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine))
.Send("01")
.AssertReply("Step 1")
Expand All @@ -58,7 +70,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_02EndTurn()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine))
.Send("02")
.AssertReply("What's up?")
Expand All @@ -71,7 +83,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_03IfCondition()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("03")
.AssertReply("Hello, I'm Zoidberg. What is your name?")
.Send("Carlos")
Expand All @@ -83,7 +95,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_04EditArray()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("04")
.AssertReply("Here are the index and values in the array.")
.AssertReply("0: 11111")
Expand All @@ -100,7 +112,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_05EndDialog()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("05")
.AssertReply("Hello, I'm Zoidberg. What is your name?")
.Send("luhan")
Expand All @@ -117,7 +129,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_06SwitchCondition()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("07")
.AssertReply("Please select a value from below:\n\n 1. Test1\n 2. Test2\n 3. Test3")
.Send("Test1")
Expand All @@ -130,7 +142,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_07RepeatDialog()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("08")
.AssertReply("Do you want to repeat this dialog, yes to repeat, no to end this dialog (1) Yes or (2) No")
.Send("Yes")
Expand All @@ -143,7 +155,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_08TraceAndLog()
{
await BuildTestFlow(getFolderPath("ActionsSample"), sendTrace: true)
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("09")
.Send("luhan")
.AssertReply(activity =>
Expand All @@ -159,7 +171,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"), sendTrace: true)
public async Task Actions_09EditActions()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("10")
.AssertReply("Hello, I'm Zoidberg. What is your name?")
.Send("luhan")
Expand All @@ -172,7 +184,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_10ReplaceDialog()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("11")
.AssertReply("Hello, I'm Zoidberg. What is your name?")
.Send("luhan")
Expand All @@ -192,7 +204,7 @@ await BuildTestFlow(getFolderPath("ActionsSample"))
public async Task Actions_11EmitEvent()
{
await BuildTestFlow(getFolderPath("ActionsSample"))
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("I can show you examples on how to use actions. Enter the number next to the entity that you with to see in action.{0}01 - Actions{0}02 - EndTurn{0}03 - IfCondiftion{0}04 - EditArray, Foreach{0}05 - EndDialog{0}06 - HttpRequest{0}07 - SwitchCondition{0}08 - RepeatDialog{0}09 - TraceAndLog{0}10 - EditActions{0}11 - ReplaceDialog{0}12 - EmitEvent{0}13 - QnAMaker", Environment.NewLine)).Send("12")
.AssertReply("Say moo to get a response, say emit to emit a event.")
.Send("moo")
Expand All @@ -215,7 +227,7 @@ private TestFlow BuildTestFlow(string folderPath, bool sendTrace = false)
.UseState(userState, convoState)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var resource = resourceExplorer.GetResource("actionssample.dialog");
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
Expand Down
17 changes: 15 additions & 2 deletions BotProject/Templates/CSharp/Tests/ControllingConversationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Microsoft.Bot.Builder.Dialogs.Declarative.Types;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

Expand Down Expand Up @@ -42,11 +44,22 @@ public static void ClassCleanup()

public TestContext TestContext { get; set; }

// Override for locale test
public static IActivity CreateConversationUpdateActivity()
{
return new Activity(ActivityTypes.ConversationUpdate)
{
MembersAdded = new List<ChannelAccount>() { new ChannelAccount(id: "test") },
MembersRemoved = new List<ChannelAccount>(),
Locale = "en-us"
};
}

[TestMethod]
public async Task ControllingConversationBotTest()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("Welcome to the Controlling Conversation sample. Choose from the list below to try.{0}You can also type \"Cancel\" to cancel any dialog or \"Endturn\" to explicitly accept an input.", Environment.NewLine))
.Send("01")
.AssertReply("Hello, What's your age?")
Expand Down Expand Up @@ -89,7 +102,7 @@ private TestFlow BuildTestFlow(bool sendTrace = false)
.UseState(userState, convoState)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var resource = resourceExplorer.GetResource("controllingconversationflowsample.dialog");
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
Expand Down
25 changes: 19 additions & 6 deletions BotProject/Templates/CSharp/Tests/InputsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Microsoft.Bot.Builder.Dialogs.Declarative.Types;
using Microsoft.Bot.Schema;
using Microsoft.Extensions.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;

Expand Down Expand Up @@ -43,11 +45,22 @@ public static void ClassCleanup()

public TestContext TestContext { get; set; }

// Override for locale test
public static IActivity CreateConversationUpdateActivity()
{
return new Activity(ActivityTypes.ConversationUpdate)
{
MembersAdded = new List<ChannelAccount>() { new ChannelAccount(id: "test") },
MembersRemoved = new List<ChannelAccount>(),
Locale = "en-us"
};
}

[TestMethod]
public async Task Inputs_01TextInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("Welcome to Input Sample Bot.{0}I can show you examples on how to use actions, You can enter number 01-07{0}01 - TextInput{0}02 - NumberInput{0}03 - ConfirmInput{0}04 - ChoiceInput{0}05 - AttachmentInput{0}06 - DateTimeInput{0}07 - OAuthInput{0}", Environment.NewLine))
.Send("01")
.AssertReply("Hello, I'm Zoidberg. What is your name? (This can't be interrupted)")
Expand All @@ -62,7 +75,7 @@ await BuildTestFlow()
public async Task Inputs_02NumberInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("Welcome to Input Sample Bot.{0}I can show you examples on how to use actions, You can enter number 01-07{0}01 - TextInput{0}02 - NumberInput{0}03 - ConfirmInput{0}04 - ChoiceInput{0}05 - AttachmentInput{0}06 - DateTimeInput{0}07 - OAuthInput{0}", Environment.NewLine))
.Send("02")
.AssertReply("What is your age?")
Expand All @@ -78,7 +91,7 @@ await BuildTestFlow()
public async Task Inputs_03ConfirmInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("Welcome to Input Sample Bot.{0}I can show you examples on how to use actions, You can enter number 01-07{0}01 - TextInput{0}02 - NumberInput{0}03 - ConfirmInput{0}04 - ChoiceInput{0}05 - AttachmentInput{0}06 - DateTimeInput{0}07 - OAuthInput{0}", Environment.NewLine))
.Send("03")
.AssertReply("yes or no (1) Yes or (2) No")
Expand All @@ -93,7 +106,7 @@ await BuildTestFlow()
public async Task Inputs_04ChoiceInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("Welcome to Input Sample Bot.{0}I can show you examples on how to use actions, You can enter number 01-07{0}01 - TextInput{0}02 - NumberInput{0}03 - ConfirmInput{0}04 - ChoiceInput{0}05 - AttachmentInput{0}06 - DateTimeInput{0}07 - OAuthInput{0}", Environment.NewLine)).Send("04")
.AssertReply("Please select a value from below:\n\n 1. Test1\n 2. Test2\n 3. Test3")
.Send("Test1")
Expand All @@ -105,7 +118,7 @@ await BuildTestFlow()
public async Task Inputs_06DateTimeInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply(String.Format("Welcome to Input Sample Bot.{0}I can show you examples on how to use actions, You can enter number 01-07{0}01 - TextInput{0}02 - NumberInput{0}03 - ConfirmInput{0}04 - ChoiceInput{0}05 - AttachmentInput{0}06 - DateTimeInput{0}07 - OAuthInput{0}", Environment.NewLine)).Send("06")
.AssertReply("Please enter a date.")
.Send("June 1st")
Expand All @@ -124,7 +137,7 @@ private TestFlow BuildTestFlow(bool sendTrace = false)
.UseState(userState, convoState)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var resource = resourceExplorer.GetResource("askingquestionssample.dialog");
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
Expand Down
16 changes: 14 additions & 2 deletions BotProject/Templates/CSharp/Tests/MessageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,23 @@ public static void ClassCleanup()

public TestContext TestContext { get; set; }

// Override for locale test
public static IActivity CreateConversationUpdateActivity()
{
return new Activity(ActivityTypes.ConversationUpdate)
{
MembersAdded = new List<ChannelAccount>() { new ChannelAccount(id: "test") },
MembersRemoved = new List<ChannelAccount>(),
Locale = "en-us"
};
}


[TestMethod]
public async Task MessageTest()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send(CreateConversationUpdateActivity())
.AssertReply("What type of message would you like to send?\n\n 1. Simple Text\n 2. Text With Memory\n 3. LGWithParam\n 4. LGComposition\n 5. Structured LG\n 6. MultiLineText\n 7. IfElseCondition\n 8. SwitchCondition")
.Send("1")
.AssertReplyOneOf(new string[] { "Hi, this is simple text", "Hey, this is simple text", "Hello, this is simple text" })
Expand Down Expand Up @@ -80,7 +92,7 @@ private TestFlow BuildTestFlow(bool sendTrace = false)
.UseState(userState, convoState)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var resource = resourceExplorer.GetResource("respondingwithtextsample.dialog");
var dialog = resourceExplorer.LoadType<Dialog>(resource);
DialogManager dm = new DialogManager(dialog)
.UseResourceExplorer(resourceExplorer)
Expand Down
Loading

0 comments on commit 9e1dd65

Please sign in to comment.