コード例 #1
0
        public Reservation MakeReservation(ReservationRequest request)
        {
            var train = _trainProvider.GetTrain(request.TrainId);

            if (OverCapcity(request, train))
                return Reservation.Empty;
            if (!train.Coaches.Any(c => c.Available >= request.SeatCount))
                return Reservation.Empty;

            return new Reservation(request.TrainId, Guid.NewGuid().ToString(), new List<Seat>() { new Seat(null, 0)  });
        }
コード例 #2
0
        public void Test_MakeReservation_Returns_Valid_Reservation_When_Train_Has_Capacity()
        {
            var trainProvider = new TrainProviderBuilder()
                .WithCoach(new CoachBuilder().WithCapacity(100).WithBooked(50).Build()).Build();

            var ticketOffice = new TicketOffice(trainProvider);
            var request = new ReservationRequest("express_2000", 1);

            var result = ticketOffice.MakeReservation(request);
            result.BookingId.Should().NotBeNullOrEmpty();
            result.TrainId.Should().Be("express_2000");
            result.Seats.Should().HaveCount(1);
        }
コード例 #3
0
 private static bool OverCapcity(ReservationRequest request, Train train)
 {
     return (double) (train.Booked + request.SeatCount)/train.TotalSeats >= 0.7d;
 }