Beispiel #1
0
        public ObjectResult ClearCart([Required] string cartId)
        {
            var cart = service.ClearCart(cartId, out var error);

            if (cart == null)
            {
                return(StatusCode(error.StatusCode, new { error.Message }));
            }
            return(StatusCode(200, cart));
        }
        public void ClearCartTestCaseNotFound()
        {
            var cart = new Cart();
            var obj  = (object)cart;

            memoryCache.Setup(x => x.TryGetValue(It.IsAny <string>(), out obj)).Returns(false);
            var service = new CustomerCartService(memoryCache.Object, hub.Object, productCacheService.Object);
            var error   = new CartOperationError();

            Assert.Null(service.ClearCart("123", out error));
        }
        public void ClearCartTestCaseOk()
        {
            var cart = new Cart
            {
                CartItems = new Dictionary <int, CartItem> {
                    { 42, new CartItem() }
                }
            };
            var obj     = (object)cart;
            var error   = new CartOperationError();
            var product = new Product();

            memoryCache.Setup(x => x.TryGetValue(It.IsAny <string>(), out obj)).Returns(true);
            productCacheService
            .Setup(x => x.TryUpdateRetained(It.IsAny <int>(), It.IsAny <int>(), out product, out error))
            .Returns(true);
            var service = new CustomerCartService(memoryCache.Object, hub.Object, productCacheService.Object);

            Assert.NotNull(service.ClearCart("123", out error));
            Assert.IsEmpty(cart.CartItems);
        }