public void UpdateProduct_WhenNotExist() { // Arrange var mockRepository = new Mock <IProductRepository>(); Guid testId = Guid.NewGuid(); mockRepository.Setup(p => p.UpdateProduct(testId, It.IsAny <Product>())) .Throws <Exception>(); var service = new ProductDomainService(mockRepository.Object); // Act & Assert Assert.Throws <Exception>(() => service.UpdateProduct(testId, new Product() { Name = "Guasha" })); }
public void UpdateProduct_WhenExist() { // Arrange var mockRepository = new Mock <IProductRepository>(); Guid testId = Guid.NewGuid(); var testProduct = new Product() { Id = testId, Name = "Guasha" }; mockRepository.Setup(p => p.UpdateProduct(testId, It.IsAny <Product>())) .Returns(() => testProduct); var service = new ProductDomainService(mockRepository.Object); // Act var check = service.UpdateProduct(testId, testProduct); // Assert var result = Assert.IsType <Product>(check); Assert.Equal(testId, result.Id); Assert.Equal(testProduct.Name, result.Name); }