コード例 #1
0
        public async Task CheckInTest()
        {
            BookingItem bookingItem = CreateBookingItem();

            var saga = new ProcessBookingSaga()
            {
                Data = new ProcessBookingSaga.BookingData()
                {
                    BookingNumber = 0, ClientId = "JonSnowClientId", BookingItem = bookingItem
                }
            };
            var context = new TestableMessageHandlerContext();

            CheckIn checkIn = new CheckIn();

            checkIn.BookingNumber = 0;
            checkIn.ClientId      = "JonSnowClientId";

            await saga.Handle(checkIn, context)
            .ConfigureAwait(false);

            var checkedInEvent = (CheckedIn)context.PublishedMessages[0].Message;

            Assert.AreEqual(0, checkedInEvent.BookingNumber);
            Assert.AreEqual(Constants.CheckedIn, saga.Data.BookingItem.Status);
        }
コード例 #2
0
        public async Task CancelBookingTest()
        {
            BookingItem bookingItem = CreateBookingItem();
            var         saga        = new ProcessBookingSaga()
            {
                Data = new ProcessBookingSaga.BookingData()
                {
                    BookingNumber = 0, ClientId = "JonSnowClientId", BookingItem = bookingItem
                }
            };
            var context = new TestableMessageHandlerContext();

            CancelBooking cancelBooking = new CancelBooking();

            cancelBooking.BookingNumber = 0;
            cancelBooking.ClientId      = "JonSnowClientId";

            await saga.Handle(cancelBooking, context)
            .ConfigureAwait(false);

            var bookingCanceled = (BookingCancelled)context.PublishedMessages[0].Message;

            Assert.AreEqual(0, bookingCanceled.BookingNumber);
            Assert.AreEqual(Constants.Cancelled, saga.Data.BookingItem.Status);
        }
コード例 #3
0
        public async Task CannotCancelCheckedOutBookingTest()
        {
            BookingItem bookingItem = CreateBookingItem();

            bookingItem.Status = Constants.CheckedOut;

            var saga = new ProcessBookingSaga()
            {
                Data = new ProcessBookingSaga.BookingData()
                {
                    BookingNumber = 0, ClientId = "JonSnowClientId", BookingItem = bookingItem
                }
            };
            var context = new TestableMessageHandlerContext();

            CancelBooking cancelBooking = new CancelBooking();

            cancelBooking.BookingNumber = 0;
            cancelBooking.ClientId      = "JonSnowClientId";

            await saga.Handle(cancelBooking, context)
            .ConfigureAwait(false);

            Assert.AreEqual(0, context.PublishedMessages.Length);
        }
コード例 #4
0
        public async Task SubmitBookingTest()
        {
            var saga = new ProcessBookingSaga()
            {
                Data = new ProcessBookingSaga.BookingData()
            };
            var context = new TestableMessageHandlerContext();

            SubmitBooking submitBooking = new SubmitBooking();

            submitBooking.BookingItem                  = new BookingItem();
            submitBooking.BookingItem.Name             = "Jon snow";
            submitBooking.BookingItem.Phone            = "13324124";
            submitBooking.BookingItem.Email            = "*****@*****.**";
            submitBooking.BookingItem.CheckInDatetime  = DateTime.Now;
            submitBooking.BookingItem.CheckOutDatetime = DateTime.Now;

            await saga.Handle(submitBooking, context)
            .ConfigureAwait(false);

            var bookingPlaced = (BookingPlaced)context.PublishedMessages[0].Message;

            Assert.AreEqual(Constants.Booked, bookingPlaced.BookingItem.Status);
            Assert.AreEqual(Constants.Booked, saga.Data.BookingItem.Status);
        }