Beispiel #1
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));
        }
        public void QueryCategoryWithMultiplePredicates()
        {
            IClient commerceToolsClient = this.categoryFixture.GetService <IClient>();

            Category parentCategory = this.categoryFixture.CreateCategory();

            this.categoryFixture.CategoriesToDelete.Add(parentCategory);

            Category category = this.categoryFixture.CreateCategory(this.categoryFixture.GetCategoryDraftWithParent(parentCategory));

            this.categoryFixture.CategoriesToDelete.Add(category);

            var queryPredicates = new List <QueryPredicate <Category> >
            {
                new QueryPredicate <Category>(c => c.Key == category.Key.valueOf()),
                new QueryPredicate <Category>(c => c.Parent.Id == parentCategory.Id.valueOf())
            };

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

            queryCommand.SetWhere(queryPredicates);

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

            Assert.Single(returnedSet.Results);
            Assert.Equal(returnedSet.Results[0].Key, category.Key);
            Assert.Equal(returnedSet.Results[0].Parent.Id, parentCategory.Id);
        }
Beispiel #3
0
        public void QueryCategory()
        {
            IClient  commerceToolsClient = this.categoryFixture.GetService <IClient>();
            Category category            = this.categoryFixture.CreateCategory();

            this.categoryFixture.CategoriesToDelete.Add(category);
            string key = category.Key;
            QueryPredicate <Category> queryPredicate = new QueryPredicate <Category>(c => c.Key == key);
            QueryCommand <Category>   queryCommand   = new QueryCommand <Category>();

            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, c => c.Key == category.Key);
        }
        public void QueryInventoryEntries()
        {
            IClient        commerceToolsClient = this.inventoryFixture.GetService <IClient>();
            InventoryEntry inventoryEntry      = this.inventoryFixture.CreateInventoryEntry();

            this.inventoryFixture.InventoryEntries.Add(inventoryEntry);
            QueryPredicate <InventoryEntry> queryPredicate =
                new QueryPredicate <InventoryEntry>(ie => ie.Id == inventoryEntry.Id.valueOf());
            QueryCommand <InventoryEntry> queryCommand = new QueryCommand <InventoryEntry>();

            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <InventoryEntry> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, cd => cd.Id == inventoryEntry.Id);
        }
        public void QueryProductDiscount()
        {
            IClient         commerceToolsClient = this.productDiscountFixture.GetService <IClient>();
            ProductDiscount productDiscount     = this.productDiscountFixture.CreateProductDiscount();

            this.productDiscountFixture.ProductDiscountsToDelete.Add(productDiscount);
            string id = productDiscount.Id;
            QueryPredicate <ProductDiscount> queryPredicate = new QueryPredicate <ProductDiscount>(pd => pd.Id == id);
            QueryCommand <ProductDiscount>   queryCommand   = new QueryCommand <ProductDiscount>();

            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <ProductDiscount> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, pd => pd.Id == productDiscount.Id);
        }
Beispiel #6
0
        public void QueryProduct()
        {
            IClient commerceToolsClient = this.productFixture.GetService <IClient>();
            Product product             = this.productFixture.CreateProduct();

            this.productFixture.ProductsToDelete.Add(product);
            string key = product.Key;
            QueryPredicate <Product> queryPredicate = new QueryPredicate <Product>(p => p.Key == key);
            QueryCommand <Product>   queryCommand   = new QueryCommand <Product>();

            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <Product> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, p => p.Key == product.Key);
        }
        public void QueryCustomerGroup()
        {
            IClient       commerceToolsClient = this.customerGroupFixture.GetService <IClient>();
            CustomerGroup customerGroup       = this.customerGroupFixture.CreateCustomerGroup();

            this.customerGroupFixture.CustomerGroupsToDelete.Add(customerGroup);
            string name = customerGroup.Name;
            QueryPredicate <CustomerGroup> queryPredicate = new QueryPredicate <CustomerGroup>(c => c.Name == name);
            QueryCommand <CustomerGroup>   queryCommand   = new QueryCommand <CustomerGroup>();

            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <CustomerGroup> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, c => c.Name == customerGroup.Name);
        }
Beispiel #8
0
        public void QueryCartDiscounts()
        {
            IClient      commerceToolsClient = this.cartDiscountFixture.GetService <IClient>();
            CartDiscount cartDiscount        = this.cartDiscountFixture.CreateCartDiscount();

            this.cartDiscountFixture.CartDiscountsToDelete.Add(cartDiscount);
            QueryPredicate <CartDiscount> queryPredicate =
                new QueryPredicate <CartDiscount>(cd => cd.Id == cartDiscount.Id.valueOf());
            QueryCommand <CartDiscount> queryCommand = new QueryCommand <CartDiscount>();

            queryCommand.SetWhere(queryPredicate);
            PagedQueryResult <CartDiscount> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, cd => cd.Id == cartDiscount.Id);
        }
        public void MultipleWhereParametersUsingSetWhere()
        {
            var c = new QueryCommand <Category>();

            c.SetWhere(new List <QueryPredicate <Category> >
            {
                new QueryPredicate <Category>(category => category.Id == "abc"),
                new QueryPredicate <Category>(category => category.Key == "def")
            });
            QueryRequestMessageBuilder queryRequestMessageBuilder = new QueryRequestMessageBuilder(
                this.clientFixture.GetService <IEndpointRetriever>(),
                this.clientFixture.GetService <IParametersBuilderFactory <IAdditionalParametersBuilder> >(),
                this.clientFixture.GetService <IParametersBuilderFactory <IQueryParametersBuilder> >());
            HttpRequestMessage httpRequestMessage = queryRequestMessageBuilder.GetRequestMessage(c);

            Assert.Equal("categories?where=id%20%3D%20%22abc%22&where=key%20%3D%20%22def%22&withTotal=false", httpRequestMessage.RequestUri.ToString());
        }
Beispiel #10
0
        public void QueryAndExpandParentCategory()
        {
            IClient  commerceToolsClient = this.categoryFixture.GetService <IClient>();
            Category category            = this.categoryFixture.CreateCategory(this.categoryFixture.GetCategoryDraftWithParent());

            this.categoryFixture.CategoriesToDelete.Add(category);
            string key = category.Key;
            QueryPredicate <Category>     queryPredicate = new QueryPredicate <Category>(c => c.Key == key);
            List <Expansion <Category> >  expansions     = new List <Expansion <Category> >();
            ReferenceExpansion <Category> expand         = new ReferenceExpansion <Category>(c => c.Parent);

            expansions.Add(expand);
            QueryCommand <Category> queryCommand = new QueryCommand <Category>();

            queryCommand.SetWhere(queryPredicate);
            queryCommand.SetExpand(expansions);
            PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, c => c.Key == category.Key && c.Parent.Obj != null);
        }
Beispiel #11
0
        public void QueryProductAndExpandParentProductType()
        {
            IClient commerceToolsClient = this.productFixture.GetService <IClient>();
            Product product             = this.productFixture.CreateProduct();

            this.productFixture.ProductsToDelete.Add(product);
            string key = product.Key;
            QueryPredicate <Product>     queryPredicate = new QueryPredicate <Product>(p => p.Key == key);
            List <Expansion <Product> >  expansions     = new List <Expansion <Product> >();
            ReferenceExpansion <Product> expand         = new ReferenceExpansion <Product>(p => p.ProductType);

            expansions.Add(expand);
            QueryCommand <Product> queryCommand = new QueryCommand <Product>();

            queryCommand.SetWhere(queryPredicate);
            queryCommand.SetExpand(expansions);
            PagedQueryResult <Product> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Contains(returnedSet.Results, p => p.Key == product.Key && p.ProductType.Obj != null);
        }
Beispiel #12
0
        public void QueryAndLimitCategory()
        {
            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);
            QueryCommand <Category>   queryCommand   = new QueryCommand <Category>();

            queryCommand.SetWhere(queryPredicate);
            queryCommand.Limit = 2;
            PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            Assert.Equal(2, returnedSet.Results.Count);
            Assert.Equal(3, returnedSet.Total);
        }
Beispiel #13
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);
        }