Exemple #1
0
        public void ShouldMoveUpOneLetter_Test()
        {
            ////Arrange
            var reservationService = new ReservationNumberService();

            ///Act
            for (int i = 0; i < 999; ++i)
            {
                reservationService.Next();
            }
            var result = reservationService.Next();

            ///Assert
            Assert.Equal("AAB001", result);
        }
        public async Task <ReservationResponse> CreateReservationAsync(ReservationRequest reservation)
        {
            var newReservationToCreate = _mapper.Map <ReservationEntity>(reservation);

            //TODO: Complete the mapping from  CreateReservationRequest to ReservationEntity;
            //Create function in Mapping folder
            foreach (var flight in reservation.flights)
            {
                foreach (var item in flight.passengers)
                {
                    ReservationDetailsEntity detailsItem = new ReservationDetailsEntity();
                    detailsItem.FlightKey    = flight.key; detailsItem.Name = item.name;
                    detailsItem.NumberOfBags = item.bags;
                    detailsItem.Seat         = item.seat;
                    newReservationToCreate.ReservationDetails.Add(detailsItem);
                }
            }
            if (newReservationToCreate != null)
            {
                if (IsValidReservation(newReservationToCreate))
                {
                    _reservationNumber.Next();
                    newReservationToCreate.ReservationNumber = _reservationNumber.Value;
                    newReservationToCreate.ReservationDetails.ForEach(c => c.ReservationNumber = _reservationNumber.Value);

                    await _context.Reservations.AddAsync(newReservationToCreate);

                    await _context.SaveChangesAsync();

                    return(new ReservationResponse
                    {
                        reservationNumber = _reservationNumber.Value
                    });
                }
                else
                {
                    throw new InvalidOperationException("Could not create booking. This reservation doesn't follow the below criteria:\n " +
                                                        "There is a maximum of 50 bags per flight in total for all the passengers." +
                                                        "Each passenger can have a maximum of 5 bags per flight. " +
                                                        "There are 50 seats available per flight." +
                                                        "Flight doesn't exit");
                }
            }
            return(null);
        }