public ActionResult Add(Shoppinglist model) { var shoppinglist = new Shoppinglist(); shoppinglist.Name = model.Name; _service.AddOrUpdate(shoppinglist); _service.Complete(); return(RedirectToAction("Index", "Shoppinglists")); }
public IHttpActionResult Add(ShoppinglistDto shoppinglistDto) { if (!ModelState.IsValid) { return(BadRequest()); } var shoppinglist = Mapper.Map <ShoppinglistDto, Shoppinglist>(shoppinglistDto); _service.AddOrUpdate(shoppinglist); shoppinglistDto.Id = shoppinglist.Id; _service.Complete(); return(Created(new Uri(Request.RequestUri + "/" + shoppinglist.Id), shoppinglistDto)); }
public void AddOrUpdate_Product_Returns_True() { // Arrange var product = new Product { Mass = 50 }; var mockRepo = new Mock <IProductRepository>(); mockRepo.Setup(m => m.AddOrUpdate(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.AddOrUpdate(product); // Assert Assert.IsTrue(actual); }
public void AddOrUpdate_Shoppinglist_Returns_True() { // Arrange var shoppinglist = new Shoppinglist { Name = "test" }; var mockRepo = new Mock <IShoppinglistRepository>(); mockRepo.Setup(m => m.AddOrUpdate(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.AddOrUpdate(shoppinglist); // Assert Assert.IsTrue(actual); }