Exemple #1
0
        public async Task <IActionResult> PutAsync(UpdateBeerContainer container)
        {
            IActionResult result = null;

            try
            {
                var containerToUpdate = await _context.BeerContainers.FindAsync(container.BeerContainerId);

                if (containerToUpdate != null)
                {
                    containerToUpdate.ContainerType = container.ContainerType;
                    containerToUpdate.DateModified  = DateTime.UtcNow;
                    await _context.SaveChangesAsync();

                    result = Ok(containerToUpdate);
                }
                else
                {
                    result = NotFound();
                }
            }
            catch (Exception e)
            {
                result = BadRequest();
            }

            return(result);
        }
        public async Task PutAsync_Should_Return_BadRequest_On_Exception()
        {
            // Arrange
            UpdateBeerContainer container = null;

            // Act
            var result = await _controller.PutAsync(container);

            // Assert
            result.Should()
            .NotBeNull();

            result.Should()
            .BeOfType <BadRequestResult>();
        }