|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Reflection; |
| 5 | +using Elasticsearch.Net; |
| 6 | +using FluentAssertions; |
| 7 | +using Nest.Tests.MockData.Domain; |
| 8 | +using NUnit.Framework; |
| 9 | + |
| 10 | +namespace Nest.Tests.Unit.Reproduce |
| 11 | +{ |
| 12 | + /// <summary> |
| 13 | + /// tests to reproduce reported errors |
| 14 | + /// </summary> |
| 15 | + [TestFixture] |
| 16 | + public class Reproduce1320Tests : BaseJsonTests |
| 17 | + { |
| 18 | + [Test] |
| 19 | + public void IdShouldBeInferred() |
| 20 | + { |
| 21 | + var products = Enumerable.Range(0, 100) |
| 22 | + .Select(i => new ProductES { Id = i }); |
| 23 | + var descriptor = new BulkDescriptor(); |
| 24 | + descriptor.FixedPath("products", "product"); |
| 25 | + foreach (var item in products) |
| 26 | + { |
| 27 | + descriptor.Index<ProductES>(op => op |
| 28 | + .Document(item) |
| 29 | + .Index("products") |
| 30 | + .Type("product") |
| 31 | + ); |
| 32 | + } |
| 33 | + |
| 34 | + var result = this._client.Bulk(d => descriptor); |
| 35 | + var index = result.ConnectionStatus.Request.Utf8String(); |
| 36 | + foreach (var id in Enumerable.Range(0, 100)) |
| 37 | + index.Should().Contain(string.Format(@"""_id"":""{0}""}}", id)); |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + [ElasticType(IdProperty = "Id")] |
| 42 | + public class ProductES |
| 43 | + { |
| 44 | + public ProductES() |
| 45 | + { |
| 46 | + ProductTag = 1; |
| 47 | + Created = DateTime.UtcNow; |
| 48 | + Modified = DateTime.UtcNow; |
| 49 | + Origin = "*"; |
| 50 | + } |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// The unique product id, will be assigned by the database |
| 54 | + /// </summary> |
| 55 | + public long Id { get; set; } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// If the product was importned from an external system this is the ID to map against |
| 59 | + /// </summary> |
| 60 | + public string ExternalId { get; set; } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// The origin (owner of the object)... |
| 64 | + /// * = global |
| 65 | + /// <![CDATA[<instance> - Instance record]]> |
| 66 | + /// <![CDATA[<instance>_<site> - Site record]]> |
| 67 | + /// <![CDATA[<instance>_<site>_<customerGroupNo> - Customer group record]]> |
| 68 | + /// <![CDATA[<instance>_<site>_<customerGroupNo>_<customerNo> - Customer record]]> |
| 69 | + /// </summary> |
| 70 | + public string Origin { get; set; } |
| 71 | + |
| 72 | + /// <summary> |
| 73 | + /// Unique URI name, to browse to the product |
| 74 | + /// </summary> |
| 75 | + public string URIName { get; set; } |
| 76 | + |
| 77 | + /// <summary> |
| 78 | + /// The name of the product, etc Apple iPhone 6, Samsung Galaxy 4S |
| 79 | + /// </summary> |
| 80 | + public string Name { get; set; } |
| 81 | + |
| 82 | + /// <summary> |
| 83 | + /// The brand: Apple, Samsung |
| 84 | + /// </summary> |
| 85 | + public string Brand { get; set; } |
| 86 | + |
| 87 | + //public ProductType ProductType { get; set; } |
| 88 | + public int ProductTag { get; set; } |
| 89 | + |
| 90 | + /// <summary> |
| 91 | + /// If active we'll export the record to the web shops |
| 92 | + /// </summary> |
| 93 | + public bool Active { get; set; } |
| 94 | + |
| 95 | + /// <summary> |
| 96 | + /// Defines the image attached to the product, can be inhiert from parent |
| 97 | + /// </summary> |
| 98 | + public string Image { get; set; } |
| 99 | + |
| 100 | + /// <summary> |
| 101 | + /// The UTC date when the record was created |
| 102 | + /// </summary> |
| 103 | + public System.DateTime Created { get; set; } |
| 104 | + |
| 105 | + /// <summary> |
| 106 | + /// The UTC date when the record was modified |
| 107 | + /// </summary> |
| 108 | + public System.DateTime Modified { get; set; } |
| 109 | + } |
| 110 | +} |
0 commit comments