示例#1
0
        public async Task GetSemanticSearchSuggestions_WhenTypeNotExists_ThrowsException()
        {
            SetupIndexAndTypeExists(true, false);

            _semanticSearchRepository.Setup(s => s.GetSemanticSearchIndex()).ReturnsAsync("test");

            _elasticSearchEngine = new ElasticSearchEngine(_elasticClient.Object, _semanticSearchRepository.Object);

            await _elasticSearchEngine.GetSemanticSearchSuggestions(new SearchEngineParameters(1, 1, true, null));
        }
示例#2
0
        public async Task GetSemanticSearchSuggestions_WhenIndexNotPopulated_ReturnsEmptyArtifactDetails()
        {
            var searchParameters = new SearchEngineParameters(1, 1, true, new HashSet <int>());

            _semanticSearchRepository.Setup(s => s.GetSemanticSearchIndex()).ReturnsAsync((string)null);

            _elasticSearchEngine = new ElasticSearchEngine(_elasticClient.Object, _semanticSearchRepository.Object);

            var result = await _elasticSearchEngine.GetSemanticSearchSuggestions(searchParameters);

            Assert.IsTrue(result.IsEmpty());
        }
示例#3
0
        public async Task GetSemanticSearchSuggestions_WhenQuerying_ReturnsArtifactDetails()
        {
            var searchParameters = new SearchEngineParameters(1, 1, true, new HashSet <int>());

            _semanticSearchRepository.Setup(s => s.GetSemanticSearchText(It.IsAny <int>(), It.IsAny <int>()))
            .ReturnsAsync(new SemanticSearchText()
            {
                Name       = "test",
                SearchText = "searchTest"
            });
            SetupIndexAndTypeExists(true, true);
            _semanticSearchRepository.Setup(s => s.GetSemanticSearchIndex()).ReturnsAsync("test");

            var searchItemHit = new Mock <IHit <SemanticSearchItem> >();

            searchItemHit.SetupGet(s => s.Id).Returns("2");
            var searchResponse = new Mock <ISearchResponse <SemanticSearchItem> >();

            searchResponse.SetupGet(s => s.Hits).Returns(new List <IHit <SemanticSearchItem> >()
            {
                searchItemHit.Object
            });

            var connectionSettings = new Mock <IConnectionSettingsValues>();

            connectionSettings.SetupGet(c => c.DefaultIndices).Returns(new FluentDictionary <Type, string>());
            _elasticClient.Setup(
                e => e.SearchAsync <SemanticSearchItem>(It.IsAny <ISearchRequest>(), It.IsAny <CancellationToken>()))
            .ReturnsAsync(searchResponse.Object);

            _elasticClient.SetupGet(e => e.ConnectionSettings).Returns(connectionSettings.Object);

            _semanticSearchRepository.Setup(s => s.GetSuggestedArtifactDetails(It.IsAny <List <int> >(), It.IsAny <int>()))
            .ReturnsAsync(new List <ArtifactSearchResult>()
            {
                new ArtifactSearchResult()
                {
                    ItemId = 2
                }
            });

            _elasticSearchEngine = new ElasticSearchEngine(_elasticClient.Object, _semanticSearchRepository.Object);

            var result = await _elasticSearchEngine.GetSemanticSearchSuggestions(searchParameters);

            Assert.IsTrue(result.Count() == 1);
            Assert.IsTrue(result.FirstOrDefault().Id == 2);
        }
 public async Task <IEnumerable <ArtifactSearchResult> > GetSemanticSearchSuggestions(SearchEngineParameters searchEngineParameters)
 {
     return(await _searchEngine.GetSemanticSearchSuggestions(searchEngineParameters));
 }