|
| 1 | +using System; |
| 2 | +using System.Net; |
| 3 | +using Elasticsearch.Net.Connection; |
| 4 | +using Elasticsearch.Net.ConnectionPool; |
| 5 | +using FluentAssertions; |
| 6 | +using Nest.Tests.MockData.Domain; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +namespace Nest.Tests.Unit.Search.Suggest |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class SuggestUrlTest |
| 13 | + { |
| 14 | + private void TestUrl(string expected, Func<SuggestDescriptor<ElasticsearchProject>, SuggestDescriptor<ElasticsearchProject>> descriptor, ConnectionSettings settings = null) |
| 15 | + { |
| 16 | + var client = new ElasticClient(settings, new InMemoryConnection()); |
| 17 | + var response = client.Suggest(descriptor); |
| 18 | + var uri = new Uri(response.ConnectionStatus.RequestUrl); |
| 19 | + var actual = WebUtility.UrlDecode(uri.AbsolutePath); |
| 20 | + actual.Should().Be(expected); |
| 21 | + } |
| 22 | + |
| 23 | + [Test] |
| 24 | + public void Suggest_to_all_url_test() |
| 25 | + { |
| 26 | + TestUrl( |
| 27 | + expected: "/_all/_suggest", |
| 28 | + descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)).AllIndices() |
| 29 | + ); |
| 30 | + } |
| 31 | + |
| 32 | + [Test] |
| 33 | + public void Suggest_to_specific_index_url_test() |
| 34 | + { |
| 35 | + var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://esserver.com"))); |
| 36 | + |
| 37 | + settings.MapDefaultTypeIndices(d => d |
| 38 | + .Add(typeof (ElasticsearchProject), typeof (ElasticsearchProject).Name.ToLower())); |
| 39 | + |
| 40 | + TestUrl( |
| 41 | + expected: "/elasticsearchproject/_suggest", |
| 42 | + descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)), |
| 43 | + settings: settings |
| 44 | + ); |
| 45 | + } |
| 46 | + |
| 47 | + [Test] |
| 48 | + public void Suggest_to_specific_index_specified_in_descriptor_url_test() |
| 49 | + { |
| 50 | + var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://esserver.com"))); |
| 51 | + |
| 52 | + settings.MapDefaultTypeIndices(d => d |
| 53 | + .Add(typeof (ElasticsearchVersionInfo), "elasticsearchproject")); |
| 54 | + |
| 55 | + TestUrl( |
| 56 | + expected: "/elasticsearchproject/_suggest", |
| 57 | + descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)).Index<ElasticsearchVersionInfo>(), |
| 58 | + settings: settings |
| 59 | + ); |
| 60 | + } |
| 61 | + |
| 62 | + [Test] |
| 63 | + public void Suggest_to_specific_index_specified_as_string_in_descriptor_url_test() |
| 64 | + { |
| 65 | + var settings = new ConnectionSettings(new SingleNodeConnectionPool(new Uri("http://esserver.com"))); |
| 66 | + |
| 67 | + TestUrl( |
| 68 | + expected: "/anotherindex/_suggest", |
| 69 | + descriptor: d => d.Term("name", s => s.OnField(f => f.Contributors)).Index("anotherindex") |
| 70 | + ); |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments