示例#1
0
        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);
        }
示例#2
0
        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 void ShouldSerializeAsJson()
        {
            var sut         = new TestDataObject(_testObject);
            var innerObject = sut.GetObject <MyTestDataObject>();

            Assert.Equal(JsonConvert.SerializeObject(_testObject), sut.TestObject);
            Assert.NotSame(_testObject, innerObject);
            Assert.Equal(_testObject.SomeText, innerObject.SomeText);
            Assert.Equal(_testObject.SomeNumber, innerObject.SomeNumber);
        }
        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 DialogFlowTests(TestDataObject testData)
        {
            // Arrange
            var testCaseData = testData.GetObject <DateResolverDialogTestCase>();
            var sut          = new DateResolverDialog();
            var testClient   = new DialogTestClient(Channels.Test, sut, testCaseData.InitialData, new[] { new XUnitDialogTestLogger(Output) });

            // Execute the test case
            Output.WriteLine($"Test Case: {testCaseData.Name}");
            Output.WriteLine($"\r\nDialog Input: {testCaseData.InitialData}");
            for (var i = 0; i < testCaseData.UtterancesAndReplies.GetLength(0); i++)
            {
                var reply = await testClient.SendActivityAsync <IMessageActivity>(testCaseData.UtterancesAndReplies[i, 0]);

                Assert.Equal(testCaseData.UtterancesAndReplies[i, 1], reply?.Text);
            }

            Output.WriteLine($"\r\nDialog result: {testClient.DialogTurnResult.Result}");
            Assert.Equal(testCaseData.ExpectedResult, testClient.DialogTurnResult.Result);
        }