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);
        }
Esempio n. 2
0
        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 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 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);
        }
Esempio n. 5
0
        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 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 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 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);
        }