コード例 #1
0
        public void QueryAndSortProductsDescending()
        {
            IClient     commerceToolsClient = this.productFixture.GetService <IClient>();
            ProductType productType         = this.productFixture.CreateNewProductType();

            for (int i = 0; i < 3; i++)
            {
                Product product = this.productFixture.CreateProduct(productType);
                this.productFixture.ProductsToDelete.Add(product);
            }

            List <Sort <Product> > sortPredicates = new List <Sort <Product> >();
            Sort <Product>         sort           = new Sort <Product>(p => p.Key, SortDirection.Descending);

            sortPredicates.Add(sort);
            QueryCommand <Product> queryCommand = new QueryCommand <Product>();

            queryCommand.Where(product => product.ProductType.Id == productType.Id.valueOf());
            queryCommand.SetSort(sortPredicates);

            PagedQueryResult <Product> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;
            var sortedList = returnedSet.Results.OrderByDescending(p => p.Key);

            Assert.True(sortedList.SequenceEqual(returnedSet.Results));
        }
コード例 #2
0
        public void QueryAndSortCategoryDescending()
        {
            IClient  commerceToolsClient = this.categoryFixture.GetService <IClient>();
            Category parentCategory      = this.categoryFixture.CreateCategory();

            this.categoryFixture.CategoriesToDelete.Add(parentCategory);
            for (int i = 0; i < 3; i++)
            {
                Category category = this.categoryFixture.CreateCategory(this.categoryFixture.GetCategoryDraftWithParent(parentCategory));
                this.categoryFixture.CategoriesToDelete.Add(category);
            }

            string id = parentCategory.Id;
            QueryPredicate <Category> queryPredicate = new QueryPredicate <Category>(c => c.Parent.Id == id);
            List <Sort <Category> >   sortPredicates = new List <Sort <Category> >();
            Sort <Category>           sort           = new Sort <Category>(c => c.Name["en"], SortDirection.Descending);

            sortPredicates.Add(sort);
            QueryCommand <Category> queryCommand = new QueryCommand <Category>();

            queryCommand.SetSort(sortPredicates);
            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;
            var sortedList = returnedSet.Results.OrderByDescending(c => c.Name["en"]);

            Assert.True(sortedList.SequenceEqual(returnedSet.Results));
        }
コード例 #3
0
        public void QueryAndSortMessagesDescending()
        {
            IClient commerceToolsClient = this.messagesFixture.GetService <IClient>();

            QueryPredicate <Message> queryPredicate = new QueryPredicate <Message>(m => m.Type == "CustomerEmailVerified" || m.Type == "CategoryCreated");

            //QueryPredicate<Message> queryPredicate = new QueryPredicate<Message>(m => m.Version >=1);

            List <Sort <Message> > sortPredicates = new List <Sort <Message> >();
            Sort <Message>         sort           = new Sort <Message>(m => m.CreatedAt, SortDirection.Descending);

            sortPredicates.Add(sort);

            QueryCommand <Message> queryCommand = new QueryCommand <Message>();

            queryCommand.SetWhere(queryPredicate);
            queryCommand.SetSort(sortPredicates);
            //queryCommand.Limit = 100;

            PagedQueryResult <Message> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.True(returnedSet.Count > 0);
        }