示例#1
0
        public async Task GetItemsForUser_ShouldReturnResult_IfItemsCanBeFound()
        {
            // Arrange
            var mockQueryHelper = new Mock <IQueryHelper>(MockBehavior.Strict);
            var controller      = new UserItemsController(mockQueryHelper.Object);
            int userId          = 1;

            mockQueryHelper.Setup(q => q.UserQueries.GetUser(userId))
            .ReturnsAsync(new UserDto());
            var expectedUserItems = new List <UserItemDto>
            {
                new UserItemDto()
            };

            mockQueryHelper.Setup(q => q.UserItemQueries
                                  .GetAllItemsForUser(userId))
            .ReturnsAsync(expectedUserItems);

            // Act
            IActionResult result = await controller.GetItemsForUser(userId);

            // Assert
            var okResult = Assert.IsType <OkObjectResult>(result);

            Assert.Equal(expectedUserItems, okResult.Value);
        }
示例#2
0
        public async Task GetItemsForUser_ShouldReturnNotFound_IfRequestUserCannotBeFound()
        {
            // Arrange
            var mockQueryHelper = new Mock <IQueryHelper>(MockBehavior.Strict);
            var controller      = new UserItemsController(mockQueryHelper.Object);
            int userId          = 1;

            mockQueryHelper.Setup(q => q.UserQueries.GetUser(userId))
            .ReturnsAsync((UserDto)null);

            // Act
            IActionResult result = await controller.GetItemsForUser(userId);

            // Assert
            var notFoundResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.Equal($"No user can be found with ID {userId}", notFoundResult.Value);
        }
示例#3
0
        public async Task GetItemsForUser_ShouldReturnNotFound_IfNoItemsCanBeFound()
        {
            // Arrange
            var mockQueryHelper = new Mock <IQueryHelper>(MockBehavior.Strict);
            var controller      = new UserItemsController(mockQueryHelper.Object);
            int userId          = 1;

            mockQueryHelper.Setup(q => q.UserQueries.GetUser(userId))
            .ReturnsAsync(new UserDto());
            mockQueryHelper.Setup(q => q.UserItemQueries
                                  .GetAllItemsForUser(userId))
            .ReturnsAsync(new List <UserItemDto>());

            // Act
            IActionResult result = await controller.GetItemsForUser(userId);

            // Assert
            var notFoundResult = Assert.IsType <NotFoundObjectResult>(result);

            Assert.Equal($"No items found for user with ID {userId}", notFoundResult.Value);
        }