Skip to content

Commit 389d9dc

Browse files
committed
Showcase what happens in #1528 when no default index is set
1 parent 2dc393c commit 389d9dc

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,17 @@
410410
<Compile Include="QueryParsers\Visitor\DslPrettyPrintVisitor.cs" />
411411
<Compile Include="QueryParsers\Visitor\VisitorDemoUseCase.cs" />
412412
<Compile Include="QueryParsers\Visitor\VisitorTests.cs" />
413+
<None Include="Reproduce\Issue1528.json">
414+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
415+
</None>
413416
<None Include="Reproduce\Issue1464.json">
414417
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
415418
</None>
416419
<Compile Include="Reproduce\Reproduce1396Tests.cs" />
417420
<Compile Include="Reproduce\Reproduce1199Tests.cs" />
418421
<Compile Include="Reproduce\Reproduce1146Tests.cs" />
419422
<Compile Include="Reproduce\Reproduce1440Tests.cs" />
423+
<Compile Include="Reproduce\Reproduce1528Tests.cs" />
420424
<Compile Include="Reproduce\Reproduce1464Tests.cs" />
421425
<Compile Include="Reproduce\Reproduce629Tests.cs" />
422426
<Compile Include="Reproduce\Reproduce1187Tests.cs" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ "index" : {"_index":"default-index", "_type":"mytype","_id":"my_id_0"} }
2+
{"name":"my_id_0"}
3+
{ "index" : {"_index":"default-index", "_type":"mytype","_id":"my_id_1"} }
4+
{"name":"my_id_1"}
5+
{ "index" : {"_index":"default-index", "_type":"mytype","_id":"my_id_2"} }
6+
{"name":"my_id_2"}
7+
{ "index" : {"_index":"default-index", "_type":"mytype","_id":"my_id_3"} }
8+
{"name":"my_id_3"}
9+
{ "index" : {"_index":"default-index", "_type":"mytype","_id":"my_id_4"} }
10+
{"name":"my_id_4"}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
using Elasticsearch.Net;
2+
using Newtonsoft.Json;
3+
using NUnit.Framework;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.IO;
7+
using System.Linq;
8+
using System.Reflection;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Elasticsearch.Net.Connection;
12+
13+
namespace Nest.Tests.Unit.Reproduce
14+
{
15+
[TestFixture]
16+
public class Reproduce1528Tests : BaseJsonTests
17+
{
18+
[ElasticType(Name ="mytype", IdProperty ="Name")]
19+
public class MyClass
20+
{
21+
public string Name { get; set; }
22+
}
23+
24+
25+
[Test]
26+
public void Issue1528()
27+
{
28+
var settings = new ConnectionSettings(defaultIndex: "default-index");
29+
var client = new ElasticClient(settings, new InMemoryConnection(settings));
30+
var descriptor = new BulkDescriptor();
31+
32+
foreach (var i in Enumerable.Range(0, 5))
33+
{
34+
descriptor.Index<MyClass>(op => op
35+
.Document(new MyClass { Name = "my_id_" + i })
36+
);
37+
}
38+
var result = client.Bulk(descriptor);
39+
var jsonRequest = result.ConnectionStatus.Request;
40+
this.BulkJsonEquals(jsonRequest.Utf8String(), MethodBase.GetCurrentMethod());
41+
}
42+
43+
[Test]
44+
public void Issue1528_NoDefaultIndex()
45+
{
46+
var settings = new ConnectionSettings();
47+
var client = new ElasticClient(settings, new InMemoryConnection(settings));
48+
var descriptor = new BulkDescriptor();
49+
50+
foreach (var i in Enumerable.Range(0, 5))
51+
{
52+
descriptor.Index<MyClass>(op => op
53+
.Document(new MyClass { Name = "my_id_" + i })
54+
);
55+
}
56+
Assert.Throws<NullReferenceException>(()=>{
57+
client.Bulk(descriptor);
58+
});
59+
}
60+
61+
}
62+
}

0 commit comments

Comments
 (0)