public void CheckIn() { int id = 1; int idAlien = 1; int idBallad = 1; int?idObjectNotAllowed = null; var now = DateTime.Now; var checkinCheckOut = new CheckInCheckOut(id, idAlien, idBallad, idObjectNotAllowed); checkinCheckOut.CheckIn(); Assert.True(checkinCheckOut.DateTimeEntry > now); }
public IActionResult PostCheckin([FromBody] CheckInCheckOut checkInCheckOut) { try { var alien = _context.Aliens.SingleOrDefault(e => e.Id == checkInCheckOut.IdAlien); if (alien is null) { return(BadRequest("Alien não indentificado")); } var ballad = _context.Ballads.SingleOrDefault(e => e.Id == checkInCheckOut.IdBallad); if (ballad is null) { return(BadRequest("Balada não indentificado")); } if (checkInCheckOut.IdObjectNotAllowed is not null) { var objectNotAllowed = _context.ObjectNotAllowed.SingleOrDefault(e => e.Id == checkInCheckOut.IdObjectNotAllowed); if (objectNotAllowed is null) { return(BadRequest("Objeto proibido não indentificado")); } } if (!alien.AgeCheckMinimumAllowed()) { return(BadRequest("Idade minima para entrada não permitida")); } var CheckOut = _context.CheckInCheckOuts.SingleOrDefault(e => e.IdAlien == checkInCheckOut.IdAlien && e.DateTimeExit == null); if (CheckOut is not null) { return(BadRequest("Alien já está em outra balada")); } checkInCheckOut.CheckIn(); _context.CheckInCheckOuts.Add(checkInCheckOut); _context.SaveChanges(); } catch (Exception e) { return(BadRequest(e.Message)); } return(Ok()); }