示例#1
0
        public async Task GetProductByStockQuantityIntervalHandlerAsync_WithMinBiggerThanMaxQuantities_ThrowsException()
        {
            //Arrange
            var command = new GetProductsByStockIntervalQueryRequest {
                MinStockQuantity = 5, MaxStockQuantity = 3
            };

            //Act
            var actualException = await Assert.ThrowsAsync <Exception>(() => _getProductsByStockInterval.Handle(command, new CancellationToken()));

            //Assert
            Assert.Equal(MessageConstants.MinStockCantBeBiggerThanMaxStock, actualException.Message);
        }
示例#2
0
        //[LoggerAspect]
        public async Task <List <GetProductQueryResponse> > Handle(GetProductsByStockIntervalQueryRequest request, CancellationToken cancellationToken)
        {
            if (request.MinStockQuantity < 0 || request.MaxStockQuantity < 0)
            {
                throw new Exception(MessageConstants.StockQuantityCannotBeNegative);
            }

            if (request.MinStockQuantity > request.MaxStockQuantity)
            {
                throw new Exception(MessageConstants.MinStockCantBeBiggerThanMaxStock);
            }

            var productList = await _unitOfWork.ProductRepository.GetByStockInterval(request.MinStockQuantity, request.MaxStockQuantity);

            var productResponseList = _mapper.Map <List <GetProductQueryResponse> >(productList);

            return(productResponseList);
        }