Example #1
0
        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);
        }
Example #3
0
        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);
        }
Example #4
0
        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());
        }