Ejemplo n.º 1
0
        public void DeleteCartItemWithValidId()
        {
            // Act
            var resultRaw = _controller.DeleteCartItem(2);
            NegotiatedContentResult <ResponseDto> result = (NegotiatedContentResult <ResponseDto>)resultRaw;

            ////// Assert
            Assert.IsNotNull(result);
            Assert.IsNotNull(result.Content);
            Assert.AreEqual(HttpStatusCode.OK, result.Content.StatusCode);
            Assert.AreEqual("CarItem with id: 2 successfully deleted.", result.Content.MessageDetail);
        }
Ejemplo n.º 2
0
        public void ShouldReturnInternalServerErrorWhenDeletingWithException()
        {
            // Arrange
            var controller = new CartController(
                new StubIShoppingCartRepository
            {
                GetShoppingCartString        = id => new ShoppingCart(id),
                SaveShoppingCartShoppingCart = cart =>
                {
                    throw new Exception("error");
                }
            },
                null);

            SetupControllerForTests(controller);

            // Act
            var response = controller.DeleteCartItem(new CartItemDelete
            {
                ProductId      = 11,
                ShoppingCartId = "id"
            });
            var error = JsonConvert.DeserializeAnonymousType(response.Content.ReadAsStringAsync().Result, new { Message = string.Empty });

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.AreEqual("error", error.Message);
        }
Ejemplo n.º 3
0
        public void ShouldDeleteAnItem()
        {
            // Arrange
            var targetItemRemoved = false;

            var controller = new CartController(
                new StubIShoppingCartRepository
            {
                GetShoppingCartString        = id => new ShoppingCart(id),
                SaveShoppingCartShoppingCart = cart =>
                {
                    targetItemRemoved = true;
                    return(cart);
                }
            },
                null);

            SetupControllerForTests(controller);

            // Act
            var response = controller.DeleteCartItem(new CartItemDelete
            {
                ProductId      = 11,
                ShoppingCartId = "id"
            });

            // Assert
            Assert.IsTrue(targetItemRemoved);
            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
        public async Task Check_DeleteCartItem_ReturnOk()
        {
            // Arrange
            var controller = new CartController(_dbContext);

            UserTempStorage.cartID = 1;


            CartItems ci = new CartItems();

            ci.GameId = 1;
            // Act
            IActionResult deleteItem = await controller.DeleteCartItem(ci);

            //string var = results.RouteValues["id"].ToString();
            // Assert
            Assert.IsInstanceOf <OkObjectResult>(deleteItem);
        }
Ejemplo n.º 5
0
        public void ShouldReturnNotFoundWhenDeletingItemFromUnexistentCart()
        {
            // Arrange
            var controller = new CartController(
                new StubIShoppingCartRepository
            {
                GetShoppingCartString = (id) => null
            },
                null);

            SetupControllerForTests(controller);

            // Act
            var response = controller.DeleteCartItem(new CartItemDelete
            {
                ProductId      = 11,
                ShoppingCartId = "id"
            });
            var error = JsonConvert.DeserializeAnonymousType(response.Content.ReadAsStringAsync().Result, new { Message = string.Empty });

            // Assert
            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }