Ejemplo n.º 1
0
        public async Task RemoveItemsForUser_ShouldReturnLatestInventory_IfAllArgumentsValid()
        {
            // Arrange
            var mockQueryHelper = new Mock <IQueryHelper>(MockBehavior.Strict);
            var controller      = new UserItemsController(mockQueryHelper.Object);
            int userId          = 1;
            var items           = new List <ItemDto>()
            {
                new ItemDto()
            };

            mockQueryHelper.Setup(q => q.UserQueries.GetUser(userId))
            .ReturnsAsync(new UserDto());
            mockQueryHelper.Setup(q => q.UserItemQueries
                                  .RemoveItemForUser(userId, It.IsAny <ItemDto>()))
            .Returns(Task.CompletedTask);
            var expectedLatestInventory = new List <UserItemDto>();

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

            // Act
            IActionResult result = await controller.RemoveItemsForUser(userId, items);

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

            Assert.Equal(expectedLatestInventory, okResult.Value);
        }
Ejemplo n.º 2
0
        public async Task RemoveItemsForUser_ShouldReturnResult_IfNoItemsSentInRequest()
        {
            // Arrange
            var mockQueryHelper = new Mock <IQueryHelper>(MockBehavior.Strict);
            var controller      = new UserItemsController(mockQueryHelper.Object);

            // Act
            IActionResult result = await controller.RemoveItemsForUser(1, new List <ItemDto>());

            // Assert
            var badRequestResult = Assert.IsType <BadRequestObjectResult>(result);

            Assert.Equal("Items in request body could not be parsed", badRequestResult.Value);
        }
Ejemplo n.º 3
0
        public async Task RemoveItemsForUser_ShouldReturnNotFound_IfRequestUserCannotBeFound()
        {
            // Arrange
            var mockQueryHelper = new Mock <IQueryHelper>(MockBehavior.Strict);
            var controller      = new UserItemsController(mockQueryHelper.Object);
            int userId          = 1;
            var items           = new List <ItemDto>()
            {
                new ItemDto()
            };

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

            // Act
            IActionResult result = await controller.RemoveItemsForUser(userId, items);

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

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