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 void QueryAndLimitStagedProductProjections() { //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 limited by 2 QueryCommand <ProductProjection> queryCommand = new QueryCommand <ProductProjection>(stagedAdditionalParameters); queryCommand.Where(productProjection => productProjection.ProductType.Id == productType.Id.valueOf()); queryCommand.SetLimit(2); queryCommand.SetWithTotal(true); PagedQueryResult <ProductProjection> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result; //Assert Assert.Equal(2, returnedSet.Results.Count); Assert.Equal(3, returnedSet.Total); }
public async Task GetMessageById() { //lets create customer first to ensure message created await WithCustomer(client, async customer => { var queryCommand = new QueryCommand <Message>(); queryCommand.SetLimit(1); await AssertEventuallyAsync(async() => { var returnedSet = await client.ExecuteAsync(queryCommand); Assert.Single(returnedSet.Results); var messageId = returnedSet.Results[0].Id; var retrievedMessage = await client .ExecuteAsync(new GetByIdCommand <Message>(messageId)); Assert.NotNull(retrievedMessage); } ); }); }
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; QueryCommand <Category> queryCommand = new QueryCommand <Category>(); queryCommand.Where(c => c.Parent.Id == id); queryCommand.SetLimit(2); queryCommand.SetWithTotal(true); PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result; Assert.Equal(2, returnedSet.Results.Count); Assert.Equal(3, returnedSet.Total); }