Пример #1
0
 public IHttpActionResult UpdateItem(Drink item)
 {
     try
     {
         if (ModelState.IsValid)
         {
             if (_repository.Update(item))
             {
                 return(Ok());
             }
             else
             {
                 return(NotFound());
             }
         }
         else
         {
             return(BadRequest(ModelState));
         }
     }
     catch (System.Exception e)
     {
         //a log here may be usefull
         return(InternalServerError(e));
     }
 }
        public void should_update_shopping_list_item_in_data_store()
        {
            _dataStore.Add(new ShoppingListItem {
                ItemName = "Item1", Quantity = 1
            });

            var repository = new ShoppingListRepository();
            var item       = new ShoppingListItemUpdate {
                ItemName = "Item1", Quantity = 5
            };

            repository.Update(item);

            Assert.AreEqual(_dataStore[0].ItemName, "Item1");
            Assert.AreEqual(_dataStore[0].Quantity, 5);
        }