public override async Task <ProductDto> Update(Product entity, string id) { try { if (entity.id != id) { throw new BusinessException("id must be the same in request and payload"); } return(await Task.Run(() => { ProductManagementService.UpdateProduct(id, entity); if (ProductManagementService.HasErrors()) { throw new BusinessException(ProductManagementService.ServiceErrorMessage()); } return WrapItem(entity); })); } catch (NotFoundException ex) { throw new BusinessException("Error retrieving item", ex); } catch (Exception ex) { throw new InternalException("Error retrieving item", ex); } }
public void UpdateNullProductWillThrow(ProductManagementService sut) { // Fixture setup // Exercise system and verify outcome Assert.Throws <ArgumentNullException>(() => sut.UpdateProduct(null)); // Teardown }
public async void TestupdateProduct() { DbContextOptions <CreaturesDbcontext> options = new DbContextOptionsBuilder <CreaturesDbcontext>().UseInMemoryDatabase("updateProduct").Options; using (CreaturesDbcontext context = new CreaturesDbcontext(options)) { Product p = new Product(); p.ID = 1; p.Name = "unicorn"; ProductManagementService Service = new ProductManagementService(context); await Service.Create(p); p.Name = "test"; await Service.UpdateProduct(p); var expect = await context.Products.FirstOrDefaultAsync(c => c.ID == 1); Assert.Equal("test", expect.Name); } }
public void UpdateNullProductWillThrow(ProductManagementService sut) { // Fixture setup // Exercise system and verify outcome Assert.Throws<ArgumentNullException>(() => sut.UpdateProduct(null)); // Teardown }
public IHttpActionResult UpdateProduct(ProductMaster product) { return(Ok(product_service.UpdateProduct(product))); }