public async Task PutAsyncTest_ReturnsBadRequest() { var putTransaction = new PutTransaction(); controller.ModelState.AddModelError("MockError", "Model is invalid"); var result = await controller.PutAsync(putTransaction); var assert = Assert.IsType <BadRequestObjectResult>(result); }
private Transaction MakeTransaction <T>(params T[] items) { var transaction = new PutTransaction(); foreach (var item in items) { var packed = CachedObject.Pack(item, _typeDescription); transaction.Items.Add(packed); } return(transaction); }
public async Task PutAsyncTest_ReturnsNoContent() { var transaction = new TransactionDTO(); var putTransaction = new PutTransaction(); _mapperMock.Setup(m => m.Map <PutTransaction, TransactionDTO>(putTransaction)) .Returns(transaction); _serviceMock.Setup(s => s.UpdateAsync(transaction)) .Returns(Task.FromResult(transaction)); var result = await controller.PutAsync(putTransaction); var assert = Assert.IsType <NoContentResult>(result); }
public async Task <IActionResult> PutAsync([FromBody] PutTransaction request) { var prefix = "[PutAsync]"; _logger.LogInformation($"{prefix} Executing action"); if (!ModelState.IsValid) { _logger.LogWarning($"{prefix} Invalid model"); return(BadRequest(ModelState)); } var entity = _mapper.Map <PutTransaction, TransactionDTO>(request); var transaction = await _service.UpdateAsync(entity); if (transaction == null) { _logger.LogWarning($"{prefix} Transaction with id {request.ID} not found"); return(NotFound()); } _logger.LogInformation($"{prefix} Updated transaction with id {request.ID}"); return(NoContent()); }