Exemple #1
0
        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));
        }
Exemple #2
0
        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);
        }