public void Delete_Should_Not_Fail() { Mock<IRestaurantRepository> repository = new Mock<IRestaurantRepository>(); Restaurant newRestaurant = new Restaurant(); repository.Setup(x => x.Delete(newRestaurant)); repository.Object.Delete(newRestaurant); repository.Verify(x => x.Delete(newRestaurant), "Unable to delete."); }
public void Save_Should_Not_Fail() { Mock<IRestaurantRepository> repository = new Mock<IRestaurantRepository>(); Restaurant newRestaurant = new Restaurant(); repository.Setup(x => x.Save(newRestaurant)).Returns(newRestaurant); repository.Object.Save(newRestaurant); repository.Verify<Restaurant>(x => x.Save(newRestaurant), "Unable to save."); }
public Restaurant Save(Restaurant restaurant) { if (restaurant.RestaurantID <= 0) { dataContext.Restaurants.InsertOnSubmit(restaurant); } else { dataContext.Restaurants.Attach(restaurant); dataContext.Refresh(System.Data.Linq.RefreshMode.KeepChanges, restaurant); } dataContext.SubmitChanges(); return restaurant; }
public void Delete(Restaurant restaurant) { dataContext.Restaurants.DeleteOnSubmit(restaurant); dataContext.SubmitChanges(); }
public ActionResult Edit(Restaurant restaurant) { try { if (ModelState.IsValid) { _repository.Save(restaurant); ViewBag.Message = "New restaurant " + restaurant.Name + " was added to the database."; return RedirectToAction("Index"); } else { throw new Exception(); } } catch { ViewBag.Message = "Data could not be saved. Please try again later."; return View(); } }
public ActionResult Edit(int id = 0) { Restaurant restaurant; if (id > 0) { restaurant = _repository.Restaurants.First(x => x.RestaurantID == id); } else { restaurant = new Restaurant(); } return View(restaurant); }
partial void DeleteRestaurant(Restaurant instance);
partial void UpdateRestaurant(Restaurant instance);
partial void InsertRestaurant(Restaurant instance);
public Restaurant Save(Restaurant restaurant) { throw new NotImplementedException(); }
public void Delete(Restaurant restaurant) { throw new NotImplementedException(); }