Example #1
0
 public BrowseProductHandlerTests()
 {
     _guid              = Guid.NewGuid();
     _query             = new BrowseProduct();
     _productRepository = new Mock <IProductRepository>();
     _logger            = new Mock <ILogger <BrowseProductHandler> >();
 }
Example #2
0
        public async Task <IActionResult> GetAllProductByCategoryId([FromQuery] BrowseProduct query)
        {
            var products = await _productsService.GetAllProductByCategoryId(query);

            Document[] documents = null;
            if (products.Items.Any())
            {
                documents = await _documentsService.GetAllDocumentsByExternalId(InitializeBrowseDocumentsByExternalId(products));
            }

            return(Collection(ExtendProductByDocument(products, documents)));
        }
        public async Task browseasync_return_null()
        {
            //Arange
            var query = new BrowseProduct();

            _mockMongoRepository.Setup(s => s.BrowseAsync(r => r.CategoryId == query.Id, query)).ReturnsAsync((PagedResult <Product>)null);

            //Act
            var result = await _repository.BrowseAsync(query);

            //Assert
            Assert.Null(result);
        }
        public async Task return_null_when_browseProduct_equal_null()
        {
            // Arrange
            BrowseProduct query = null;

            _mockDispatcher.Setup(r => r.QueryAsync(query)).ReturnsAsync((PagedResult <ProductDto>)null);

            // Act
            var controller = new ProductsController(_mockDispatcher.Object);
            var result     = await controller.GetAllProductByCategoryId(query);

            //Assert
            Assert.Null(result.Value);
            Assert.IsType <ActionResult <PagedResult <ProductDto> > >(result);
        }
        public async Task <PagedResult <ProductDto> > HandleAsync(BrowseProduct query)
        {
            _logger.LogInformation($"Browsing product by Id: '{query.Id}");
            var pagedResult = await _productRepository.BrowseAsync(query);

            _logger.LogInformation($"Browsed product by Id: '{query.Id}");
            var products = pagedResult.Items.Select(p => new ProductDto
            {
                Id          = p.Id,
                Name        = p.Name,
                Description = p.Description,
                Price       = p.Price,
                CategoryId  = p.CategoryId
            }).ToList();

            return(PagedResult <ProductDto> .From(pagedResult, products));
        }
        public async Task return_items_when_browseProduct_not_null()
        {
            // Arrange
            var query = new BrowseProduct();

            var productDtos = new List <ProductDto> {
                new ProductDto()
            };
            var pagedResultBaseMock = new PagedResultBaseMock();
            var pageProducts        = PagedResult <ProductDto> .From(pagedResultBaseMock, productDtos);

            _mockDispatcher.Setup(r => r.QueryAsync(query)).ReturnsAsync(pageProducts);

            // Act
            var controller = new ProductsController(_mockDispatcher.Object);
            var result     = await controller.GetAllProductByCategoryId(query);

            //Assert
            Assert.NotNull(result.Result);
            Assert.IsType <ActionResult <PagedResult <ProductDto> > >(result);
        }
Example #7
0
 public async Task <PagedResult <Product> > BrowseAsync(BrowseProduct query)
 => await _repository.BrowseAsync(q => q.CategoryId == query.Id, query);
 public async Task <ActionResult <PagedResult <ProductDto> > > GetAllProductByCategoryId([FromQuery] BrowseProduct query)
 => Collection(await QueryAsync(query));