public void SearchPropertyNameUtility_OrderBy()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.IsNull(searchOptionsBuilder.OrderBy);

            searchOptionsBuilder.WithOrderBy(_ => SearchFns.Score()).WithThenByDescending(_ => SearchFns.Score());

            Assert.IsNotNull(searchOptionsBuilder.OrderBy);
            Assert.AreEqual(2, searchOptionsBuilder.OrderBy.Count());
            Assert.AreEqual("search.score() asc", searchOptionsBuilder.OrderBy.ElementAtOrDefault(0));
            Assert.AreEqual("search.score() desc", searchOptionsBuilder.OrderBy.ElementAtOrDefault(1));

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.IsNotNull(Options.OrderBy);
            Assert.AreEqual(2, Options.OrderBy.Count());
            Assert.AreEqual("search.score() asc", Options.OrderBy.ElementAtOrDefault(0));
            Assert.AreEqual("search.score() desc", Options.OrderBy.ElementAtOrDefault(1));

            searchOptionsBuilder.WithOrderByDescending(_ => SearchFns.Score()).WithThenBy(_ => SearchFns.Score());

            Assert.IsNotNull(searchOptionsBuilder.OrderBy);
            Assert.AreEqual(2, searchOptionsBuilder.OrderBy.Count());
            Assert.AreEqual("search.score() desc", searchOptionsBuilder.OrderBy.ElementAtOrDefault(0));
            Assert.AreEqual("search.score() asc", searchOptionsBuilder.OrderBy.ElementAtOrDefault(1));

            Options = searchOptionsBuilder.Build();
            Assert.IsNotNull(Options);
            Assert.IsNotNull(Options.OrderBy);
            Assert.AreEqual(2, Options.OrderBy.Count());
            Assert.AreEqual("search.score() desc", Options.OrderBy.ElementAtOrDefault(0));
            Assert.AreEqual("search.score() asc", Options.OrderBy.ElementAtOrDefault(1));
        }
Beispiel #2
0
        public ProductSearchServiceTests()
        {
            this.searchManager          = Substitute.For <ISearchService>();
            this.searchMapper           = Substitute.For <ISearchMapper>();
            this.searchOptionsBuilder   = Substitute.For <ISearchOptionsBuilder>();
            this.searchSettingsProvider = Substitute.For <ISearchSettingsProvider>();

            this.service = new ProductSearchService(
                this.searchSettingsProvider,
                this.searchOptionsBuilder,
                this.searchManager,
                this.searchMapper);
            this.fixture = new Fixture();
        }
        public void SearchPropertyNameUtility_IncludeTotalResultCount()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.IsFalse(searchOptionsBuilder.IncludeTotalCount);

            searchOptionsBuilder.WithIncludeTotalCount(true);

            Assert.IsTrue(searchOptionsBuilder.IncludeTotalCount);

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.IsTrue(Options.IncludeTotalCount);
        }
        public void SearchPropertyNameUtility_SearchMode()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.AreEqual(SearchMode.Any, searchOptionsBuilder.SearchMode);

            searchOptionsBuilder.WithSearchMode(SearchMode.All);

            Assert.AreEqual(SearchMode.All, searchOptionsBuilder.SearchMode);

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.AreEqual(SearchMode.All, Options.SearchMode);
        }
        public void SearchPropertyNameUtility_Skip()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.IsNull(searchOptionsBuilder.Skip);

            searchOptionsBuilder.WithSkip(1);

            Assert.IsNotNull(searchOptionsBuilder.Skip);
            Assert.AreEqual(1, searchOptionsBuilder.Skip);

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.AreEqual(1, Options.Skip);
        }
        public void SearchPropertyNameUtility_ScoringProfile()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.IsNull(searchOptionsBuilder.ScoringProfile);

            searchOptionsBuilder.WithScoringProfile("test");

            Assert.IsNotNull(searchOptionsBuilder.ScoringProfile);
            Assert.AreEqual("test", searchOptionsBuilder.ScoringProfile);

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.AreEqual("test", Options.ScoringProfile);
        }
        public ProductSearchService(
            ISearchSettingsProvider searchSettingsProvider,
            ISearchOptionsBuilder searchOptionsBuilder,
            ISearchService searchService,
            ISearchMapper searchMapper)
        {
            Assert.ArgumentNotNull(searchSettingsProvider, nameof(searchSettingsProvider));
            Assert.ArgumentNotNull(searchOptionsBuilder, nameof(searchOptionsBuilder));
            Assert.ArgumentNotNull(searchService, nameof(searchService));
            Assert.ArgumentNotNull(searchMapper, nameof(searchMapper));

            this.searchSettingsProvider = searchSettingsProvider;
            this.searchOptionsBuilder   = searchOptionsBuilder;
            this.searchService          = searchService;
            this.searchMapper           = searchMapper;
        }
        public void SearchPropertyNameUtility_ScoringParameters()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.IsNull(searchOptionsBuilder.ScoringParameters);

            searchOptionsBuilder.WithScoringParameter("foo");

            Assert.IsNotNull(searchOptionsBuilder.ScoringParameters);
            Assert.AreEqual(1, searchOptionsBuilder.ScoringParameters.Count());

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.IsNotNull(Options.ScoringParameters);
            Assert.AreEqual(1, Options.ScoringParameters.Count());
        }
        public void SearchPropertyNameUtility_HighlightFields()
        {
            ISearchOptionsBuilder <Model> searchOptionsBuilder = SearchOptionsBuilder <Model> .Create(__jsonSerializerSettings);

            Assert.IsNull(searchOptionsBuilder.HighlightFields);

            searchOptionsBuilder.WithHighlightField(_ => SearchFns.Score());

            Assert.IsNotNull(searchOptionsBuilder.HighlightFields);
            Assert.AreEqual(1, searchOptionsBuilder.HighlightFields.Count());
            Assert.AreEqual("search.score()", searchOptionsBuilder.HighlightFields.ElementAtOrDefault(0));

            SearchOptions Options = searchOptionsBuilder.Build();

            Assert.IsNotNull(Options);
            Assert.IsNotNull(Options.HighlightFields);
            Assert.AreEqual(1, Options.HighlightFields.Count());
            Assert.AreEqual("search.score()", Options.HighlightFields.ElementAtOrDefault(0));
        }
Beispiel #10
0
 public SearchOptionsBuilderTests()
 {
     this.searchMapper = Substitute.For <ISearchMapper>();
     this.fixture      = new Fixture();
     this.builder      = new SearchOptionsBuilder(this.searchMapper);
 }