forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CancelAndHelpDialogTests.cs
95 lines (83 loc) · 3.58 KB
/
CancelAndHelpDialogTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System;
using System.Threading;
using System.Threading.Tasks;
using CoreBot.Tests.Common;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Dialogs;
using Microsoft.Bot.Builder.Testing;
using Microsoft.Bot.Builder.Testing.XUnit;
using Microsoft.Bot.Connector;
using Microsoft.Bot.Schema;
using Microsoft.BotBuilderSamples.Dialogs;
using Xunit;
using Xunit.Abstractions;
namespace CoreBot.Tests.Dialogs
{
public class CancelAndHelpDialogTests : BotTestBase
{
private readonly IMiddleware[] _middlewares;
public CancelAndHelpDialogTests(ITestOutputHelper output)
: base(output)
{
_middlewares = new IMiddleware[] { new XUnitDialogTestLogger(output) };
}
[Theory]
[InlineData("cancel")]
[InlineData("quit")]
public async Task ShouldBeAbleToCancel(string cancelUtterance)
{
var sut = new TestCancelAndHelpDialog();
var testClient = new DialogTestClient(Channels.Test, sut, middlewares: _middlewares);
// Execute the test case
var reply = await testClient.SendActivityAsync<IMessageActivity>("Hi");
Assert.Equal("Hi there", reply.Text);
Assert.Equal(DialogTurnStatus.Waiting, testClient.DialogTurnResult.Status);
reply = await testClient.SendActivityAsync<IMessageActivity>(cancelUtterance);
Assert.Equal("Cancelling...", reply.Text);
Assert.Equal(DialogTurnStatus.Complete, testClient.DialogTurnResult.Status);
}
[Theory]
[InlineData("help")]
[InlineData("?")]
public async Task ShouldBeAbleToGetHelp(string cancelUtterance)
{
var sut = new TestCancelAndHelpDialog();
var testClient = new DialogTestClient(Channels.Test, sut, middlewares: _middlewares);
// Execute the test case
var reply = await testClient.SendActivityAsync<IMessageActivity>("Hi");
Assert.Equal("Hi there", reply.Text);
Assert.Equal(DialogTurnStatus.Waiting, testClient.DialogTurnResult.Status);
reply = await testClient.SendActivityAsync<IMessageActivity>(cancelUtterance);
Assert.Equal("Show help here", reply.Text);
Assert.Equal(DialogTurnStatus.Waiting, testClient.DialogTurnResult.Status);
}
/// <summary>
/// A concrete instance of <see cref="CancelAndHelpDialog"/> for testing.
/// </summary>
private class TestCancelAndHelpDialog : CancelAndHelpDialog
{
public TestCancelAndHelpDialog()
: base(nameof(TestCancelAndHelpDialog))
{
AddDialog(new TextPrompt(nameof(TextPrompt)));
var steps = new WaterfallStep[]
{
PromptStep,
FinalStep,
};
AddDialog(new WaterfallDialog("testWaterfall", steps));
InitialDialogId = "testWaterfall";
}
private async Task<DialogTurnResult> PromptStep(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
return await stepContext.PromptAsync(nameof(TextPrompt), new PromptOptions { Prompt = MessageFactory.Text("Hi there") }, cancellationToken);
}
private Task<DialogTurnResult> FinalStep(WaterfallStepContext stepContext, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
}
}