Exemple #1
0
        public async Task QueryCategoriesByParentAndLimit()
        {
            var count = 3;

            await WithCategory(client, async parentCategory =>
            {
                await WithListOfCategories(
                    client, categoryDraft => DefaultCategoryDraftWithParent(categoryDraft, parentCategory), count,
                    async categoriesList =>
                {
                    var limit = count - 1;
                    Assert.Equal(count, categoriesList.Count);
                    var queryCommand = new QueryCommand <Category>();
                    queryCommand.Where(c => c.Parent.Id == parentCategory.Id.valueOf());
                    queryCommand.Expand(c => c.Parent);
                    queryCommand.SetLimit(limit);
                    queryCommand.SetWithTotal(true);

                    var returnedSet = await client.ExecuteAsync(queryCommand);
                    Assert.Equal(limit, returnedSet.Count);
                    Assert.Equal(limit, returnedSet.Limit);
                    Assert.Equal(count, returnedSet.Total);

                    var categoriesResult = returnedSet.Results;
                    Assert.NotNull(categoriesList[0].Parent);
                    Assert.Equal(parentCategory.Id, categoriesResult[0].Parent.Id);
                });
            });
        }
Exemple #2
0
        public async Task QueryCategoriesByParentAndSortDescending()
        {
            var count = 3;

            await WithCategory(client, async parentCategory =>
            {
                await WithListOfCategories(
                    client, categoryDraft => DefaultCategoryDraftWithParent(categoryDraft, parentCategory), count,
                    async categoriesList =>
                {
                    Assert.Equal(count, categoriesList.Count);
                    var orderedCategoriesNames = categoriesList.OrderByDescending(c => c.Name["en"])
                                                 .Select(c => c.Name["en"]).ToList();
                    var queryCommand = new QueryCommand <Category>();
                    queryCommand.Where(c => c.Parent.Id == parentCategory.Id.valueOf());
                    queryCommand.Expand(c => c.Parent);
                    queryCommand.Sort(c => c.Name["en"], SortDirection.Descending);
                    var returnedSet      = await client.ExecuteAsync(queryCommand);
                    var categoriesResult = returnedSet.Results;
                    Assert.Equal(count, categoriesResult.Count);
                    Assert.NotNull(categoriesList[0].Parent);
                    Assert.Equal(parentCategory.Id, categoriesResult[0].Parent.Id);
                    var returnedCategoriesNames = categoriesResult.Select(c => c.Name["en"]).ToList();
                    Assert.True(returnedCategoriesNames.SequenceEqual(orderedCategoriesNames));
                });
            });
        }
Exemple #3
0
 public async Task QueryCategoryByParentAndExpandIt()
 {
     await WithCategory(client, async parentCategory =>
     {
         await WithCategory(
             client, categoryDraft => DefaultCategoryDraftWithParent(categoryDraft, parentCategory),
             async category =>
         {
             var queryCommand = new QueryCommand <Category>();
             queryCommand.Where(c => c.Parent.Id == parentCategory.Id.valueOf());
             var returnedSet = await client.ExecuteAsync(queryCommand.Expand(c => c.Parent));
             Assert.Single(returnedSet.Results);
             var retrievedCategory = returnedSet.Results[0];
             Assert.Equal(category.Key, retrievedCategory.Key);
             Assert.NotNull(retrievedCategory.Parent);
             Assert.Equal(parentCategory.Id, retrievedCategory.Parent.Id);
         });
     });
 }
Exemple #4
0
        public void QueryAndExpandParents()
        {
            //Arrange
            IClient     commerceToolsClient = this.productProjectionsFixture.GetService <IClient>();
            ProductType productType         = this.productProjectionsFixture.productFixture.CreateNewProductType();
            var         publishedProduct    =
                this.productProjectionsFixture.productFixture.CreateProduct(productType, true, true);

            //Act
            QueryCommand <ProductProjection> queryCommand = new QueryCommand <ProductProjection>();

            queryCommand.Where(productProjection => productProjection.ProductType.Id == productType.Id.valueOf());
            queryCommand.Expand(p => p.ProductType).Expand(p => p.Categories.ExpandAll());
            PagedQueryResult <ProductProjection> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result;

            this.productProjectionsFixture.productFixture.ProductsToDelete.Add(publishedProduct);

            //Assert
            Assert.NotNull(returnedSet.Results);
            Assert.Contains(returnedSet.Results,
                            pp => pp.Id == publishedProduct.Id && pp.ProductType.Obj != null && pp.Categories.Count == 1 &&
                            pp.Categories[0].Obj != null);
        }
        public async void QueryAndExpandParents()
        {
            await WithCategory(client, async category =>
            {
                await WithProductType(client, async productType =>
                {
                    await WithProduct(
                        client, draft =>
                    {
                        var productDraft     = DefaultProductDraftWithProductType(draft, productType);
                        productDraft         = DefaultProductDraftWithCategory(productDraft, category);
                        productDraft.Publish = true;
                        return(productDraft);
                    },
                        async publishedProduct =>
                    {
                        Assert.True(publishedProduct.MasterData.Published);
                        Assert.NotNull(publishedProduct.ProductType);
                        Assert.NotEmpty(publishedProduct.MasterData.Current.Categories);

                        var queryCommand = new QueryCommand <ProductProjection>();
                        queryCommand.Where(productProjection =>
                                           productProjection.ProductType.Id == productType.Id.valueOf());
                        queryCommand.Expand(p => p.ProductType)
                        .Expand(p => p.Categories.ExpandAll());

                        var returnedSet = await client.ExecuteAsync(queryCommand);
                        Assert.NotNull(returnedSet.Results);
                        Assert.Contains(returnedSet.Results,
                                        pp => pp.Id == publishedProduct.Id && pp.ProductType.Obj != null &&
                                        pp.Categories.Count == 1 &&
                                        pp.Categories[0].Obj != null);
                    });
                });
            });
        }