public void TestGetProductByIdNull() { //Arrange Mock <IProductRepository> mockProductRepository = new Mock <IProductRepository>(); IProductApplicationService productsApplicationService = new ProductApplicationService(mockProductRepository.Object); int id = 0; //Act & Assert Assert.Throws <InvalidOperationException>(() => productsApplicationService .GetProductById(id)); }
public void TestGetProductById() { //Arrange int id = 1; Mock <IProductRepository> mockProductRepository = new Mock <IProductRepository>(); mockProductRepository.Setup(service => service.GetProductById(id)) .Returns(new Product() { ProductId = 1, Ingrediants = "ingrediants", Descriptions = "descriptions", Quantity = 500, }); IProductApplicationService productsApplicationService = new ProductApplicationService(mockProductRepository.Object); //Act ProductDto result = productsApplicationService.GetProductById(id); //Assert Assert.IsType <ProductDto>(result); }