public async Task ProductSuggestWithNoTokenizerWithNoResults()
        {
            await WithSuggestProduct(client, async product =>
            {
                Assert.NotEmpty(product.MasterData.Staged.SearchKeywords);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords.Keys.Count);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords["en"].Count);
                var multiToolSearchKeyword = product.MasterData.Staged.SearchKeywords["en"]
                                             .FirstOrDefault(keyword => keyword.Text.StartsWith("Multi"));
                Assert.NotNull(multiToolSearchKeyword);

                //Arrange
                var searchKeyword = new LocalizedString {
                    { "en", "tool" }
                };
                var suggestParams  = new SuggestQueryCommandParameters(searchKeyword);
                var suggestCommand = new SuggestQueryCommand <ProductSuggestion>(suggestParams);

                await AssertEventuallyAsync(async() =>
                {
                    //Act
                    var suggestionResult = await client.ExecuteAsync(suggestCommand);

                    //Assert
                    Assert.Single(suggestionResult.Suggestions);
                    Assert.Empty(suggestionResult.Suggestions["en"]);
                }
                                            );
            });
        }
        public async Task ProductSuggestWithWhitespaceTokenizer()
        {
            await WithSuggestProduct(client, async product =>
            {
                Assert.NotEmpty(product.MasterData.Staged.SearchKeywords);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords.Keys.Count);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords["en"].Count);
                var swissArmyKnifeSearchKeyword = product.MasterData.Staged.SearchKeywords["en"]
                                                  .FirstOrDefault(keyword =>
                                                                  keyword.SuggestTokenizer != null &&
                                                                  keyword.SuggestTokenizer.GetType() == typeof(WhitespaceTokenizer));

                Assert.NotNull(swissArmyKnifeSearchKeyword);

                //Arrange
                var searchKeyword = new LocalizedString {
                    { "en", "kni" }
                };
                var suggestParams  = new SuggestQueryCommandParameters(searchKeyword);
                var suggestCommand = new SuggestQueryCommand <ProductSuggestion>(suggestParams);

                await AssertEventuallyAsync(async() =>
                {
                    //Act
                    var suggestionResult = await client.ExecuteAsync(suggestCommand);

                    //Assert
                    Assert.Single(suggestionResult.Suggestions);
                    var productSuggestions = suggestionResult.Suggestions["en"];
                    Assert.Single(productSuggestions);
                    Assert.Equal(swissArmyKnifeSearchKeyword.Text, productSuggestions[0].Text);
                }
                                            );
            });
        }
        public async Task ProductSuggestWithCustomTokenizer()
        {
            await WithSuggestProduct(client, async product =>
            {
                Assert.NotEmpty(product.MasterData.Staged.SearchKeywords);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords.Keys.Count);
                Assert.Single(product.MasterData.Staged.SearchKeywords["de"]);
                var schweizerSearchKeyword = product.MasterData.Staged.SearchKeywords["de"].FirstOrDefault();

                Assert.NotNull(schweizerSearchKeyword);

                //Arrange
                var searchKeyword = new LocalizedString {
                    { "de", "offiz" }
                };
                var suggestParams  = new SuggestQueryCommandParameters(searchKeyword);
                var suggestCommand = new SuggestQueryCommand <ProductSuggestion>(suggestParams);

                await AssertEventuallyAsync(async() =>
                {
                    //Act
                    var suggestionResult = await client.ExecuteAsync(suggestCommand);

                    //Assert
                    Assert.Single(suggestionResult.Suggestions);
                    var productSuggestions = suggestionResult.ToSuggestionList("de").ToList();
                    Assert.Single(productSuggestions);
                    Assert.Equal(schweizerSearchKeyword.Text, productSuggestions[0]);
                }
                                            );
            });
        }
Example #4
0
        private Uri GetRequestUri <T>(SuggestQueryCommand <T> command)
            where T : ISuggestion
        {
            string requestUri = this.GetMessageBase <T>();
            List <KeyValuePair <string, string> > queryStringParameters = new List <KeyValuePair <string, string> >();

            if (command.QueryParameters != null)
            {
                IQueryParametersBuilder queryParametersBuilder = this.queryParametersBuilderFactory.GetParameterBuilder(command.QueryParameters);
                queryStringParameters.AddRange(queryParametersBuilder.GetQueryParameters(command.QueryParameters));
            }

            queryStringParameters.ForEach(x => { requestUri = QueryHelpers.AddQueryString(requestUri, x.Key, x.Value); });
            return(new Uri(requestUri, UriKind.Relative));
        }
        public async Task ProductSuggestWithTwoLanguages()
        {
            await WithSuggestProduct(client, async product =>
            {
                Assert.NotEmpty(product.MasterData.Staged.SearchKeywords);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords.Keys.Count);
                Assert.Equal(2, product.MasterData.Staged.SearchKeywords["en"].Count);
                Assert.Single(product.MasterData.Staged.SearchKeywords["de"]);

                var multiToolSearchKeyword = product.MasterData.Staged.SearchKeywords["en"]
                                             .FirstOrDefault(keyword => keyword.Text.StartsWith("Multi"));
                var schweizerSearchKeyword = product.MasterData.Staged.SearchKeywords["de"].FirstOrDefault();

                Assert.NotNull(multiToolSearchKeyword);
                Assert.NotNull(schweizerSearchKeyword);

                //Arrange
                var searchKeyword = new LocalizedString {
                    { "de", "offiz" }, { "en", "multi" }
                };
                var suggestParams  = new SuggestQueryCommandParameters(searchKeyword);
                var suggestCommand = new SuggestQueryCommand <ProductSuggestion>(suggestParams);

                await AssertEventuallyAsync(async() =>
                {
                    //Act
                    var suggestionResult = await client.ExecuteAsync(suggestCommand);

                    //Assert
                    Assert.Equal(2, suggestionResult.Suggestions.Count);

                    var englishProductSuggestions = suggestionResult.Suggestions["en"];
                    var germanyProductSuggestions = suggestionResult.Suggestions["de"];

                    Assert.Single(englishProductSuggestions);
                    Assert.Single(germanyProductSuggestions);
                    Assert.Equal(schweizerSearchKeyword.Text, germanyProductSuggestions[0].Text);
                    Assert.Equal(multiToolSearchKeyword.Text, englishProductSuggestions[0].Text);
                }
                                            );
            });
        }
Example #6
0
 public HttpRequestMessage GetRequestMessage <T>(SuggestQueryCommand <T> command)
     where T : ISuggestion
 {
     return(this.GetRequestMessage <T>(this.GetRequestUri <T>(command), null, HttpMethod));
 }
Example #7
0
 public SuggestQueryHttpApiCommand(SuggestQueryCommand <T> command, IRequestMessageBuilderFactory requestMessageBuilderFactory)
 {
     this.command        = command;
     this.requestBuilder = requestMessageBuilderFactory.GetRequestMessageBuilder <SuggestQueryRequestMessageBuilder>();
 }