public void Should_ideally_left_70_percent_of_every_coach_available()
        {
            // setup mocks
            var firstBookingId  = "75bcd15";
            var secondBookingId = "9904fgG6";

            var bookingReferenceProvider = ConfigureABookingReferenceProviderMock(new[] { firstBookingId, secondBookingId });

            var trainId           = "express_2000";
            var trainDataProvider = new TrainDataServiceMock(TrainProviderHelper.GetTrainWith2CoachesAnd2IndividualSeatsAvailable(trainId));

            // act
            // First reservation
            var ticketOffice     = new TicketOffice(bookingReferenceProvider, trainDataProvider);
            var firstReservation = ticketOffice.MakeReservation(new ReservationRequest(trainId, 1));

            // Must be located in the remaining seat of 1st coach
            Check.That(firstReservation.TrainId).IsEqualTo(trainId);
            Check.That(firstReservation.BookingReference.Value).IsEqualTo(firstBookingId);
            Check.That(firstReservation.Seats).ContainsExactly(new Seat("A", 7));

            // Second reservation
            var secondReservation = ticketOffice.MakeReservation(new ReservationRequest(trainId, 1));

            // Must be located in the remaining seat of 1st coach
            Check.That(secondReservation.TrainId).IsEqualTo(trainId);
            Check.That(secondReservation.BookingReference.Value).IsEqualTo(secondBookingId);
            Check.That(secondReservation.Seats).ContainsExactly(new Seat("B", 7));
        }
        public void Reserve1SeatsInEmptyTrainReturnSuccessReservation()
        {
            Reservation expected = Reservation.Of("empty_train", "75bcd15", new List <Seat>()
            {
                Seat.Of("A", 1, "")
            });
            Reservation result = _ticketOffice.MakeReservation(ReservationRequest.Of("empty_train", 1));

            Assert.AreEqual(expected, result);
        }
        public void Should_fail_to_reserve_when_asking_more_seats_than_the_70_percent_limit()
        {
            // setup mocks
            var expectedBookingId        = "75bcd15";
            var bookingReferenceProvider = ConfigureABookingReferenceProviderMock(expectedBookingId);

            var trainId           = "express_2000";
            var trainDataProvider = ConfigureATrainDataProviderMock(trainId, TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable(trainId));

            // act
            var ticketOffice = new TicketOffice(bookingReferenceProvider, trainDataProvider);
            var reservation  = ticketOffice.MakeReservation(new ReservationRequest(trainId, 9));

            Check.That(reservation.TrainId).IsEqualTo(trainId);
            Check.That(reservation.BookingReference.Value).IsEmpty();
            Check.That(reservation.Seats).IsEmpty();
        }
        public void Should_reserve_seats_when_unreserved_seats_are_available()
        {
            // setup mocks
            var expectedBookingId        = "75bcd15";
            var bookingReferenceProvider = ConfigureABookingReferenceProviderMock(expectedBookingId);

            var trainId           = "express_2000";
            var trainDataProvider = ConfigureATrainDataProviderMock(trainId, TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable(trainId));

            // act
            var ticketOffice = new TicketOffice(bookingReferenceProvider, trainDataProvider);
            var reservation  = ticketOffice.MakeReservation(new ReservationRequest(trainId, 3));

            Check.That(reservation.TrainId).IsEqualTo(trainId);
            Check.That(reservation.BookingReference.Value).IsEqualTo(expectedBookingId);
            Check.That(reservation.Seats).ContainsExactly(new Seat("A", 1), new Seat("A", 2), new Seat("A", 3));
        }
        public void Should_mark_seats_as_reserved_once_reserved()
        {
            // setup mocks
            var expectedBookingId        = "75bcd15";
            var bookingReferenceProvider = ConfigureABookingReferenceProviderMock(expectedBookingId);

            var trainId           = "express_2000";
            var trainDataProvider = ConfigureATrainDataProviderMock(trainId, TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable(trainId));

            // act
            var ticketOffice = new TicketOffice(bookingReferenceProvider, trainDataProvider);
            var reservation  = ticketOffice.MakeReservation(new ReservationRequest(trainId, 1));

            Check.That(reservation.TrainId).IsEqualTo(trainId);
            Check.That(reservation.BookingReference.Value).IsEqualTo(expectedBookingId);
            Check.That(reservation.Seats).ContainsExactly(new Seat("A", 1));

            // Check that the train data mock has been called to persist this reservation
            trainDataProvider.Received().MarkSeatsAsReserved(trainId, reservation.BookingReference, reservation.Seats);
        }
        public void Should_reserve_seats_in_the_same_coach()
        {
            // setup mocks
            var firstBookingId  = "75bcd15";
            var secondBookingId = "9904fgG6";

            var bookingReferenceProvider = ConfigureABookingReferenceProviderMock(new[] { firstBookingId, secondBookingId });

            var trainId           = "express_2000";
            var trainDataProvider = new TrainDataServiceMock(TrainProviderHelper.GetTrainWith2CoachesOf10And1Then2SeatsAvailable(trainId));

            // act
            var ticketOffice     = new TicketOffice(bookingReferenceProvider, trainDataProvider);
            var firstReservation = ticketOffice.MakeReservation(new ReservationRequest(trainId, 2));

            // Must be located in the remaining seats of the 2nd coach
            Check.That(firstReservation.TrainId).IsEqualTo(trainId);
            Check.That(firstReservation.BookingReference.Value).IsEqualTo(firstBookingId);
            Check.That(firstReservation.Seats).ContainsExactly(new Seat("B", 6), new Seat("B", 7));
        }