Ejemplo n.º 1
0
        private void ConfigureAndCreateEntitiesBeforeRunningTests()
        {
            //update current project to support these languages
            var project = this.ChangeProjectLanguages(new List <string> {
                "en", "de"
            });

            Assert.Equal(2, project.Languages.Count);
            Assert.True(project.Languages.Contains("en") && project.Languages.Contains("de"));

            //Fill entities
            this.FillCategories();
            this.FillProducts();
            var allProductIds = AvailableProducts.Select(product => product.Id).ToArray();

            var searchRequest = new SearchProductProjectionsCommand();

            searchRequest.SetStaged(true);
            searchRequest.FilterQuery(p => p.Id.In(allProductIds));
            IClient commerceToolsClient = this.GetService <IClient>();

            //wait till elastic search index refreshed with created products
            AssertEventually(() =>
            {
                var searchResults = commerceToolsClient.ExecuteAsync(searchRequest).Result;
                Assert.Equal(allProductIds.Length, searchResults.Results.Count);
            });
        }
        /// <summary>
        /// check if all the products used in search tests are indexed
        /// </summary>
        /// <returns>true if the products used in search tests are indexed</returns>
        private bool CheckIfProductsIndexed()
        {
            if (AvailableProductType == null)
            {
                return(false);
            }

            var searchRequest = new SearchProductProjectionsCommand();

            searchRequest.SetStaged(SearchForStaged);
            searchRequest.FilterQuery(p => p.ProductType.Id == AvailableProductType.Id.valueOf());
            var searchResults = client.ExecuteAsync(searchRequest).Result;
            var indexed       = searchResults.Count >= ExpectedProductsCount;

            if (indexed)
            {
                AvailableProducts = searchResults.Results;
            }

            return(indexed);
        }