public async Task ShowsFirstMessageAndCallsAzureDialogDirectly() { // Arrange var feedbackOptions = new FeedbackOptions(); var mockTemplateManager = SimpleMockFactory.CreateMockTemplateManager("mock template message"); var mockDialog = new Mock <AzureDialog>(Configuration, _telemetryClient, mockTemplateManager.Object); mockDialog.Setup(x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(async(DialogContext dialogContext, object options, CancellationToken cancellationToken) => { dialogContext.Dialogs.Add(new TextPrompt("MockDialog")); return(await dialogContext.PromptAsync("MockDialog", new PromptOptions() { Prompt = MessageFactory.Text($"{nameof(AzureDialog)} mock invoked") }, cancellationToken)); }); var fileSearchDialog = new Mock <FileSearchDialog>(_telemetryClient, Configuration); var mainDialog = new MainDialog(_telemetryClient, feedbackOptions, _mockLogger.Object, mockTemplateManager.Object, _userState, mockDialog.Object, fileSearchDialog.Object); var testClient = new DialogTestClient(Channels.Test, mainDialog, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("mock template message", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>("next"); Assert.Equal($"{nameof(AzureDialog)} mock invoked", reply.Text); }
public async Task ShowsUnsupportedCitiesWarning(string jsonFile, string expectedMessage) { // Load the LUIS result json and create a mock recognizer that returns the expected result. var luisResultJson = GetEmbeddedTestData($"{GetType().Namespace}.TestData.{jsonFile}"); var mockLuisResult = JsonConvert.DeserializeObject <FlightBooking>(luisResultJson); var mockLuisRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <FlightBookingRecognizer, FlightBooking>( mockLuisResult, new Mock <IConfiguration>().Object); mockLuisRecognizer.Setup(x => x.IsConfigured).Returns(true); var sut = new MainDialog(mockLuisRecognizer.Object, _mockBookingDialog, _mockLogger.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Execute the test case Output.WriteLine($"Test Case: {mockLuisResult.Text}"); var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy"); Assert.Equal($"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>(mockLuisResult.Text); Assert.Equal(expectedMessage, reply.Text); }
public async Task ShouldInvokeContinueAndBegin() { _mockDialog .Setup(x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(new DialogTurnResult(DialogTurnStatus.Waiting))); _mockDialog .Setup(x => x.ContinueDialogAsync(It.IsAny <DialogContext>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(new DialogTurnResult(DialogTurnStatus.Complete))); var sut = new DialogTestClient(_mockDialog.Object); // Assert proper methods in the mock dialog have been called. await sut.SendActivityAsync <IMessageActivity>("test"); _mockDialog.Verify( x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>()), Times.Once()); _mockDialog.Verify( x => x.ContinueDialogAsync(It.IsAny <DialogContext>(), It.IsAny <CancellationToken>()), Times.Never); // Assert proper methods in the mock dialog have been called on the next turn too. await sut.SendActivityAsync <IMessageActivity>("test 2"); _mockDialog.Verify( x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>()), Times.Once()); _mockDialog.Verify( x => x.ContinueDialogAsync(It.IsAny <DialogContext>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task TaskSelector(string utterance, string intent, string invokedDialogResponse) { var mockLuisRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <IRecognizer, FlightBooking>( new FlightBooking { Intents = new Dictionary <FlightBooking.Intent, IntentScore> { { Enum.Parse <FlightBooking.Intent>(intent), new IntentScore() { Score = 1 } }, }, Entities = new FlightBooking._Entities(), }); var sut = new MainDialog(_mockLogger.Object, mockLuisRecognizer.Object, _mockBookingDialog); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitOutputMiddleware(Output) }); var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("What can I help you with today?", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>(utterance); Assert.Equal(invokedDialogResponse, reply.Text); reply = testClient.GetNextReply <IMessageActivity>(); Assert.Equal("What else can I do for you?", reply.Text); }
public async Task ShouldHandleInvokeActivities() { Activity activitySent = null; string fromBotIdSent = null; string toBotIdSent = null; Uri toUriSent = null; // Callback to capture the parameters sent to the skill void CaptureAction(string fromBotId, string toBotId, Uri toUri, Uri serviceUrl, string conversationId, Activity activity, CancellationToken cancellationToken) { // Capture values sent to the skill so we can assert the right parameters were used. fromBotIdSent = fromBotId; toBotIdSent = toBotId; toUriSent = toUri; activitySent = activity; } // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClient = CreateMockSkillClient(CaptureAction); // Use Memory for conversation state var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient); // Create the SkillDialogInstance and the activity to send. var activityToSend = (Activity)Activity.CreateInvokeActivity(); activityToSend.Name = Guid.NewGuid().ToString(); var sut = new SkillDialog(dialogOptions); var client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions { Activity = activityToSend }, conversationState: conversationState); // Send something to the dialog to start it await client.SendActivityAsync <Activity>("irrelevant"); // Assert results and data sent to the SkillClient for fist turn Assert.AreEqual(dialogOptions.BotId, fromBotIdSent); Assert.AreEqual(dialogOptions.Skill.AppId, toBotIdSent); Assert.AreEqual(dialogOptions.Skill.SkillEndpoint.ToString(), toUriSent.ToString()); Assert.AreEqual(activityToSend.Name, activitySent.Name); Assert.AreEqual(DeliveryModes.ExpectReplies, activitySent.DeliveryMode); Assert.AreEqual(DialogTurnStatus.Waiting, client.DialogTurnResult.Status); // Send a second message to continue the dialog await client.SendActivityAsync <Activity>("Second message"); // Assert results for second turn Assert.AreEqual("Second message", activitySent.Text); Assert.AreEqual(DialogTurnStatus.Waiting, client.DialogTurnResult.Status); // Send EndOfConversation to the dialog await client.SendActivityAsync <IEndOfConversationActivity>((Activity)Activity.CreateEndOfConversationActivity()); // Assert we are done. Assert.AreEqual(DialogTurnStatus.Complete, client.DialogTurnResult.Status); }
public async Task ShouldBeAbleToGetHelp(string utterance, string response, string cancelUtterance) { var sut = new TestCancelAndHelpDialog(); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: _middlewares); var reply = await testClient.SendActivityAsync <IMessageActivity>(utterance); Assert.Equal(response, reply.Text); Assert.Equal(DialogTurnStatus.Waiting, testClient.DialogTurnResult.Status); reply = await testClient.SendActivityAsync <IMessageActivity>(cancelUtterance); Assert.Equal("Show Help...", reply.Text); Assert.Equal(DialogTurnStatus.Waiting, testClient.DialogTurnResult.Status); }
public async Task DialogFlowUseCases(TestDataObject testData) { // Arrange var bookingTestData = testData.GetObject <GetBookingDetailsDialogTestCase>(); var sut = new GetBookingDetailsDialog(); var testClient = new DialogTestClient(Channels.Test, sut, bookingTestData.InitialBookingDetails, new[] { new XUnitOutputMiddleware(Output) }); // Act/Assert Output.WriteLine($"Test Case: {bookingTestData.Name}"); for (var i = 0; i < bookingTestData.UtterancesAndReplies.GetLength(0); i++) { var reply = await testClient.SendActivityAsync <IMessageActivity>(bookingTestData.UtterancesAndReplies[i, 0]); Assert.Equal(bookingTestData.UtterancesAndReplies[i, 1], reply?.Text); } if (testClient.DialogTurnResult.Status == DialogTurnStatus.Cancelled) { Assert.Null(testClient.DialogTurnResult.Result); } else { var bookingResults = (BookingDetails)testClient.DialogTurnResult.Result; Assert.Equal(bookingTestData.ExpectedBookingDetails.Origin, bookingResults.Origin); Assert.Equal(bookingTestData.ExpectedBookingDetails.Destination, bookingResults.Destination); Assert.Equal(bookingTestData.ExpectedBookingDetails.TravelDate, bookingResults.TravelDate); } }
public async Task DialogFlowUseCases(TestDataObject testData) { // Arrange var bookingTestData = testData.GetObject <BookingDialogTestCase>(); var sut = new BookingDialog(); var testClient = new DialogTestClient(Channels.Test, sut, bookingTestData.InitialBookingDetails, _middlewares); // Execute the test case Output.WriteLine($"Test Case: {bookingTestData.Name}"); for (var i = 0; i < bookingTestData.UtterancesAndReplies.GetLength(0); i++) { IMessageActivity reply; if (bookingTestData.UtterancesAndReplies[i, 0] != "") { reply = await testClient.SendActivityAsync <IMessageActivity>(bookingTestData.UtterancesAndReplies[i, 0]); } else { reply = testClient.GetNextReply <IMessageActivity>(); } Assert.Equal(bookingTestData.UtterancesAndReplies[i, 1], reply?.Text); } var bookingResults = (BookingDetails)testClient.DialogTurnResult.Result; Assert.Equal(bookingTestData.ExpectedBookingDetails?.Origin, bookingResults?.Origin); Assert.Equal(bookingTestData.ExpectedBookingDetails?.Destination, bookingResults?.Destination); Assert.Equal(bookingTestData.ExpectedBookingDetails?.TravelDate, bookingResults?.TravelDate); }
public async Task DialogFlowUseCases(TestDataObject testData) { // Arrange var bookingTestData = testData.GetObject <BookingDialogTestCase>(); var mockFlightBookingService = new Mock <IFlightBookingService>(); mockFlightBookingService .Setup(x => x.BookFlight(It.IsAny <BookingDetails>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(bookingTestData.FlightBookingServiceResult)); var mockGetBookingDetailsDialog = SimpleMockFactory.CreateMockDialog <GetBookingDetailsDialog>(bookingTestData.GetBookingDetailsDialogResult).Object; var sut = new BookingDialog(mockGetBookingDetailsDialog, mockFlightBookingService.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: _middlewares); // Act/Assert Output.WriteLine($"Test Case: {bookingTestData.Name}"); for (var i = 0; i < bookingTestData.UtterancesAndReplies.GetLength(0); i++) { var utterance = bookingTestData.UtterancesAndReplies[i, 0]; // Send the activity and receive the first reply or just pull the next // activity from the queue if there's nothing to send var reply = !string.IsNullOrEmpty(utterance) ? await testClient.SendActivityAsync <IMessageActivity>(utterance) : testClient.GetNextReply <IMessageActivity>(); Assert.Equal(bookingTestData.UtterancesAndReplies[i, 1], reply.Text); } Assert.Equal(bookingTestData.ExpectedDialogResult.Status, testClient.DialogTurnResult.Status); }
public async Task ShouldNotInterceptOAuthCardsForTokenException() { var connectionName = "connectionName"; var firstResponse = new ExpectedReplies(new List <Activity> { CreateOAuthCardAttachmentActivity("https://test") }); var mockSkillClient = new Mock <BotFrameworkClient>(); mockSkillClient .Setup(x => x.PostActivityAsync <ExpectedReplies>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Uri>(), It.IsAny <Uri>(), It.IsAny <string>(), It.IsAny <Activity>(), It.IsAny <CancellationToken>())) .Returns(Task.FromResult(new InvokeResponse <ExpectedReplies> { Status = 200, Body = firstResponse })); var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient, connectionName); var sut = new SkillDialog(dialogOptions); var activityToSend = CreateSendActivity(); var testAdapter = new TestAdapter(Channels.Test) .Use(new AutoSaveStateMiddleware(conversationState)); var initialDialogOptions = new BeginSkillDialogOptions { Activity = activityToSend }; var client = new DialogTestClient(testAdapter, sut, initialDialogOptions, conversationState: conversationState); testAdapter.ThrowOnExchangeRequest(connectionName, Channels.Test, "user1", "https://test"); var finalActivity = await client.SendActivityAsync <IMessageActivity>("irrelevant"); Assert.IsNotNull(finalActivity); Assert.IsTrue(finalActivity.Attachments.Count == 1); }
public async Task ShowsMessageIfLuisNotConfiguredAndCallsBookDialogDirectly() { // Arrange var mockRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <FlightBookingRecognizer>(null, constructorParams: new Mock <IConfiguration>().Object); mockRecognizer.Setup(x => x.IsConfigured).Returns(false); // Create a specialized mock for BookingDialog that displays a dummy TextPrompt. // The dummy prompt is used to prevent the MainDialog waterfall from moving to the next step // and assert that the dialog was called. var mockDialog = new Mock <BookingDialog>(); mockDialog .Setup(x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(async(DialogContext dialogContext, object options, CancellationToken cancellationToken) => { dialogContext.Dialogs.Add(new TextPrompt("MockDialog")); return(await dialogContext.PromptAsync("MockDialog", new PromptOptions() { Prompt = MessageFactory.Text($"{nameof(BookingDialog)} mock invoked") }, cancellationToken)); }); var sut = new MainDialog(mockRecognizer.Object, mockDialog.Object, _mockLogger.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the appsettings.json file.", reply.Text); reply = testClient.GetNextReply <IMessageActivity>(); Assert.Equal("BookingDialog mock invoked", reply.Text); }
public async Task CancelDialogSendsEoC() { Activity activitySent = null; // Callback to capture the parameters sent to the skill void CaptureAction(string fromBotId, string toBotId, Uri toUri, Uri serviceUrl, string conversationId, Activity activity, CancellationToken cancellationToken) { // Capture values sent to the skill so we can assert the right parameters were used. activitySent = activity; } // Create a mock skill client to intercept calls and capture what is sent. var mockSkillClient = CreateMockSkillClient(CaptureAction); // Use Memory for conversation state var conversationState = new ConversationState(new MemoryStorage()); var dialogOptions = CreateSkillDialogOptions(conversationState, mockSkillClient); // Create the SkillDialogInstance and the activity to send. var sut = new SkillDialog(dialogOptions); var activityToSend = (Activity)Activity.CreateMessageActivity(); activityToSend.Text = Guid.NewGuid().ToString(); var client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions { Activity = activityToSend }, conversationState: conversationState); // Send something to the dialog to start it await client.SendActivityAsync <IMessageActivity>("irrelevant"); // Cancel the dialog so it sends an EoC to the skill await client.DialogContext.CancelAllDialogsAsync(CancellationToken.None); Assert.AreEqual(ActivityTypes.EndOfConversation, activitySent.Type); }
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); }
public async Task TaskSelector(string utterance, string intent, string invokedDialogResponse, string taskConfirmationMessage) { // Create a mock recognizer that returns the expected intent. var mockLuisRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <FlightBookingRecognizer, FlightBooking>( new FlightBooking { Intents = new Dictionary <FlightBooking.Intent, IntentScore> { { Enum.Parse <FlightBooking.Intent>(intent), new IntentScore() { Score = 1 } }, }, Entities = new FlightBooking._Entities(), }, new Mock <IConfiguration>().Object); mockLuisRecognizer.Setup(x => x.IsConfigured).Returns(true); var sut = new MainDialog(mockLuisRecognizer.Object, _mockBookingDialog, _mockLogger.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Execute the test case Output.WriteLine($"Test Case: {intent}"); var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy"); Assert.Equal($"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>(utterance); Assert.Equal(invokedDialogResponse, reply.Text); // The Booking dialog displays an additional confirmation message, assert that it is what we expect. if (!string.IsNullOrEmpty(taskConfirmationMessage)) { reply = testClient.GetNextReply <IMessageActivity>(); Assert.StartsWith(taskConfirmationMessage, reply.Text); } // Validate that the MainDialog starts over once the task is completed. reply = testClient.GetNextReply <IMessageActivity>(); Assert.Equal("What else can I do for you?", reply.Text); }
public async Task ShowsAnswerFromQnAMaker() { var mockTemplateManager = SimpleMockFactory.CreateMockTemplateManager("mock template message"); var azureDialog = new AzureDialog(_configurationLazy.Value, _telemetryClient, mockTemplateManager.Object); var testClient = new DialogTestClient(Channels.Test, azureDialog, middlewares: new[] { new XUnitDialogTestLogger(Output) }); var reply = await testClient.SendActivityAsync <IMessageActivity>("azure database for mysql"); Assert.NotNull(reply); }
public async Task Test_ValidateCheckoutNoDiscountDialog() { userState = new UserState(new MemoryStorage()); var checkoutDialog = new CheckoutDialog(userState); //var mainDialog = new MainDialog(checkoutDialog); var testClient = new DialogTestClient(Channels.Msteams, checkoutDialog); var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.AreEqual("Do you have membership with us?", ((HeroCard)reply.Attachments[0].Content).Text); reply = await testClient.SendActivityAsync <IMessageActivity>("no"); Assert.AreEqual("Do you want to shop and check some offers today?", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>("Yes"); Assert.AreEqual("No discount for you at this moment.", ((HeroCard)reply.Attachments[0].Content).Text); }
public async Task ShowsPromptIfLuisIsConfigured() { // Arrange var sut = new MainDialog(_mockLogger.Object, SimpleMockFactory.CreateMockLuisRecognizer <IRecognizer>(null).Object, _mockBookingDialog); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitOutputMiddleware(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("What can I help you with today?", reply.Text); }
public async Task ShouldExposeDialogTurnResults(DialogTurnStatus turnStatus, object turnResult) { _mockDialog .Setup(x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(new DialogTurnResult(turnStatus, turnResult))); var sut = new DialogTestClient(_mockDialog.Object); await sut.SendActivityAsync <IMessageActivity>("test"); Assert.Equal(turnStatus, sut.DialogTurnResult.Status); Assert.Equal(turnResult, sut.DialogTurnResult.Result); }
public async Task TaskSelector(string utterance, string intent, string invokedDialogResponse, string taskConfirmationMessage) { // Create a mock recognizer that returns the expected intent. var mockLuisRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <FlightBookingRecognizer, FlightBooking>( new FlightBooking { Intents = new Dictionary <FlightBooking.Intent, IntentScore> { { Enum.Parse <FlightBooking.Intent>(intent), new IntentScore() { Score = 1 } }, }, Entities = new FlightBooking._Entities(), }, new Mock <IConfiguration>().Object); mockLuisRecognizer.Setup(x => x.IsConfigured).Returns(true); var sut = new MainDialog(mockLuisRecognizer.Object, _mockBookingDialog, _mockLogger.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Execute the test case Output.WriteLine($"Test Case: {intent}"); var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("Are you experiencing any of the following: severe difficulty breathing, chest pain, very hard time waking up, confusion, lost consciousness?", reply.Text); reply = await testClient.SendActivityAsync <IMessageActivity>(utterance); Assert.Equal("Please call 911 or go directly to your nearest emergency department.", reply.Text); // Validate that the MainDialog starts over once the task is completed. reply = testClient.GetNextReply <IMessageActivity>(); //Assert.Equal("What else can I do for you?", reply.Text); }
public async Task BeginDialogOptionsValidation() { var dialogOptions = new SkillDialogOptions(); var sut = new SkillDialog(dialogOptions); var client = new DialogTestClient(Channels.Test, sut); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant"), "null options should fail"); client = new DialogTestClient(Channels.Test, sut, new Dictionary <string, string>()); await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant"), "options should be of type DialogArgs"); client = new DialogTestClient(Channels.Test, sut, new BeginSkillDialogOptions()); await Assert.ThrowsExceptionAsync <ArgumentNullException>(async() => await client.SendActivityAsync <IMessageActivity>("irrelevant"), "Activity in DialogArgs should be set"); }
public async Task Test_CheckoutWithDiscountDialog() { userState = new UserState(new MemoryStorage()); var checkoutDialog = new CheckoutDialog(userState); //var mainDialog= new MainDialog(checkoutDialog); var testClient = new DialogTestClient(Channels.Msteams, checkoutDialog); var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.AreEqual("Do you have membership with us?", ((HeroCard)reply.Attachments[0].Content).Text); reply = await testClient.SendActivityAsync <IMessageActivity>("yes"); Assert.AreEqual("Great! we have special offers for you.", reply.Text); reply = testClient.GetNextReply <IMessageActivity>(); Assert.AreEqual("Do you want to shop and check some offers today?", ((HeroCard)reply.Attachments[0].Content).Text); reply = await testClient.SendActivityAsync <IMessageActivity>("Yes"); Assert.AreEqual("You will receive a coupon shortly.", ((HeroCard)reply.Attachments[0].Content).Text); }
public async Task ShowsPromptIfLuisIsConfigured() { // Arrange var mockRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <FlightBookingRecognizer>(null, constructorParams: new Mock <IConfiguration>().Object); mockRecognizer.Setup(x => x.IsConfigured).Returns(true); var sut = new MainDialog(mockRecognizer.Object, _mockBookingDialog, _mockLogger.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("What can I help you with today?", reply.Text); }
public async Task ShowsMessageIfLuisNotConfigured() { // Arrange var sut = new MainDialog(_mockLogger.Object, null, _mockBookingDialog); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitOutputMiddleware(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); Assert.Equal("NOTE: LUIS is not configured. To enable all capabilities, add 'LuisAppId', 'LuisAPIKey' and 'LuisAPIHostName' to the appsettings.json file.", reply.Text); reply = testClient.GetNextReply <IMessageActivity>(); Assert.Equal("What can I help you with today?", reply.Text); }
public async Task ShouldLogIncomingAndOutgoingMessageActivities(string utterance, string textReply, string speakReply, string inputHint) { var mockOutput = new MockTestOutputHelper(); var sut = new XUnitOutputMiddleware(mockOutput); var testClient = new DialogTestClient(Channels.Test, new EchoDialog(textReply, speakReply, inputHint), null, new List <IMiddleware> { sut }); await testClient.SendActivityAsync <IMessageActivity>(utterance); Assert.Equal("\r\nUser: Hi", mockOutput.Output[0]); Assert.StartsWith(" -> ts: ", mockOutput.Output[1]); Assert.StartsWith($"\r\nBot: Text={textReply}\r\n Speak={speakReply}\r\n InputHint={inputHint}", mockOutput.Output[2]); Assert.StartsWith(" -> ts: ", mockOutput.Output[3]); Assert.Contains("elapsed", mockOutput.Output[3]); }
public async Task ShowsPromptIfLuisIsConfigured() { // Arrange var mockRecognizer = SimpleMockFactory.CreateMockLuisRecognizer <FlightBookingRecognizer>(null, constructorParams: new Mock <IConfiguration>().Object); mockRecognizer.Setup(x => x.IsConfigured).Returns(true); var sut = new MainDialog(mockRecognizer.Object, _mockBookingDialog, _mockLogger.Object); var testClient = new DialogTestClient(Channels.Test, sut, middlewares: new[] { new XUnitDialogTestLogger(Output) }); // Act/Assert var reply = await testClient.SendActivityAsync <IMessageActivity>("hi"); var weekLaterDate = DateTime.Now.AddDays(7).ToString("MMMM d, yyyy"); Assert.Equal($"What can I help you with today?\nSay something like \"Book a flight from Paris to Berlin on {weekLaterDate}\"", reply.Text); }
public async Task ShouldUseCustomCallback() { var callbackCalled = false; async Task TestCallback(ITurnContext context, CancellationToken token) { callbackCalled = true; await context.SendActivityAsync("test reply from the bot", cancellationToken : token); } var sut = new DialogTestClient(Channels.Test, _mockDialog.Object, callback: TestCallback); await sut.SendActivityAsync <IActivity>("test message"); Assert.True(callbackCalled); }
public async Task ShouldExposeDialogContext() { _mockDialog .Setup(x => x.BeginDialogAsync(It.IsAny <DialogContext>(), It.IsAny <object>(), It.IsAny <CancellationToken>())) .Returns(() => Task.FromResult(new DialogTurnResult(DialogTurnStatus.Waiting, "waiting result"))); var sut = new DialogTestClient(Channels.Test, _mockDialog.Object); // Should be null before the dialog is started Assert.Null(sut.DialogContext); await sut.SendActivityAsync <IMessageActivity>("test"); // Should not be null once the client has been started and should have the test dialog in the stack. Assert.NotNull(sut.DialogContext); Assert.Single(sut.DialogContext.Stack); Assert.Equal(_mockDialog.Object.Id, sut.DialogContext.Stack[0].Id); }
public async Task ShouldUseCustomAdapter() { var customAdapter = new Mock <TestAdapter>(Channels.Directline, false) { CallBase = true, }; var sut = new DialogTestClient(customAdapter.Object, _mockDialog.Object); await sut.SendActivityAsync <IActivity>("test message"); customAdapter.Verify( x => x.SendTextToBotAsync( It.Is <string>(s => s == "test message"), It.IsAny <BotCallbackHandler>(), It.IsAny <CancellationToken>()), Times.Once); }
public async Task ShouldBeAbleToCancelAtAnyTime(TestDataObject testData) { // Arrange var bookingTestData = testData.GetObject <BookingDialogTestCase>(); var sut = new BookingDialog(); var testClient = new DialogTestClient(Channels.Test, sut, bookingTestData.InitialBookingDetails, _middlewares); // Execute the test case Output.WriteLine($"Test Case: {bookingTestData.Name}"); for (var i = 0; i < bookingTestData.UtterancesAndReplies.GetLength(0); i++) { var reply = await testClient.SendActivityAsync <IMessageActivity>(bookingTestData.UtterancesAndReplies[i, 0]); Assert.Equal(bookingTestData.UtterancesAndReplies[i, 1], reply.Text); } Assert.Equal(DialogTurnStatus.Complete, testClient.DialogTurnResult.Status); Assert.Null(testClient.DialogTurnResult.Result); }
public async Task ShouldLogOtherIncomingAndOutgoingActivitiesAsRawJson(string activityType) { var mockOutput = new MockTestOutputHelper(); var sut = new XUnitOutputMiddleware(mockOutput); var testClient = new DialogTestClient(Channels.Test, new EchoDialog(), null, new List <IMiddleware> { sut }); var activity = new Activity(activityType); await testClient.SendActivityAsync <IActivity>(activity); Assert.Equal($"\r\nUser: Activity = ActivityTypes.{activityType}", mockOutput.Output[0]); Assert.StartsWith(activityType, JsonConvert.DeserializeObject <Activity>(mockOutput.Output[1]).Type); Assert.StartsWith(" -> ts: ", mockOutput.Output[2]); Assert.Equal($"\r\nBot: Activity = ActivityTypes.{activityType}", mockOutput.Output[3]); Assert.StartsWith(activityType, JsonConvert.DeserializeObject <Activity>(mockOutput.Output[4]).Type); Assert.StartsWith(" -> ts: ", mockOutput.Output[5]); Assert.Contains("elapsed", mockOutput.Output[5]); }