public async Task Should_mark_book_as_available()
        {
            var reservationId = NewId.NextGuid();
            var bookId        = NewId.NextGuid();
            var memberId      = NewId.NextGuid();

            await TestHarness.Bus.Publish <BookAdded>(new
            {
                BookId = bookId,
                Isbn   = "0307969959",
                Title  = "Neuromancer"
            });

            var existsId = await _bookSagaHarness.Exists(bookId, x => x.Available);

            Assert.IsTrue(existsId.HasValue, "Saga did not exist");

            await TestHarness.Bus.Publish <ReservationRequested>(new
            {
                ReservationId = reservationId,
                InVar.Timestamp,
                Duration = TimeSpan.FromDays(2),
                MemberId = memberId,
                BookId   = bookId,
            });

            existsId = await SagaHarness.Exists(reservationId, x => x.Reserved);

            Assert.IsTrue(existsId.HasValue, "Reservation was not reserved");

            existsId = await _bookSagaHarness.Exists(bookId, x => x.Reserved);

            Assert.IsTrue(existsId.HasValue, "Saga did not exist");

            await AdvanceSystemTime(TimeSpan.FromHours(24));

            existsId = await SagaHarness.Exists(reservationId, x => x.Reserved);

            Assert.IsTrue(existsId.HasValue, "Reservation was not still reserved");

            await AdvanceSystemTime(TimeSpan.FromHours(24));

            Guid?notExists = await SagaHarness.NotExists(reservationId);

            Assert.IsFalse(notExists.HasValue);

            existsId = await _bookSagaHarness.Exists(bookId, x => x.Available);

            Assert.IsTrue(existsId.HasValue, "Saga did not exist");
        }
        public async Task The_reservation_should_be_removed()
        {
            var reservationId = NewId.NextGuid();
            var bookId        = NewId.NextGuid();
            var memberId      = NewId.NextGuid();

            await TestHarness.Bus.Publish <BookAdded>(new
            {
                BookId = bookId,
                Isbn   = "0307969959",
                Title  = "Neuromancer"
            });

            var existsId = await _bookSagaHarness.Exists(bookId, x => x.Available);

            Assert.IsTrue(existsId.HasValue, "Saga did not exist");

            await TestHarness.Bus.Publish <ReservationRequested>(new
            {
                ReservationId = reservationId,
                InVar.Timestamp,
                MemberId = memberId,
                BookId   = bookId,
            });

            existsId = await SagaHarness.Exists(reservationId, x => x.Reserved);

            Assert.IsTrue(existsId.HasValue, "Reservation was not reserved");

            existsId = await _bookSagaHarness.Exists(bookId, x => x.Reserved);

            Assert.IsTrue(existsId.HasValue, "Saga did not exist");

            await TestHarness.Bus.Publish <BookCheckedOut>(new
            {
                BookId = bookId,
                InVar.Timestamp
            });

            Guid?notExists = await SagaHarness.NotExists(reservationId);

            Assert.IsFalse(notExists.HasValue);

            existsId = await _bookSagaHarness.Exists(bookId, x => x.CheckedOut);

            Assert.IsTrue(existsId.HasValue, "Book was not checked out");
        }
Beispiel #3
0
        public async Task Should_Mark_Book_As_Available()
        {
            var reservationId = NewId.NextGuid();
            var bookId        = NewId.NextGuid();
            var memberId      = NewId.NextGuid();

            await TestHarness.Bus.Publish <IBookAddedGlobalEvent>(new
            {
                BookId = bookId,
                Isbn   = "0307969959",
                Title  = "Neuromancer"
            });

            (await _bookSagaHarness.Exists(bookId, x => x.Available)).HasValue.Should()
            .BeTrue("Book Saga state machine should be existed at Available State!");

            await TestHarness.Bus.Publish <IReservationRequestedGlobalEvent>(new
            {
                ReservationId = reservationId,
                Timestamp     = InVar.Timestamp,
                MemberId      = memberId,
                BookId        = bookId
            });

            (await SagaHarness.Exists(reservationId, x => x.Reserved)).HasValue.Should()
            .BeTrue("Reservation Saga state machine should be existed at Reserved State!");
            (await _bookSagaHarness.Exists(bookId, x => x.Reserved)).HasValue.Should()
            .BeTrue("Book Saga state machine should be existed at Reserved State!");

            // Turn the clock toward 24 hours
            await AdvanceSystemTime(TimeSpan.FromHours(24));

            (await SagaHarness.NotExists(reservationId)).HasValue.Should().BeFalse(
                "The Reservation state machine should be finalized already cause of reservation expired itself!");
            (await _bookSagaHarness.Exists(bookId, x => x.Available)).HasValue.Should().BeTrue(
                "Book Saga state machine should be existed at Available State cause the reservation was expired!");
        }