forked from microsoft/BotFramework-Composer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
remove entry in .botproj (microsoft#425)
* 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
Showing
27 changed files
with
211 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.