public void BookTicket_Test_2() { BookTicketRequest ticketRequest = new BookTicketRequest() { SeatIDs = new System.Collections.Generic.List <long>() { 1, 2 }, ShowID = 7 }; var ticket = ticketService.BookTicket(ticketRequest); Assert.IsNull(ticket); }
[ExpectedException(typeof(AppValidationException))]//Asset exception attribute public void BookTicket_Test_3() { BookTicketRequest ticketRequest = new BookTicketRequest() { SeatIDs = new System.Collections.Generic.List <long>() { 1 }, ShowID = 1 }; ticketService.BookTicket(ticketRequest); ticketRequest.SeatIDs.Add(1); ticketService.BookTicket(ticketRequest); //Asserts exception : specified as attribute }
public void BookTicket_Test_1() { BookTicketRequest ticketRequest = new BookTicketRequest() { SeatIDs = new System.Collections.Generic.List <long>() { 1, 2 }, ShowID = 1 }; var ticket = ticketService.BookTicket(ticketRequest); Assert.IsNotNull(ticket); Assert.AreEqual(ticket.UserID, 1); Assert.AreEqual(ticket.Price, 123 * 2); Assert.AreEqual(ticket.ReservedSeats.Count, 2); }
public Ticket BookTicket(BookTicketRequest bookTicketRequest) { Ticket ticket = null; var reservedSeatsForTheShow = _searchService.GetReservedSeatsByShow(bookTicketRequest.ShowID); if (reservedSeatsForTheShow.Intersect(bookTicketRequest.SeatIDs).Any()) { throw new Models.Core.AppValidationException("One or more seats are already reserved, please try other seats."); } var pricePerUnit = _showsRepository.GetPriceByShow(bookTicketRequest.ShowID); if (pricePerUnit != null) { using (var transaction = _bookMyTicketDBContext.Database.BeginTransaction()) { ticket = new Ticket { ShowID = bookTicketRequest.ShowID, Price = (decimal)(pricePerUnit * bookTicketRequest.SeatIDs.Count), UserID = _clientContext.UserInfo.ID }; ticket.ID = _ticketsRepository.InsertTicket(_mapper.Map <Entities.Ticket>(ticket)); ticket.ReservedSeats = new List <long>(); bookTicketRequest.SeatIDs.ForEach(seat => { var reservation = new Reservation() { TicketID = ticket.ID, SeatID = seat }; _reservationsRepository.InsertReservation(_mapper.Map <Entities.Reservation>(reservation)); ticket.ReservedSeats.Add(seat); }); transaction.Commit(); } } return(ticket); }
public Ticket BookTicket(BookTicketRequest ticketRequest) { return(_ticketService.BookTicket(ticketRequest)); }