public void GetQueryRequestMessageWithExpand()
        {
            List <Expansion <Category> >  expansions      = new List <Expansion <Category> >();
            ReferenceExpansion <Category> parentExpansion = new ReferenceExpansion <Category>(c => c.Parent);

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

            queryCommand.SetExpand(expansions);
            QueryRequestMessageBuilder queryRequestMessageBuilder = new QueryRequestMessageBuilder(
                this.clientFixture.GetService <IClientConfiguration>(),
                this.clientFixture.GetService <IEndpointRetriever>(),
                this.clientFixture.GetService <IParametersBuilderFactory <IAdditionalParametersBuilder> >());
            HttpRequestMessage httpRequestMessage = queryRequestMessageBuilder.GetRequestMessage(queryCommand);

            Assert.Equal(this.clientFixture.APIBaseAddressWithProjectKey + "/categories?expand=parent", httpRequestMessage.RequestUri.ToString());
        }
        public void GetQueryRequestMessageWithTwoExpands()
        {
            List <Expansion <Category> >  expansions             = new List <Expansion <Category> >();
            ReferenceExpansion <Category> parentExpansion        = new ReferenceExpansion <Category>(c => c.Parent);
            ReferenceExpansion <Category> firstAncestorExpansion = new ReferenceExpansion <Category>(c => c.Ancestors[0]);

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

            queryCommand.SetExpand(expansions);
            QueryRequestMessageBuilder queryRequestMessageBuilder = new QueryRequestMessageBuilder(
                this.clientFixture.GetService <IEndpointRetriever>(),
                this.clientFixture.GetService <IParametersBuilderFactory <IAdditionalParametersBuilder> >(),
                this.clientFixture.GetService <IParametersBuilderFactory <IQueryParametersBuilder> >());
            HttpRequestMessage httpRequestMessage = queryRequestMessageBuilder.GetRequestMessage(queryCommand);

            Assert.Equal("categories?expand=parent&expand=ancestors%5B0%5D&withTotal=false", httpRequestMessage.RequestUri.ToString());
        }
示例#3
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);
        }
示例#4
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);
        }