public async Task ShouldDeleteTicket() { List <TicketsToBuyVm> tickets = new List <TicketsToBuyVm>(); tickets.Add(new TicketsToBuyVm { Id = 1 }); await CreateTickets(tickets); TicketService ticketService = new TicketService(_dbContext, _mainEventProvider); TicketController ticketController = new TicketController(ticketService); SetUser(ticketController, _createdUser1.Entity.Id); TicketVm ticketVm = new TicketVm { Id = 1 }; ActionResult <TicketVm> result = await ticketController.DeleteTicketAsync(ticketVm); TicketVm deletedTicket = (TicketVm)((OkObjectResult)result.Result).Value; Assert.AreEqual(1, deletedTicket.Id); // Check that we have deleted only the first, but not the other Ticket ticket1 = _dbContext.Tickets.Find(1); Assert.IsNull(ticket1); Ticket ticket2 = _dbContext.Tickets.Find(2); Assert.IsNotNull(ticket2); }
public void ShouldNotDeleteTicketIfDoesntExist() { TicketService ticketService = new TicketService(_dbContext, _mainEventProvider); TicketController ticketController = new TicketController(ticketService); var ex = Assert.ThrowsAsync <HttpException>(async() => { ActionResult <TicketVm> result = await ticketController.DeleteTicketAsync(new TicketVm { Id = 123 }); }); Assert.That(ex.Message == "Fant ikke billetten"); }