Ejemplo n.º 1
0
 public async Task <IActionResult> GetAll()
 {
     try
     {
         return(Ok(await _stackService.GetAll()));
     }
     catch (Exception ex)
     {
         _logger.LogError(ex.Message);
         return(BadRequest(ex.Message));
     }
 }
        public async Task ShouldReturnSuccess_WhenService_GetAllStacks()
        {
            // Arrange
            IEnumerable <Stack>         stacks         = StackFake.GetStacks();
            IEnumerable <StackResponse> stackResponses = stacks.Select(stack =>
            {
                return(new StackResponse {
                    StackId = stack.StackId, StackName = stack.StackName
                });
            });

            _stackRepository.Setup(m => m.GetAll()).Returns(Task.FromResult(stacks));
            _mapper.Setup(m => m.Map <IEnumerable <StackResponse> >(It.IsAny <IEnumerable <Stack> >())).Returns(stackResponses);

            // Act
            IEnumerable <StackResponse> result = await _stackService.GetAll();

            // Assert
            Assert.NotEmpty(result);
            Assert.Equal(result.Count(), stackResponses.Count());
        }