public async void QueryAndSortStagedProductProjections() { 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.Sort(p => p.Name["en"]); var returnedSet = await client.ExecuteAsync(queryCommand); var sortedList = returnedSet.Results.OrderBy(p => p.Name["en"]); Assert.True(sortedList.SequenceEqual(returnedSet.Results)); }); }); }
public void QueryAndSortStagedProductProjections() { //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 sorted by name QueryCommand <ProductProjection> queryCommand = new QueryCommand <ProductProjection>(stagedAdditionalParameters); queryCommand.Where(productProjection => productProjection.ProductType.Id == productType.Id.valueOf()); queryCommand.Sort(p => p.Name["en"]); PagedQueryResult <ProductProjection> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result; var sortedList = returnedSet.Results.OrderBy(p => p.Name["en"]); //Assert Assert.True(sortedList.SequenceEqual(returnedSet.Results)); }
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)); }); }); }
public void GetQueryRequestMessageWithSort() { QueryCommand <Message> queryCommand = new QueryCommand <Message>(); queryCommand.Sort(message => message.Id).Sort(message => message.CreatedAt, SortDirection.Descending); 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("messages?sort=id%20asc&sort=createdAt%20desc&withTotal=false", httpRequestMessage.RequestUri.ToString()); }
public void QueryAndSortCategory() { 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.Sort(c => c.Name["en"]); queryCommand.Where(c => c.Parent.Id == id); PagedQueryResult <Category> returnedSet = commerceToolsClient.ExecuteAsync(queryCommand).Result; var sortedList = returnedSet.Results.OrderBy(c => c.Name["en"]); Assert.True(sortedList.SequenceEqual(returnedSet.Results)); }