Esempio n. 1
0
        public void Not_reserve_seats_when_it_exceed_max_capacity_threshold()
        {
            const int seatsRequestedCount    = 3;
            var       bookingReferenceClient = new BookingReferenceClientStub(BookingReference);
            var       service = BuildTicketOfficeService(TrainTopologies.With_10_seats_and_6_already_reserved(), bookingReferenceClient);

            var reservation = service.MakeReservation(new ReservationRequestDto(TrainId, seatsRequestedCount));

            Assert.Equal("{\"train_id\": \"" + TrainId + "\", \"booking_reference\": \"\", \"seats\": []}", reservation);
            Assert.False(bookingReferenceClient.Booked);
        }
Esempio n. 2
0
        public void Reserve_all_seats_in_the_same_coach()
        {
            const int seatsRequestedCount    = 2;
            var       bookingReferenceClient = new BookingReferenceClientStub(BookingReference);
            var       trainDataService       = BuildTicketOfficeService(TrainTopologies.With_2_coaches_and_9_seats_already_reserved_in_the_first_coach(), bookingReferenceClient);

            var reservation = trainDataService.MakeReservation(new ReservationRequestDto(TrainId, seatsRequestedCount));

            Assert.Equal("{\"train_id\": \"" + TrainId + "\", \"booking_reference\": \"" + BookingReference + "\", \"seats\": [\"1B\", \"2B\"]}", reservation);
            Assert.True(bookingReferenceClient.Booked);
        }
Esempio n. 3
0
        public void Cannot_Reserve_When_Train_Is_Not_Full_But_Not_Coach_Is_Available()
        {
            const int seatsRequestedCount    = 2;
            var       bookingReferenceClient = new BookingReferenceClientStub(BookingReference);
            var       trainDataService       = BuildTicketOfficeService(TrainTopologies.With_10_coaches_half_available(), bookingReferenceClient);

            var reservation = trainDataService.MakeReservation(new ReservationRequestDto(TrainId, seatsRequestedCount));

            Assert.Equal("{\"train_id\": \"" + TrainId + "\", \"booking_reference\": \"\", \"seats\": []}", reservation);
            Assert.False(bookingReferenceClient.Booked);
        }
Esempio n. 4
0
        public void Reserve_seats_when_train_is_empty()
        {
            const int seatsRequestedCount    = 3;
            var       bookingReferenceClient = new BookingReferenceClientStub(BookingReference);
            var       service = BuildTicketOfficeService(TrainTopologies.With_10_available_seats(), bookingReferenceClient);

            var reservation = service.MakeReservation(new ReservationRequestDto(TrainId, seatsRequestedCount));

            Assert.Equal("{\"train_id\": \"" + TrainId + "\", \"booking_reference\": \"" + BookingReference + "\", \"seats\": [\"1A\", \"2A\", \"3A\"]}", reservation);
            Assert.Equal(TrainId, bookingReferenceClient.TrainIdBooked);
            Assert.Equal(BookingReference, bookingReferenceClient.ReferenceBooked);
            Assert.Equal(3, bookingReferenceClient.SeatsBooked.Count);
            Assert.Equal(new Seat("A", 1), bookingReferenceClient.SeatsBooked[0]);
            Assert.Equal(new Seat("A", 2), bookingReferenceClient.SeatsBooked[1]);
            Assert.Equal(new Seat("A", 3), bookingReferenceClient.SeatsBooked[2]);
        }