public IActionResult AddTicket(AddTicketResultModel ticket) { var type = _unitOfWork.TicketTypeRepository.Get(ticket.TypeID); var typeDTO = new TicketTypeDTO { Id = type.Id, TypeName = type.TypeName }; var ticketDTO = new TicketDTO() { Price = ticket.Price, Type = typeDTO, FlightID = ticket.FlightID }; for (int i = 0; i < ticket.Amount; i++) { _ticketService.Create(ticketDTO); } return(RedirectToAction("GetAllTickets", "Admin")); }
public void CreateTest() { //Arrange var ticket = new Ticket() { Price = 400, FlightId = 1 }; var ticketDTO = new TicketDTO() { Price = 400, FlightID = 1 }; List <Ticket> tickets = new List <Ticket>(); ticketMockRepository.Setup(x => x.GetAll()).Returns(tickets); ticketMockRepository.Setup(x => x.Create(ticket)).Callback((Ticket t) => { tickets.Add(new Ticket()); }); mapper.Setup(x => x.Map <Ticket>(ticketDTO)).Returns(ticket); ticketService.Create(ticketDTO); Assert.Single(ticketService.GetAll()); }