public void UpdateName(Product product, string newName) { if (_productRepository.List(p => p.Name == newName && p.Id != product.Id).Any()) { throw new Exception("Duplicate name."); } var productToUpdate = _productRepository.GetById(product.Id); productToUpdate.Name = newName; product.Name = newName; _productRepository.Update(productToUpdate); }
public void UpdatesNameGivenCurrentName() { var product = _productRepository.GetById(TEST_ID2); string newName = product.Name; var productService = new ProductService(_productRepository); productService.UpdateName(product, newName); // here's why I don't like this approach - the client ends up with 2 ways to work with product: through a service or directly product.UpdatePrice(2); _productRepository.Update(product); Assert.Equal(newName, product.Name); }