public void Should_be_a_value_type()
        {
            var firstInstance  = TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable("trainId42");
            var secondInstance = TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable("trainId42");

            Check.That(firstInstance).IsEqualTo(secondInstance);
        }
        public void Should_return_70_percent_of_OverallTrainCapacity_as_MaxReservableSeatsFollowingThePolicy()
        {
            var train = TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable("trainId42");

            Check.That(train.OverallTrainCapacity).IsEqualTo(10);
            Check.That(train.MaxReservableSeatsFollowingThePolicy).IsEqualTo(7);
        }
        public void Should_be_able_to_reserve_70_percent_of_overall_train_capacity()
        {
            var train = TrainProviderHelper.GetTrainWith1CoachAnd10SeatsAvailable("trainId42");

            Check.That(train.OverallTrainCapacity).IsEqualTo(10);
            var option = train.FindReservationOption(7);

            Check.That(option.IsFullfiled).IsTrue();
        }
        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);
        }