예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
        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);
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }