|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Collections.Specialized; |
| 4 | +using System.Linq; |
| 5 | +using Nest.Tests.MockData; |
| 6 | +using Nest.Tests.MockData.Domain; |
| 7 | +using NUnit.Framework; |
| 8 | + |
| 9 | +namespace Nest.Tests.Integration.Index |
| 10 | +{ |
| 11 | + [TestFixture] |
| 12 | + public class IndexUsingUrlIdTests : IntegrationTests |
| 13 | + { |
| 14 | + [Test] |
| 15 | + public void IndexUsingAnUrlAsId() |
| 16 | + { |
| 17 | + var id = "http://www.skusuplier.com/products/123?affiliateId=23131#oopsIcopiedAnAnchor"; |
| 18 | + var newProduct = new Product |
| 19 | + { |
| 20 | + Id = id, |
| 21 | + Name = "Top Product" |
| 22 | + }; |
| 23 | + var response = this._client.Index(newProduct); |
| 24 | + |
| 25 | + var productInElasticsearch = this._client.Get<Product>(id); |
| 26 | + Assert.NotNull(productInElasticsearch); |
| 27 | + Assert.AreEqual(productInElasticsearch.Id, id); |
| 28 | + Assert.True(response.IsValid); |
| 29 | + } |
| 30 | + |
| 31 | + |
| 32 | + [Test] |
| 33 | + public void IndexUsingAnUrlAsIdUsingCustomUrlParameterInSettings() |
| 34 | + { |
| 35 | + var settings = ElasticsearchConfiguration.Settings().SetGlobalQueryStringParameters(new NameValueCollection |
| 36 | + { |
| 37 | + {"apiKey", "my-api-key"} |
| 38 | + }); |
| 39 | + var client = new ElasticClient(settings); |
| 40 | + |
| 41 | + var id = "http://www.skusuplier.com/products/123?affiliateId=23131#oopsIcopiedAnAnchor"; |
| 42 | + var newProduct = new Product |
| 43 | + { |
| 44 | + Id = id, |
| 45 | + Name = "Top Product" |
| 46 | + }; |
| 47 | + var response = client.Index(newProduct); |
| 48 | + |
| 49 | + var productInElasticsearch = client.Get<Product>(id); |
| 50 | + Assert.NotNull(productInElasticsearch); |
| 51 | + Assert.AreEqual(productInElasticsearch.Id, id); |
| 52 | + Assert.True(response.IsValid); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments