Exemplo n.º 1
0
        public async void GetSortedProducts_WhenCalled_SortOptionLow_ReturnsNotNullResult()
        {
            //Arrange
            var _serviceContextMock = new Mock <IServiceContext>();

            _serviceContextMock.Setup(a => a.GetProductsAsync()).Returns(GetProductsAsync());

            IProductRepository _productRepository = new ProductRepository(_serviceContextMock.Object);

            SortResourceParameter sortParameter = new SortResourceParameter
            {
                sortOption = SortOption.Low
            };

            var result = _productRepository.GetProductsAsync(sortParameter);

            SortController _sortController = new SortController(_productRepository);

            //Act
            var actionResult = await _sortController.GetSortedParams(sortParameter) as OkObjectResult;

            //Assert
            Assert.NotNull(actionResult);
        }
Exemplo n.º 2
0
        private async Task <IActionResult> GetSortedProducts(SortResourceParameter sortResourceParameter)
        {
            var products = await _productRepository.GetProductsAsync(sortResourceParameter);

            return(Ok(products));
        }
Exemplo n.º 3
0
        private async Task <IActionResult> GetRecommendedProducts(SortResourceParameter sortResourceParameter)
        {
            var shopperHistories = await _productRepository.GetPopularProductsFromShopperHistoriesAsync();

            return(Ok(shopperHistories));
        }
Exemplo n.º 4
0
 public Task <IActionResult> GetSortedParams([FromQuery] SortResourceParameter
                                             sortResourceParameter) => sortResourceParameter.sortOption.ToString() == "Recommended" ?
 GetRecommendedProducts(sortResourceParameter) : GetSortedProducts(sortResourceParameter);