public IHttpActionResult Delete(int id) { var shoppinglistInDb = _service.Get(id); if (shoppinglistInDb == null) { return(NotFound()); } var products = _service.GetAllProducts(shoppinglistInDb.Id); _service.RemoveRange(products); shoppinglistInDb.Products = null; _service.Remove(shoppinglistInDb); _service.Complete(); return(Ok()); }
public void Remove_Shoppinglist_Returns_True() { // Arrange var shoppinglist = new Shoppinglist { Name = "test" }; var mockRepo = new Mock <IShoppinglistRepository>(); mockRepo.Setup(m => m.Remove(shoppinglist)) .Returns( true ); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.Shoppinglists).Returns(mockRepo.Object); ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object); // Act var actual = service.Remove(shoppinglist); // Assert Assert.IsTrue(actual); }
public void Remove_Product_Returns_True() { // Arrange var product = new Product { Mass = 50 }; var mockRepo = new Mock <IProductRepository>(); mockRepo.Setup(m => m.Remove(product)) .Returns( true ); var mockUnitOfWork = new Mock <IUnitOfWork>(); mockUnitOfWork.Setup(uow => uow.Products).Returns(mockRepo.Object); ShoppinglistService service = new ShoppinglistService(mockUnitOfWork.Object); // Act var actual = service.Remove(product); // Assert Assert.IsTrue(actual); }