public async Task <ActionResult> CreateTicketTypeAsync(TicketTypeVm ticketTypeVm) { await _ticketTypeService.CreateTicketTypeAsync(ticketTypeVm); Log.Information("Ticket type {@ticketTypeVm} added to db", ticketTypeVm); return(Ok()); }
public async Task <ActionResult> DeleteTicketTypeAsync(TicketTypeVm ticketTypeVm) { await _ticketTypeService.DeleteTicketTypeAsync(ticketTypeVm); Log.Information("Ticket type {@ticketTypeVm} deleted", ticketTypeVm); return(Ok()); }
public async Task ShouldGetTicketTypeById() { CreateTicketTypes(); TicketTypeService ticketTypeService = new TicketTypeService(_dbContext, _mainEventProvider); TicketTypeController ticketTypeController = new TicketTypeController(ticketTypeService); ActionResult <TicketTypeVm> result1 = await ticketTypeController.GetTicketTypeAsync(1); TicketTypeVm returnedTicketType1 = (TicketTypeVm)((OkObjectResult)result1.Result).Value; Assert.AreEqual(1, returnedTicketType1.Id); Assert.AreEqual("Test ticket type", returnedTicketType1.DescriptionName); Assert.AreEqual(10, returnedTicketType1.BasePrice); Assert.AreEqual(20, returnedTicketType1.AmountAvailable); ActionResult <TicketTypeVm> result2 = await ticketTypeController.GetTicketTypeAsync(2); TicketTypeVm returnedTicketType2 = (TicketTypeVm)((OkObjectResult)result2.Result).Value; Assert.AreEqual(2, returnedTicketType2.Id); Assert.AreEqual(_descrName1, returnedTicketType2.DescriptionName); Assert.AreEqual(_basePrice1, returnedTicketType2.BasePrice); Assert.AreEqual(_amountAvailable1, returnedTicketType2.AmountAvailable); }
public async Task ShouldCreateTicketType() { TicketTypeService ticketTypeService = new TicketTypeService(_dbContext, _mainEventProvider); TicketTypeController ticketTypeController = new TicketTypeController(ticketTypeService); CreateTicketTypes(); ActionResult <List <TicketTypeListVm> > resultAr = await ticketTypeController.GetTicketTypesAsync(); List <TicketTypeListVm> result = resultAr.Value; Assert.AreEqual(2, result.Count); string descrName3 = "Description name 3"; int basePrice3 = 30; int amountAvailable3 = 250; TicketTypeVm ticketTypeVm = new TicketTypeVm { DescriptionName = descrName3, BasePrice = basePrice3, AmountAvailable = amountAvailable3 }; await ticketTypeController.CreateTicketTypeAsync(ticketTypeVm); ActionResult <List <TicketTypeListVm> > newResultAr = await ticketTypeController.GetTicketTypesAsync(); List <TicketTypeListVm> newResult = newResultAr.Value; Assert.AreEqual(3, newResult.Count); Assert.That(newResult, Has.Exactly(1).Matches <TicketTypeListVm>(ticketType => ticketType.Id == 3 && ticketType.DescriptionName == descrName3 && ticketType.BasePrice == basePrice3 && ticketType.AmountAvailable == amountAvailable3)); }
public async Task ShouldUpdateTicketType() { CreateTicketTypes(); string newdescrName = "New descr name"; int newBasePrice = 80; int newAmmount = 350; TicketTypeService ticketTypeService = new TicketTypeService(_dbContext, _mainEventProvider); TicketTypeController ticketTypeController = new TicketTypeController(ticketTypeService); TicketTypeVm ticketTypeVm = new TicketTypeVm { Id = 1, DescriptionName = newdescrName, BasePrice = newBasePrice, AmountAvailable = newAmmount }; await ticketTypeController.UpdateTicketTypeAsync(ticketTypeVm); // Check that only one has been changed TicketType ticketType1 = _dbContext.TicketTypes.Find(1); Assert.AreEqual(newdescrName, ticketType1.DescriptionName); Assert.AreEqual(newBasePrice, ticketType1.BasePrice); Assert.AreEqual(newAmmount, ticketType1.AmountAvailable); TicketType ticketType2 = _dbContext.TicketTypes.Find(2); Assert.AreEqual(_descrName1, ticketType2.DescriptionName); Assert.AreEqual(_basePrice1, ticketType2.BasePrice); Assert.AreEqual(_amountAvailable1, ticketType2.AmountAvailable); }
/// <summary> /// Deletes ticket type /// </summary> /// <param name="ticketTypeVm"></param> public async Task DeleteTicketTypeAsync(TicketTypeVm ticketTypeVm) { var ticketTypeToBeDeleted = _dbContext.TicketTypes.Where(a => a.Id == ticketTypeVm.Id).SingleOrDefault(); if (ticketTypeToBeDeleted == null) { throw new HttpException(HttpStatusCode.NotFound, $"Fant ingen billettyper med navnet: {ticketTypeVm.DescriptionName}"); } _dbContext.Remove <TicketType>(ticketTypeToBeDeleted); await _dbContext.SaveChangesAsync(); }
/// <summary> /// Modify ticket type /// </summary> /// <param name="ticketTypeVm"></param> public async Task UpdateTicketTypeAsync(TicketTypeVm ticketTypeVm) { var existingTicketType = _dbContext.TicketTypes.Find(ticketTypeVm.Id); if (existingTicketType == null) { throw new HttpException(HttpStatusCode.NotFound, $"Fant ingen billettyper med navnet: {ticketTypeVm.DescriptionName}"); } existingTicketType.AmountAvailable = ticketTypeVm.AmountAvailable; existingTicketType.BasePrice = ticketTypeVm.BasePrice; existingTicketType.DescriptionName = ticketTypeVm.DescriptionName; _dbContext.Update(existingTicketType); await _dbContext.SaveChangesAsync(); }
public async Task ShouldDeleteTicketType() { CreateTicketTypes(); TicketTypeService ticketTypeService = new TicketTypeService(_dbContext, _mainEventProvider); TicketTypeController ticketTypeController = new TicketTypeController(ticketTypeService); TicketTypeVm ticketTypeVm = new TicketTypeVm { Id = 1 }; await ticketTypeController.DeleteTicketTypeAsync(ticketTypeVm); // Check that we have deleted only the first, but not the other TicketType ticketType1 = _dbContext.TicketTypes.Find(1); Assert.IsNull(ticketType1); TicketType ticketType2 = _dbContext.TicketTypes.Find(2); Assert.IsNotNull(ticketType2); }
/// <summary> /// Create ticket type /// </summary> /// <param name="ticketTypeVm"></param> public async Task CreateTicketTypeAsync(TicketTypeVm ticketTypeVm) { var existingTicketType = _dbContext.TicketTypes .Where(a => a.DescriptionName == ticketTypeVm.DescriptionName) .SingleOrDefault(); if (existingTicketType != null) { throw new HttpException(HttpStatusCode.Conflict, $"Billettypen {ticketTypeVm.DescriptionName} eksisterer allerede"); } var newTicketType = new TicketType { DescriptionName = ticketTypeVm.DescriptionName, AmountAvailable = ticketTypeVm.AmountAvailable, BasePrice = ticketTypeVm.BasePrice, MainEventId = _mainEventProvider.MainEventId }; _dbContext.TicketTypes.Add(newTicketType); await _dbContext.SaveChangesAsync(); }