AdventureWorks.WebServices.Controllers.ShoppingCartController.RemoveShoppingCartItem C# (CSharp) Method

RemoveShoppingCartItem() private method

private RemoveShoppingCartItem ( string id, string itemIdToRemove ) : void
id string
itemIdToRemove string
return void
        public void RemoveShoppingCartItem(string id, string itemIdToRemove)
        {
            lock (_lock)
            {
                ShoppingCart shoppingCart = _shoppingCartRepository.GetById(id);

                if (shoppingCart == null)
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }

                if (!_shoppingCartRepository.RemoveItemFromCart(shoppingCart, itemIdToRemove))
                {
                    throw new HttpResponseException(HttpStatusCode.NotFound);
                }
            }
        }

Usage Example

        public void RemoveShoppingCartItem_Throws_ForUnknownItem()
        {
            var shoppingCartRepository = new MockShoppingCartRepository();
            shoppingCartRepository.GetByIdDelegate = (userId) =>
                                                         {
                                                             return new ShoppingCart(new Collection<ShoppingCartItem>());
                                                         };

            shoppingCartRepository.RemoveItemFromCartDelegate = (shoppingCart, itemId) =>
            {
                return false;
            };

            var target = new ShoppingCartController(shoppingCartRepository, new MockProductRepository());
            try
            {
                target.RemoveShoppingCartItem("JohnDoe", "UnknownProductid");
            }
            catch (HttpResponseException ex)
            {
                Assert.AreEqual(System.Net.HttpStatusCode.NotFound, ex.Response.StatusCode);
            }
        }