public void BuyProduct_EmptyProductId_ReturnsFalse() { _productRepositoryMock.Setup(m => m.GetProductById("")) .Returns<Product>(null); var productService = new ProductService(_productRepositoryMock.Object); //Act var result = productService.BuyProduct(""); //Assert { Assert.IsFalse(result); } }
public void BuyProduct_AvailableProduct_ReturnsTrue() { //Arrange int quantityAfterBuy = _availableProduct.StockLevel - 1; _productRepositoryMock.Setup(m => m.GetProductById(_availableProduct.Id)) .Returns(_availableProduct); var productService = new ProductService(_productRepositoryMock.Object); //Act var result = productService.BuyProduct(_availableProduct.Id); //Assert Assert.IsTrue(result); }
public void ListProducts_Nothing_CallsProductRepositoryListProducts() { //Arrange _productRepositoryMock.Setup(m => m.ListProducts()) .Returns(It.IsAny<Product[]>()); var productService = new ProductService(_productRepositoryMock.Object); //Act productService.ListProducts(); //Assert _productRepositoryMock.Verify(v => v.ListProducts(), Times.Once); }
public void GetProduct_Nothing_CallsProductRepositoryGetProduct() { //Arrange _productRepositoryMock.Setup(m => m.GetProductById(It.IsAny<string>())) .Returns(It.IsAny<Product>()); var productService = new ProductService(_productRepositoryMock.Object); //Act productService.GetProduct(""); //Assert _productRepositoryMock.Verify(v => v.GetProductById(It.IsAny<string>()), Times.Once); }
public void CreateProduct_AnyProduct_CallsProductRepositoryCreateProduct() { //Arrange _productRepositoryMock.Setup(m => m.CreateProduct(It.IsAny<Product>())); var productService = new ProductService(_productRepositoryMock.Object); //Act productService.CreateProduct(_availableProduct); //Assert _productRepositoryMock.Verify(v => v.CreateProduct(It.IsAny<Product>()), Times.Once); }
public void BuyProduct_ValidId_VerifyRepositoryIsCalled() { //Arrange _productRepositoryMock.Setup(m => m.GetProductById(It.IsAny<string>())) .Returns(_availableProduct); var productService = new ProductService(_productRepositoryMock.Object); //Act var bought = productService.BuyProduct(_availableProduct.Id); //Assert _productRepositoryMock.Verify(v => v.GetProductById(_availableProduct.Id), Times.Once); }
public void BuyProduct_NullProduct_ReturnsFalse() { //Arrange _productRepositoryMock.Setup(m => m.GetProductById(It.IsAny<string>())) .Returns<Product>(null); var productService = new ProductService(_productRepositoryMock.Object); //Act var result = productService.BuyProduct("1"); //Assert Assert.IsFalse(result); }