Exemplo n.º 1
0
            public async Task <IDataResult <IEnumerable <Product> > > Handle(GetProductsQuery request, CancellationToken cancellationToken)
            {
                var result = new SuccessDataResult <IEnumerable <Product> >(await _productDal.GetListAsync());

                _messageBrokerHelper.QueueMessage($"GetProductsQuery Komutuyla Bütün Ürünler Sorgulandı.");
                return(result);
            }
            public async Task <List <ProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
            {
                var result = await _context.Products
                             .ToListAsync();

                return(_mapper.Map <List <ProductDto> >(result));
            }
Exemplo n.º 3
0
        public async Task ShouldReturnPricesIncreasedBy20Percent()
        {
            //
            var products = new List <Product>
            {
                new Product {
                    ProductId = "1", Description = "Desc1", Name = "p1", UnitPrice = 100.0
                }
            };

            Mock <IProductRepository> productRepoMock = new Mock <IProductRepository>();

            productRepoMock.Setup(repo => repo.GetAllAsync())
            .ReturnsAsync(products);

            ProductDxos productDxos = new ProductDxos();

            var handlr = new GetProductsHandler(productRepoMock.Object, productDxos, new NullLogger <GetProductsHandler>());

            GetProductsQuery queryObj = new GetProductsQuery();

            var productDtos = await handlr.Handle(queryObj, CancellationToken.None);

            Assert.AreEqual(120.0, productDtos[0].Price);
        }
Exemplo n.º 4
0
        public async Task <PagedList <ProductItemDTO> > GetProductItemsAsync(GetProductsQuery query)
        {
            // 搜索
            var filter = Builders <ProductItemDTO> .Filter.Empty;

            if (query.Keyword.IsPresent())
            {
                var itemNoFilter = Builders <ProductItemDTO> .Filter.Regex(x => x.ItemNo, query.Keyword);

                var keywordFilter = Builders <ProductItemDTO> .Filter.Regex(x => x.ProductName, query.Keyword);

                filter = Builders <ProductItemDTO> .Filter.Or(itemNoFilter, keywordFilter);
            }

            // 输出数据
            var fluent = DB.ProductItems.Find(filter);
            var total  = await fluent.CountDocumentsAsync().ConfigureAwait(false);

            fluent = fluent.SortByDescending(x => x.CreatedOnUtc);
            if (query.PageSize > 0 && query.PageIndex > 0)
            {
                fluent = fluent
                         .Skip((query.PageIndex - 1) * query.PageSize)
                         .Limit(query.PageSize);
            }

            var list = await fluent.ToListAsync().ConfigureAwait(false);

            return(new PagedList <ProductItemDTO>(total, query.PageSize, list));
        }
Exemplo n.º 5
0
        public Task <PagedList <ProductDTO> > GetProductsAsync(GetProductsQuery query)
        {
            var where = new StringBuilder();

            if (query.Keyword.IsPresent())
            {
                where.AppendFormat(" AND (ASIN LIKE '%{0}%' OR ProductName LIKE '%{0}%')", query.Keyword);
            }
            if (query.Status.HasValue)
            {
                where.AppendFormat(" AND Status = {0}", (int)query.Status.Value);
            }

            string orderBy = "CreatedOnUtc";

            switch (query.OrderBy.GetValueOrDefault())
            {
            case 1:
                orderBy = "ASIN";
                break;
            }

            orderBy += " " + query.SortDirection;

            return(base.GetPagedListAsync <ProductDTO>(query.PageSize, query.PageIndex, "Product", "*", where.ToString(), orderBy));
        }
Exemplo n.º 6
0
        public async Task Handle_ValidAscOrderBy_ReturnProducts(
            List <Entities.Product> products,
            [Frozen] Mock <IRepository <Entities.Product> > productRepoMock,
            GetProductsQueryHandler sut,
            GetProductsQuery query
            )
        {
            //Arrange
            productRepoMock.Setup(x => x.ListAsync(
                                      It.IsAny <GetProductsPaginatedSpecification>(),
                                      It.IsAny <CancellationToken>()
                                      ))
            .ReturnsAsync(products);

            query.OrderBy = "asc(name)";

            //Act
            var result = await sut.Handle(query, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
            productRepoMock.Verify(x => x.ListAsync(
                                       It.IsAny <ISpecification <Entities.Product> >(),
                                       It.IsAny <CancellationToken>()
                                       ));

            for (int i = 0; i < result.Products.Count; i++)
            {
                result.Products[i].ProductNumber.Should().Be(products[i].ProductNumber);
            }
        }
        public IEnumerable <Product> Handle(GetProductsQuery message)
        {
            var products = this._database
                           .Products
                           .Include(p => p.Category)
                           .Include(p => p.FieldValues)
                           .Include(p => p.FieldValues.Select(fv => fv.Field))
            ;

            if (message.CategoryId.HasValue)
            {
                products = products.Where(p => p.CategoryId == message.CategoryId);
            }

            if (message.FieldValues != null)
            {
                var fieldIds = message.FieldValues.Select(fv => fv.Key).ToList();
                var fields   = _database.Fields.Where(f => fieldIds.Contains(f.Id)).ToList();

                products = this.FilterFields(message.FieldValues, fields, products);
            }

            return(products
                   .OrderBy(p => p.Id)
                   .Skip((message.Page - 1) * message.Take)
                   .Take(message.Take)
                   .ToList());
        }
Exemplo n.º 8
0
        public Task <List <ProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var products     = _repository.GetAll().ToList();
            var productsDtos = _mapper.Map <List <Product>, List <ProductDto> >(products);

            return(Task.FromResult(productsDtos));
        }
            public async Task GetProducts_ShouldReturnProducts_WhenProductsExist(
                [Frozen] Mock <IMediator> mockMediator,
                List <Core.Handlers.GetProduct.Product> products,
                [Greedy] ProductController sut,
                GetProductsQuery query
                )
            {
                //Arrange
                var dto = new GetProductsDto
                {
                    TotalProducts = products.Count,
                    Products      = products
                };

                mockMediator.Setup(x => x.Send(It.IsAny <GetProductsQuery>(), It.IsAny <CancellationToken>()))
                .ReturnsAsync(dto);

                //Act
                var actionResult = await sut.GetProducts(query);

                //Assert
                var okObjectResult = actionResult as OkObjectResult;

                okObjectResult.Should().NotBeNull();

                var response = okObjectResult.Value as Models.GetProductsResult;

                response.TotalProducts.Should().Be(products.Count);
                response.Products.Count.Should().Be(products.Count);

                for (int i = 0; i < products.Count; i++)
                {
                    response.Products[i].ProductNumber.Should().Be(products[i].ProductNumber);
                }
            }
        public async Task <ActionResult <Result <ProductsVm> > > GetProducts()
        {
            var query  = new GetProductsQuery();
            var result = await _mediatR.Send(query);

            return(Ok(result));
        }
Exemplo n.º 11
0
        public async Task <IEnumerable <GetProductsDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var products = await searchProductService
                           .GetProducts(request.FilteringData);

            return(mapper.Map <List <GetProductsDto> >(products));
        }
Exemplo n.º 12
0
        public void Handle_NoProductsExists_ThrowArgumentNullException(
            [Frozen] Mock <IRepository <Entities.Product> > productRepoMock,
            GetProductsQueryHandler sut,
            GetProductsQuery query
            )
        {
            // Arrange
            query.OrderBy = "";

            productRepoMock.Setup(x => x.ListAsync(
                                      It.IsAny <GetProductsPaginatedSpecification>(),
                                      It.IsAny <CancellationToken>()
                                      ))
            .ReturnsAsync((List <Entities.Product>)null);

            //Act
            Func <Task> func = async() => await sut.Handle(query, CancellationToken.None);

            //Assert
            func.Should().ThrowAsync <ArgumentNullException>();
            productRepoMock.Verify(x => x.ListAsync(
                                       It.IsAny <ISpecification <Entities.Product> >(),
                                       It.IsAny <CancellationToken>()
                                       ));
        }
        private string AppentFilters(GetProductsQuery query)
        {
            var sqlQuery = string.Empty;

            if (!string.IsNullOrEmpty(query.Name))
            {
                sqlQuery = sqlQuery.AddWhere("[Name] LIKE @Name ");
            }

            if (query.CategoryId.HasValue)
            {
                sqlQuery = sqlQuery.AddWhere(
                    "EXISTS (SELECT [Id] FROM [ProductCategories] " +
                    "WHERE [ProductId] = Products.Id " +
                    "AND [CategoryId] = @CategoryId) ");
            }

            if (query.AttributeValues.Any())
            {
                sqlQuery = sqlQuery.AddWhere(
                    "EXISTS (SELECT [Id] FROM [ProductAttributeValues] " +
                    "WHERE [ProductId] = Products.Id " +
                    $"AND ([AttributeValueId] ={string.Join(" OR [AttributeValueId] = ", query.AttributeValues)})) ");
            }

            sqlQuery = sqlQuery.AddWhere("[Price] > @MinPrice ");
            sqlQuery = sqlQuery.AddWhere("[Price] < @MaxPrice ");

            return(sqlQuery);
        }
        public async Task <IEnumerable <ProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var products = await _dbContext.Produts.ToListAsync();

            var response = _mapper.Map <IEnumerable <ProductDto> >(products);

            return(response);
        }
Exemplo n.º 15
0
        public ProductsControllersTests()
        {
            _getProductsQuery    = A.Fake <GetProductsQuery>();
            _searchProductsQuery = A.Fake <SearchProductsQuery>();
            _getProductBundles   = A.Fake <GetProductBundlesQuery>();

            _productController = new ProductsController(_getProductsQuery, _searchProductsQuery, _getProductBundles);
        }
        public GetProductsQueryHandlerTests(ITestOutputHelper output)
        {
            _output = output;

            _handler = new GetProductsQueryHandler(Context, Mapper);

            _query = new GetProductsQuery();
        }
Exemplo n.º 17
0
        public async Task <List <ProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var entities = await _context.Products.ToListAsync();

            var responseDto = _mapper.Map <List <Product>, List <ProductDto> >(entities);

            return(responseDto);
        }
Exemplo n.º 18
0
        public async Task <IEnumerable <ProductQueryModel> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            _logger.Debug("Handling GetProductsQuery");

            var products = await _productQueryRepository.GetAllProducts().ConfigureAwait(false);

            return(products);
        }
Exemplo n.º 19
0
        public async Task <IActionResult> Get()
        {
            var query = new GetProductsQuery();

            var result = await _mediator.Send(query);

            return(Ok(result));
        }
Exemplo n.º 20
0
        public Product Get(int ID)
        {
            IQuery query = new GetProductsQuery();

            using (var connection = new SqlConnection(connectionString))
            {
                return(connection.Query <Product>(query.Sql, new { ID }).First());
            }
        }
Exemplo n.º 21
0
        public Task <IQueryable <Product> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var selectedPropertiesList = request.GraphQLContext.GetSelectedPropertiesListAsString();
            var results = _context
                          .Products
                          .Select <Product>($"new({selectedPropertiesList})");

            return(Task.FromResult(results));
        }
Exemplo n.º 22
0
        public async Task <List <ProductResponse> > Handle(
            GetProductsQuery request,
            CancellationToken cancellationToken)
        {
            var products = await productRepository
                           .GetAllAsync(request.Filter, request.Pagination, request.Sorting)
                           .ConfigureAwait(false);

            return(mapper.Map <List <ProductResponse> >(products));
        }
 public async Task <IEnumerable <ProductDTO> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
 {
     return(await _context.Product.Select(x => new ProductDTO()
     {
         Guid = x.Guid,
         Id = x.Id,
         Name = x.Name,
         ShortName = x.ShortName,
         Price = x.Price.Where(y => y.CurrentPrice == true).FirstOrDefault().Price1
     }).ToListAsync());
 }
Exemplo n.º 24
0
 public async Task <BaseDto <IList <ProductInput> > > Handle(GetProductsQuery request, CancellationToken cancellationToken) =>
 new BaseDto <IList <ProductInput> >
 {
     Message = "Success retrieve Product datas",
     Status  = true,
     Data    = await _context.products.OrderBy(x => x.id).Select(result => new ProductInput {
         merchant_id = result.merchant_id,
         name        = result.name,
         price       = result.price
     }).ToListAsync()
 };
Exemplo n.º 25
0
        public virtual ActionResult List()
        {
            var request = new GetProductsQuery()
            {
                UserId = CurrentUserId()
            };

            var result = mediator.Send(request);

            return(View(result));
        }
Exemplo n.º 26
0
        public async Task ShouldReturnProductList()
        {
            // Arrange
            var request = new GetProductsQuery();

            // Act
            List <ProductListDto> list = await SendAsync(request);

            // Assert
            list.Should().Contain(x => x.Id == ProductId);
        }
Exemplo n.º 27
0
        public async Task <IEnumerable <Product> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            IEnumerable <Product> products = await _productRepository.GetProductsAsync();

            if (products == null)
            {
                throw new ApplicationException("Failed to load products");
            }

            return(products);
        }
Exemplo n.º 28
0
        public async Task <IList <GetProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
        {
            var            result   = new List <GetProductDto>();
            List <Product> products = await _context.Products.ToListAsync();

            if (products != null)
            {
                result = _mapper.Map <List <GetProductDto> >(products);
            }
            return(result);
        }
 public IEnumerable <Product> Handle(GetProductsQuery query)
 {
     if (!string.IsNullOrEmpty(query.Name))
     {
         return(productRepository.GetByName(query.Name));
     }
     else
     {
         return(productRepository.GetAll());
     }
 }
Exemplo n.º 30
0
 public async Task <IList <ProductDto> > Handle(GetProductsQuery request, CancellationToken cancellationToken)
 {
     return
         (await _context.Products.Select(product => new ProductDto
     {
         Id = product.Id,
         Name = product.Name,
         Price = product.Price,
         Quentity = product.Quantity,
     }).ToListAsync(cancellationToken));
 }