|
| 1 | +using FluentAssertions; |
| 2 | +using Elasticsearch.Net.Connection; |
| 3 | +using Nest.Tests.MockData.Domain; |
| 4 | +using NUnit.Framework; |
| 5 | +using System; |
| 6 | +using System.Collections.Generic; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using System.Net; |
| 11 | + |
| 12 | +namespace Nest.Tests.Unit.Search |
| 13 | +{ |
| 14 | + [TestFixture] |
| 15 | + public class SearchUrlTests |
| 16 | + { |
| 17 | + private void TestUrl(string expected, SearchDescriptor<ElasticsearchProject> descriptor, ConnectionSettings settings = null) |
| 18 | + { |
| 19 | + var client = new ElasticClient(settings, new InMemoryConnection()); |
| 20 | + var response = client.Search<ElasticsearchProject>(descriptor); |
| 21 | + var uri = new Uri(response.ConnectionStatus.RequestUrl); |
| 22 | + var actual = WebUtility.UrlDecode(uri.AbsolutePath); |
| 23 | + actual.Should().Be(expected); |
| 24 | + } |
| 25 | + |
| 26 | + [Test] |
| 27 | + public void AllIndices_AllTypes_Test() |
| 28 | + { |
| 29 | + TestUrl( |
| 30 | + expected: "/_search", |
| 31 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 32 | + .AllIndices() |
| 33 | + .AllTypes() |
| 34 | + ); |
| 35 | + } |
| 36 | + |
| 37 | + [Test] |
| 38 | + public void AllIndices_ExplicitType_Test() |
| 39 | + { |
| 40 | + TestUrl( |
| 41 | + expected: "/_all/type1/_search", |
| 42 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 43 | + .AllIndices() |
| 44 | + .Type("type1") |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + [Test] |
| 49 | + public void AllIndices_MultipleExplicitTypes_Test() |
| 50 | + { |
| 51 | + TestUrl( |
| 52 | + expected: "/_all/type1,type2/_search", |
| 53 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 54 | + .AllIndices() |
| 55 | + .Types("type1", "type2") |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + [Test] |
| 60 | + public void AllIndices_InferredType_Test() |
| 61 | + { |
| 62 | + TestUrl( |
| 63 | + expected: "/_all/elasticsearchprojects/_search", |
| 64 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 65 | + .AllIndices() |
| 66 | + ); |
| 67 | + } |
| 68 | + |
| 69 | + [Test] |
| 70 | + public void AllIndices_MappedType_Test() |
| 71 | + { |
| 72 | + TestUrl( |
| 73 | + expected: "/_all/type1/_search", |
| 74 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 75 | + .AllIndices(), |
| 76 | + settings: new ConnectionSettings() |
| 77 | + .MapDefaultTypeNames(m => m |
| 78 | + .Add(typeof(ElasticsearchProject), "type1") |
| 79 | + ) |
| 80 | + ); |
| 81 | + } |
| 82 | + |
| 83 | + [Test] |
| 84 | + public void DefaultIndex_AllIndices_AllTypes_Test() |
| 85 | + { |
| 86 | + TestUrl( |
| 87 | + expected: "/_search", |
| 88 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 89 | + .AllIndices() |
| 90 | + .AllTypes(), |
| 91 | + settings: new ConnectionSettings() |
| 92 | + .SetDefaultIndex("defaultindex") |
| 93 | + ); |
| 94 | + } |
| 95 | + |
| 96 | + [Test] |
| 97 | + public void DefaultIndex_AllTypes_Test() |
| 98 | + { |
| 99 | + TestUrl( |
| 100 | + expected: "/defaultindex/_search", |
| 101 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 102 | + .AllTypes(), |
| 103 | + settings: new ConnectionSettings() |
| 104 | + .SetDefaultIndex("defaultindex") |
| 105 | + ); |
| 106 | + } |
| 107 | + |
| 108 | + [Test] |
| 109 | + public void DefaultIndex_ExplicitType_Test() |
| 110 | + { |
| 111 | + TestUrl( |
| 112 | + expected: "/defaultindex/type1/_search", |
| 113 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 114 | + .Type("type1"), |
| 115 | + settings: new ConnectionSettings() |
| 116 | + .SetDefaultIndex("defaultindex") |
| 117 | + ); |
| 118 | + } |
| 119 | + |
| 120 | + [Test] |
| 121 | + public void DefaultIndex_MultipleExplicitTypes_Test() |
| 122 | + { |
| 123 | + TestUrl( |
| 124 | + expected: "/defaultindex/type1,type2/_search", |
| 125 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 126 | + .Types("type1", "type2"), |
| 127 | + settings: new ConnectionSettings() |
| 128 | + .SetDefaultIndex("defaultindex") |
| 129 | + ); |
| 130 | + } |
| 131 | + |
| 132 | + [Test] |
| 133 | + public void DefaultIndex_InferredType_Test() |
| 134 | + { |
| 135 | + TestUrl( |
| 136 | + expected: "/defaultindex/elasticsearchprojects/_search", |
| 137 | + descriptor: new SearchDescriptor<ElasticsearchProject>(), |
| 138 | + settings: new ConnectionSettings() |
| 139 | + .SetDefaultIndex("defaultindex") |
| 140 | + ); |
| 141 | + } |
| 142 | + |
| 143 | + [Test] |
| 144 | + public void DefaultIndex_MappedType_Test() |
| 145 | + { |
| 146 | + TestUrl( |
| 147 | + expected: "/defaultindex/type1/_search", |
| 148 | + descriptor: new SearchDescriptor<ElasticsearchProject>(), |
| 149 | + settings: new ConnectionSettings() |
| 150 | + .SetDefaultIndex("defaultindex") |
| 151 | + .MapDefaultTypeNames(m => m |
| 152 | + .Add(typeof(ElasticsearchProject), "type1") |
| 153 | + ) |
| 154 | + ); |
| 155 | + } |
| 156 | + |
| 157 | + [Test] |
| 158 | + public void No_DefaultIndex_AllIndices_AllTypes_Test() |
| 159 | + { |
| 160 | + TestUrl( |
| 161 | + expected: "/_search", |
| 162 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 163 | + .AllIndices() |
| 164 | + .AllTypes() |
| 165 | + ); |
| 166 | + } |
| 167 | + |
| 168 | + [Test] |
| 169 | + public void No_DefaultIndex_AllTypes_Test() |
| 170 | + { |
| 171 | + TestUrl( |
| 172 | + expected: "/_search", |
| 173 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 174 | + .AllTypes() |
| 175 | + ); |
| 176 | + } |
| 177 | + |
| 178 | + [Test] |
| 179 | + public void No_DefaultIndex_ExplicitType_Test() |
| 180 | + { |
| 181 | + TestUrl( |
| 182 | + expected: "/_all/type1/_search", |
| 183 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 184 | + .Type("type1") |
| 185 | + ); |
| 186 | + } |
| 187 | + |
| 188 | + [Test] |
| 189 | + public void No_DefaultIndex_MultipleExplicitTypes_Test() |
| 190 | + { |
| 191 | + TestUrl( |
| 192 | + expected: "/_all/type1,type2/_search", |
| 193 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 194 | + .Types("type1", "type2") |
| 195 | + ); |
| 196 | + } |
| 197 | + |
| 198 | + [Test] |
| 199 | + public void No_DefaultIndex_InferredType_Test() |
| 200 | + { |
| 201 | + TestUrl( |
| 202 | + expected: "/_all/elasticsearchprojects/_search", |
| 203 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 204 | + ); |
| 205 | + } |
| 206 | + |
| 207 | + [Test] |
| 208 | + public void No_DefaultIndex_MappedType_Test() |
| 209 | + { |
| 210 | + TestUrl( |
| 211 | + expected: "/_all/type1/_search", |
| 212 | + descriptor: new SearchDescriptor<ElasticsearchProject>(), |
| 213 | + settings: new ConnectionSettings() |
| 214 | + .MapDefaultTypeNames(m => m |
| 215 | + .Add(typeof(ElasticsearchProject), "type1") |
| 216 | + ) |
| 217 | + ); |
| 218 | + } |
| 219 | + |
| 220 | + [Test] |
| 221 | + public void MappedIndex_AllTypes_Test() |
| 222 | + { |
| 223 | + TestUrl( |
| 224 | + expected: "/index1/_search", |
| 225 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 226 | + .AllTypes(), |
| 227 | + settings: new ConnectionSettings() |
| 228 | + .MapDefaultTypeIndices(m => m |
| 229 | + .Add(typeof(ElasticsearchProject), "index1") |
| 230 | + ) |
| 231 | + ); |
| 232 | + } |
| 233 | + |
| 234 | + [Test] |
| 235 | + public void MappedIndex_MappedType_Test() |
| 236 | + { |
| 237 | + TestUrl( |
| 238 | + expected: "/index1/type1/_search", |
| 239 | + descriptor: new SearchDescriptor<ElasticsearchProject>(), |
| 240 | + settings: new ConnectionSettings() |
| 241 | + .MapDefaultTypeIndices(m => m |
| 242 | + .Add(typeof(ElasticsearchProject), "index1") |
| 243 | + ) |
| 244 | + .MapDefaultTypeNames(m => m |
| 245 | + .Add(typeof(ElasticsearchProject), "type1") |
| 246 | + ) |
| 247 | + ); |
| 248 | + } |
| 249 | + |
| 250 | + [Test] |
| 251 | + public void MappedIndex_InferredType_Test() |
| 252 | + { |
| 253 | + TestUrl( |
| 254 | + expected: "/index1/elasticsearchprojects/_search", |
| 255 | + descriptor: new SearchDescriptor<ElasticsearchProject>(), |
| 256 | + settings: new ConnectionSettings() |
| 257 | + .MapDefaultTypeIndices(m => m |
| 258 | + .Add(typeof(ElasticsearchProject), "index1") |
| 259 | + ) |
| 260 | + ); |
| 261 | + } |
| 262 | + |
| 263 | + [Test] |
| 264 | + public void MappedIndex_MultipleExplicitTypes_Test() |
| 265 | + { |
| 266 | + TestUrl( |
| 267 | + expected: "/index1/type1,type2/_search", |
| 268 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 269 | + .Types("type1", "type2"), |
| 270 | + settings: new ConnectionSettings() |
| 271 | + .MapDefaultTypeIndices(m => m |
| 272 | + .Add(typeof(ElasticsearchProject), "index1") |
| 273 | + ) |
| 274 | + ); |
| 275 | + } |
| 276 | + |
| 277 | + [Test] |
| 278 | + public void ExplicitIndex_AllTypes_Test() |
| 279 | + { |
| 280 | + TestUrl( |
| 281 | + expected: "/index1/_search", |
| 282 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 283 | + .Index("index1") |
| 284 | + .AllTypes() |
| 285 | + ); |
| 286 | + } |
| 287 | + |
| 288 | + [Test] |
| 289 | + public void ExplicitIndex_InferredType_Test() |
| 290 | + { |
| 291 | + TestUrl( |
| 292 | + expected: "/index1/elasticsearchprojects/_search", |
| 293 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 294 | + .Index("index1") |
| 295 | + ); |
| 296 | + } |
| 297 | + |
| 298 | + [Test] |
| 299 | + public void ExplicitIndex_ExplicitType_Test() |
| 300 | + { |
| 301 | + TestUrl( |
| 302 | + expected: "/index1/type1/_search", |
| 303 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 304 | + .Index("index1") |
| 305 | + .Type("type1") |
| 306 | + ); |
| 307 | + } |
| 308 | + |
| 309 | + [Test] |
| 310 | + public void ExplicitIndex_MultipleExplicitTypes_Test() |
| 311 | + { |
| 312 | + TestUrl( |
| 313 | + expected: "/index1/type1,type2/_search", |
| 314 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 315 | + .Index("index1") |
| 316 | + .Types("type1", "type2") |
| 317 | + ); |
| 318 | + } |
| 319 | + |
| 320 | + [Test] |
| 321 | + public void MultipleExplicitIndices_MultipleExplicitTypes_Test() |
| 322 | + { |
| 323 | + TestUrl( |
| 324 | + expected: "/index1,index2/type1,type2/_search", |
| 325 | + descriptor: new SearchDescriptor<ElasticsearchProject>() |
| 326 | + .Indices("index1", "index2") |
| 327 | + .Types("type1", "type2") |
| 328 | + ); |
| 329 | + } |
| 330 | + } |
| 331 | +} |
0 commit comments