public async void QueryAndLimitStagedProductProjections() { var productsCount = 3; await WithProductType(client, async productType => { await WithListOfProducts(client, productDraft => DefaultProductDraftWithProductType(productDraft, productType), productsCount, async products => { Assert.Equal(productsCount, products.Count); var stagedAdditionalParameters = new ProductProjectionAdditionalParameters { Staged = true }; var queryCommand = new QueryCommand <ProductProjection>(stagedAdditionalParameters); queryCommand.Where(productProjection => productProjection.ProductType.Id == productType.Id.valueOf()); queryCommand.SetLimit(2); queryCommand.SetWithTotal(true); //Assert await AssertEventuallyAsync(async() => { var returnedSet = await client.ExecuteAsync(queryCommand); Assert.Equal(2, returnedSet.Results.Count); Assert.Equal(3, returnedSet.Total); }); }); }); }
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); }); }); }
public async Task QueryCategoriesByParentAndOffset() { var count = 3; await WithCategory(client, async parentCategory => { await WithListOfCategories( client, categoryDraft => DefaultCategoryDraftWithParent(categoryDraft, parentCategory), count, async categoriesList => { var offset = count - 1; Assert.Equal(count, categoriesList.Count); var queryCommand = new QueryCommand <Category>(); queryCommand.Where(c => c.Parent.Id == parentCategory.Id.valueOf()); queryCommand.SetOffset(offset); queryCommand.SetWithTotal(true); var returnedSet = await client.ExecuteAsync(queryCommand); Assert.Equal(count - offset, returnedSet.Results.Count); Assert.Equal(count - offset, returnedSet.Count); Assert.Equal(offset, returnedSet.Offset); Assert.Equal(count, returnedSet.Total); }); }); }
public void QueryAndOffsetStagedProductProjections() { //Arrange IClient commerceToolsClient = this.productProjectionsFixture.GetService <IClient>(); ProductType productType = this.productProjectionsFixture.productFixture.CreateNewProductType(); for (int i = 0; i < 3; i++) { Product stagedProduct = this.productProjectionsFixture.productFixture.CreateProduct(productType, true); this.productProjectionsFixture.productFixture.ProductsToDelete.Add(stagedProduct); } //Act ProductProjectionAdditionalParameters stagedAdditionalParameters = new ProductProjectionAdditionalParameters(); stagedAdditionalParameters.Staged = true; //Retrieve Products with created productType QueryCommand <ProductProjection> queryCommand = new QueryCommand <ProductProjection>(stagedAdditionalParameters); queryCommand.Where(productProjection => productProjection.ProductType.Id == productType.Id.valueOf()); queryCommand.SetOffset(2); queryCommand.SetWithTotal(true); PagedQueryResult <ProductProjection> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result; //Assert Assert.Single(returnedSet.Results); Assert.Equal(3, returnedSet.Total); }
public void QueryAndOffsetCategory() { 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; QueryCommand <Category> queryCommand = new QueryCommand <Category>(); queryCommand.Where(c => c.Parent.Id == id); queryCommand.SetOffset(2); queryCommand.SetWithTotal(true); PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result; Assert.Single(returnedSet.Results); Assert.Equal(3, returnedSet.Total); }