public async Task UpdatePieceOfWork() { // Initialize the database await _pieceOfWorkRepository.CreateOrUpdateAsync(_pieceOfWork); await _pieceOfWorkRepository.SaveChangesAsync(); var databaseSizeBeforeUpdate = await _pieceOfWorkRepository.CountAsync(); // Update the pieceOfWork var updatedPieceOfWork = await _pieceOfWorkRepository.QueryHelper().GetOneAsync(it => it.Id == _pieceOfWork.Id); // Disconnect from session so that the updates on updatedPieceOfWork are not directly saved in db //TODO detach updatedPieceOfWork.Title = UpdatedTitle; updatedPieceOfWork.Description = UpdatedDescription; PieceOfWorkDto updatedPieceOfWorkDto = _mapper.Map <PieceOfWorkDto>(_pieceOfWork); var response = await _client.PutAsync("/api/piece-of-works", TestUtil.ToJsonContent(updatedPieceOfWorkDto)); response.StatusCode.Should().Be(HttpStatusCode.OK); // Validate the PieceOfWork in the database var pieceOfWorkList = await _pieceOfWorkRepository.GetAllAsync(); pieceOfWorkList.Count().Should().Be(databaseSizeBeforeUpdate); var testPieceOfWork = pieceOfWorkList.Last(); testPieceOfWork.Title.Should().Be(UpdatedTitle); testPieceOfWork.Description.Should().Be(UpdatedDescription); }
public async Task <IActionResult> GetPieceOfWork([FromRoute] long id) { _log.LogDebug($"REST request to get PieceOfWork : {id}"); var result = await _pieceOfWorkService.FindOne(id); PieceOfWorkDto pieceOfWorkDto = _mapper.Map <PieceOfWorkDto>(result); return(ActionResultUtil.WrapOrNotFound(pieceOfWorkDto)); }
public async Task <IActionResult> UpdatePieceOfWork([FromBody] PieceOfWorkDto pieceOfWorkDto) { _log.LogDebug($"REST request to update PieceOfWork : {pieceOfWorkDto}"); if (pieceOfWorkDto.Id == 0) { throw new BadRequestAlertException("Invalid Id", EntityName, "idnull"); } PieceOfWork pieceOfWork = _mapper.Map <PieceOfWork>(pieceOfWorkDto); await _pieceOfWorkService.Save(pieceOfWork); return(Ok(pieceOfWork) .WithHeaders(HeaderUtil.CreateEntityUpdateAlert(EntityName, pieceOfWork.Id.ToString()))); }
public async Task <ActionResult <PieceOfWorkDto> > CreatePieceOfWork([FromBody] PieceOfWorkDto pieceOfWorkDto) { _log.LogDebug($"REST request to save PieceOfWork : {pieceOfWorkDto}"); if (pieceOfWorkDto.Id != 0) { throw new BadRequestAlertException("A new pieceOfWork cannot already have an ID", EntityName, "idexists"); } PieceOfWork pieceOfWork = _mapper.Map <PieceOfWork>(pieceOfWorkDto); await _pieceOfWorkService.Save(pieceOfWork); return(CreatedAtAction(nameof(GetPieceOfWork), new { id = pieceOfWork.Id }, pieceOfWork) .WithHeaders(HeaderUtil.CreateEntityCreationAlert(EntityName, pieceOfWork.Id.ToString()))); }
public async Task UpdateNonExistingPieceOfWork() { var databaseSizeBeforeUpdate = await _pieceOfWorkRepository.CountAsync(); // If the entity doesn't have an ID, it will throw BadRequestAlertException PieceOfWorkDto _pieceOfWorkDto = _mapper.Map <PieceOfWorkDto>(_pieceOfWork); var response = await _client.PutAsync("/api/piece-of-works", TestUtil.ToJsonContent(_pieceOfWorkDto)); response.StatusCode.Should().Be(HttpStatusCode.BadRequest); // Validate the PieceOfWork in the database var pieceOfWorkList = await _pieceOfWorkRepository.GetAllAsync(); pieceOfWorkList.Count().Should().Be(databaseSizeBeforeUpdate); }
public async Task CreatePieceOfWorkWithExistingId() { var databaseSizeBeforeCreate = await _pieceOfWorkRepository.CountAsync(); databaseSizeBeforeCreate.Should().Be(0); // Create the PieceOfWork with an existing ID _pieceOfWork.Id = 1L; // An entity with an existing ID cannot be created, so this API call must fail PieceOfWorkDto _pieceOfWorkDto = _mapper.Map <PieceOfWorkDto>(_pieceOfWork); var response = await _client.PostAsync("/api/piece-of-works", TestUtil.ToJsonContent(_pieceOfWorkDto)); // Validate the PieceOfWork in the database var pieceOfWorkList = await _pieceOfWorkRepository.GetAllAsync(); pieceOfWorkList.Count().Should().Be(databaseSizeBeforeCreate); }
public async Task CreatePieceOfWork() { var databaseSizeBeforeCreate = await _pieceOfWorkRepository.CountAsync(); // Create the PieceOfWork PieceOfWorkDto _pieceOfWorkDto = _mapper.Map <PieceOfWorkDto>(_pieceOfWork); var response = await _client.PostAsync("/api/piece-of-works", TestUtil.ToJsonContent(_pieceOfWorkDto)); response.StatusCode.Should().Be(HttpStatusCode.Created); // Validate the PieceOfWork in the database var pieceOfWorkList = await _pieceOfWorkRepository.GetAllAsync(); pieceOfWorkList.Count().Should().Be(databaseSizeBeforeCreate + 1); var testPieceOfWork = pieceOfWorkList.Last(); testPieceOfWork.Title.Should().Be(DefaultTitle); testPieceOfWork.Description.Should().Be(DefaultDescription); }