Skip to content

Commit

Permalink
remove entry in .botproj (microsoft#425)
Browse files Browse the repository at this point in the history
* remove entry field in .botproj

* dialog add displayName for client

* change to dialog displayName

* update unit test

* update cypress e2e test

* fix E2E tests

* fix ut

* fix ut

* rename to Main

* remove entry from bot runtime

* fix bot runtime tests

* break bot runtime tests
  • Loading branch information
zhixzhan authored and boydc2014 committed Jul 2, 2019
1 parent 4887231 commit 16600dd
Show file tree
Hide file tree
Showing 27 changed files with 211 additions and 127 deletions.
3 changes: 1 addition & 2 deletions BotProject/CSharp/BotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public void SetCurrent(BotProject botProject)
IStorage storage = new MemoryStorage();
var userState = new UserState(storage);
var conversationState = new ConversationState(storage);
var rootDialog = botProject.entry;

// manage all bot resources
var resourceExplorer = new ResourceExplorer();
Expand All @@ -81,7 +80,7 @@ public void SetCurrent(BotProject botProject)
};
CurrentAdapter = adapter;

CurrentBot = new TestBot(rootDialog, conversationState, resourceExplorer, DebugSupport.SourceRegistry);
CurrentBot = new TestBot("Main.dialog", conversationState, resourceExplorer, DebugSupport.SourceRegistry);
}

public void SetCurrent(Stream fileStream, LuConfigFile luConfig = null)
Expand Down
2 changes: 0 additions & 2 deletions BotProject/CSharp/BotProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ namespace Microsoft.Bot.Builder.TestBot.Json
{
public class BotProject
{
[JsonProperty("entry")]
public string entry { get; set; }
public List<string> Folders{ get; set; }

public static async Task<BotProject> LoadAsync(string file)
Expand Down
145 changes: 145 additions & 0 deletions BotProject/CSharp/Tests/InputsTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Adapters;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Dialogs.Adaptive;
using Microsoft.Bot.Builder.Dialogs.Debugging;
using Microsoft.Bot.Builder.Dialogs.Declarative;
using Microsoft.Bot.Builder.Dialogs.Declarative.Resources;
using Microsoft.Bot.Builder.Dialogs.Declarative.Types;
using Microsoft.Bot.Builder.TestBot.Json;
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;

namespace Tests
{
[TestClass]
public class InputsTests
{
private static string getOsPath(string path) => Path.Combine(path.TrimEnd('\\').Split('\\'));

private static readonly string samplesDirectory = getOsPath(@"..\..\..\..\..\..\SampleBots");

private static ResourceExplorer resourceExplorer = new ResourceExplorer();


[ClassInitialize]
public static void ClassInitialize(TestContext context)
{
TypeFactory.Configuration = new ConfigurationBuilder().AddInMemoryCollection().Build();
TypeFactory.RegisterAdaptiveTypes();
string path = Path.GetFullPath(Path.Combine(Environment.CurrentDirectory, samplesDirectory, "Inputs_Samples"));
resourceExplorer.AddFolder(path);
}

[ClassCleanup]
public static void ClassCleanup()
{
resourceExplorer.Dispose();
}

public TestContext TestContext { get; set; }

[TestMethod]
public async Task Inputs_01TextInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send("01")
.AssertReply("Hello, I'm Zoidberg. What is your name?")
.Send("02")
.AssertReply("Hello 02, nice to talk to you!")
.AssertReply("Hello, I'm Zoidberg. What is your name?")
.Send("02")
.AssertReply("What is your age?")
.StartTestAsync();
}

[TestMethod]
public async Task Inputs_02NumberInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send("02")
.AssertReply("What is your age?")
.Send("18")
.AssertReply("Hello, your age is 18!")
.AssertReply("2 * 2.2 equals?")
.Send("4.4")
.AssertReply("2 * 2.2 equals 4.4, that's right!")
.StartTestAsync();
}

[TestMethod]
public async Task Inputs_03ConfirmInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send("03")
.AssertReply("yes or no (1) Yes or (2) No")
.Send("asdasd")
.AssertReply("I need a yes or no. (1) Yes or (2) No")
.Send("yes")
.AssertReply("confirmation: True")
.AssertReply("yes or no (1) Yes or (2) No")
.Send("nope")
.AssertReply("confirmation: False")
.StartTestAsync();
}

[TestMethod]
public async Task Inputs_04ChoiceInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send("04")
.AssertReply("Please select a value from below:\n\n 1. Test1\n 2. Test2\n 3. Test3")
.Send("Test1")
.AssertReply("You select: Test1")
.StartTestAsync();
}

[TestMethod]
public async Task Inputs_06DateTimeInput()
{
await BuildTestFlow()
.SendConversationUpdate()
.Send("06")
.AssertReply("Please enter a date.")
.Send("June 1st 2019")
.AssertReply("You entered: 2019-06-01")
.StartTestAsync();
}

private TestFlow BuildTestFlow(bool sendTrace = false)
{
TypeFactory.Configuration = new ConfigurationBuilder().Build();
var storage = new MemoryStorage();
var convoState = new ConversationState(storage);
var userState = new UserState(storage);
var adapter = new TestAdapter(TestAdapter.CreateConversation(TestContext.TestName), sendTrace);
adapter
.UseStorage(storage)
.UseState(userState, convoState)
.UseLanguageGeneration(resourceExplorer)
.UseResourceExplorer(resourceExplorer)
.Use(new TranscriptLoggerMiddleware(new FileTranscriptLogger()));

var resource = resourceExplorer.GetResource("Main.dialog");
var dialog = DeclarativeTypeLoader.Load<IDialog>(resource, resourceExplorer, DebugSupport.SourceRegistry);
DialogManager dm = new DialogManager(dialog);

return new TestFlow(adapter, async (turnContext, cancellationToken) =>
{
if (dialog is AdaptiveDialog planningDialog)
{
await dm.OnTurnAsync(turnContext, null, cancellationToken).ConfigureAwait(false);
}
});
}
}
}
Loading

0 comments on commit 16600dd

Please sign in to comment.