Пример #1
0
        public async Task <IActionResult> ProductById(string ProductId)
        {
            //Do code here
            Task <Product> product_by_id = _groceryServices.GetProductById(ProductId);

            if (product_by_id.Result is null)
            {
                return(NotFound($"{ProductId} not found"));
            }

            return(Ok(product_by_id.Result.ProductName));
        }
Пример #2
0
        public async Task <IActionResult> ProductById(string ProductId)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var getproduct = await _groceryServices.GetProductById(ProductId);

            if (getproduct == null)
            {
                return(NotFound());
            }
            return(CreatedAtAction("AllProduct", new { ProductId = getproduct.ProductId }, getproduct));
        }
        public async Task <bool> Testfor_Validate_GetProductById()
        {
            //Arrange
            bool res = false;

            //Act
            groceryservice.Setup(repo => repo.GetProductById(_product.ProductId)).ReturnsAsync(_product);
            var result = await _groceryS.GetProductById(_product.ProductId);

            if (result != null)
            {
                res = true;
            }
            //Asert
            //final result displaying in text file
            await File.AppendAllTextAsync("../../../../output_revised.txt", "Testfor_Validate_GetProductById=" + res + "\n");

            return(res);
        }