Beispiel #1
0
        public async Task Put_NotExistingCartItemPassed_ReturnsNotFoundResponse()
        {
            //Arrange
            Mock <ICartItemService> moqRepo = new Mock <ICartItemService>();        //Mock is type of our Interface

            moqRepo.Setup(repo => repo.UpdateCartItem(null));                       //access the function inside the service class and specify what it returns
            CartItemController controller = new CartItemController(moqRepo.Object); //pass context and moq object inside controller

            //Act
            ActionResult badResponse = await controller.Edit_CartItem(null);//non existing CartItem is paased

            //Assert
            Assert.IsType <NotFoundResult>(badResponse);
        }
Beispiel #2
0
        public async Task Put_ExistingCartItemPassed_ReturnsOkResult()
        {
            //Arrange
            Mock <ICartItemService> moqRepo = new Mock <ICartItemService>();//Mock is type of our Interface
            Category category = new Category()
            {
                CategoryId   = 3,
                CategoryName = "Fruits"
            };

            Product product = new Product()
            {
                ProductId   = 1,
                ProductName = "Oranges",
                Price       = 2,
                CategoryId  = 3,
                Category    = category
            };

            CartItemDTO cartItem = new CartItemDTO()
            {
                ProductId = 1,
                Product   = product,
                Price     = 2,
                Quantity  = 5
            };

            moqRepo.Setup(repo => repo.UpdateCartItem(cartItem));                   //access the function inside the service class and specify what it returns
            CartItemController controller = new CartItemController(moqRepo.Object); //pass moq object inside controller

            //Act
            ActionResult okResponse = await controller.Edit_CartItem(cartItem);//existing CartItem is passed

            //Assert
            Assert.IsType <OkObjectResult>(okResponse);
        }