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