public void GetTokenCount_Responses( string searchTerm, string language, object[] responseTokens, int expectedCount ) { ElasticsearchInterceptingConnection conn = new ElasticsearchInterceptingConnection(); conn.RegisterRequestHandlerForType <AnalyzeResponse>( (req, res) => { JObject resObject = new JObject(); resObject["tokens"] = JArray.FromObject(responseTokens); byte[] byteArray = Encoding.UTF8.GetBytes(resObject.ToString()); res.Stream = new MemoryStream(byteArray); res.StatusCode = 200; } ); //While this has a URI, it does not matter, an InMemoryConnection never requests //from the server. var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); var connectionSettings = new ConnectionSettings(pool, conn); IElasticClient client = new ElasticClient(connectionSettings); ESTokenAnalyzerService service = new ESTokenAnalyzerService(client, new NullLogger <ESTokenAnalyzerService>()); int actualCount = service.GetTokenCount(searchTerm); Assert.Equal(expectedCount, actualCount); }
private ESBestBetsMatchService GetMatchService(ESTokenAnalyzerService tokenService, IConnection connection) { //While this has a URI, it does not matter, an InMemoryConnection never requests //from the server. var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); var connectionSettings = new ConnectionSettings(pool, connection); IElasticClient client = new ElasticClient(connectionSettings); return(new ESBestBetsMatchService(client, tokenService, new NullLogger <ESBestBetsMatchService>())); }
public void GetMatches_Normal( string searchTerm, string lang, ESMatchConnection connection, ESMatchTokenizerConnection tokenizerConn, string[] expectedCategories ) { //Use real ES client, with mocked connection. ESTokenAnalyzerService tokenService = GetTokenizerService(tokenizerConn); ESBestBetsMatchService service = GetMatchService(tokenService, connection); string[] actualMatches = service.GetMatches(lang, searchTerm); Assert.Equal(expectedCategories, actualMatches); }