Skip to content

Commit c94c237

Browse files
committed
test to try and reproduce #620 to no avail
1 parent d2c5bd9 commit c94c237

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System.Linq;
2+
using FluentAssertions;
3+
using NUnit.Framework;
4+
using Nest.Tests.MockData.Domain;
5+
using Elasticsearch.Net;
6+
7+
namespace Nest.Tests.Integration.LowLevel
8+
{
9+
[TestFixture]
10+
public class DynamicNullTests : IntegrationTests
11+
{
12+
[Test]
13+
public void Calling_A_Null_Field_Should_Not_Throw_With_Nests_Serializer()
14+
{
15+
var result = this._client.Raw.Search("{ size: 10}");
16+
var hit = result.Response["hits"]["hits"][0];
17+
Assert.DoesNotThrow(() => { var x = hit["testfield"]; });
18+
var exists = false;
19+
Assert.DoesNotThrow(() => { exists = hit["testfield"] != null; });
20+
exists.Should().BeFalse();
21+
var field = hit["testfield"];
22+
}
23+
24+
[Test]
25+
public void Calling_A_Null_Field_Should_Not_Throw_With_ElasticsearchNet_Serializer()
26+
{
27+
var client = new ElasticsearchClient();
28+
var result = client.Search("{ size: 10}");
29+
var hit = result.Response["hits"]["hits"][0];
30+
31+
Assert.DoesNotThrow(() => { var x = hit["testfield"]; });
32+
var exists = false;
33+
Assert.DoesNotThrow(() => { exists = hit["testfield"] != null; });
34+
exists.Should().BeFalse();
35+
Assert.DoesNotThrow(() => { exists = hit["_index"] != null; });
36+
exists.Should().BeTrue();
37+
38+
var source = hit["_source"];
39+
((object) source).Should().NotBeNull();
40+
Assert.DoesNotThrow(() => { var x = source["name"]; });
41+
string field = source["name"];
42+
43+
field.Should().NotBeNullOrWhiteSpace();
44+
}
45+
46+
}
47+
}

Diff for: src/Tests/Nest.Tests.Integration/Nest.Tests.Integration.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
<Compile Include="Integration\Filter\BoolFilterTests.cs" />
159159
<Compile Include="Integration\HighlightTests.cs" />
160160
<Compile Include="Integration\Query\TermQueryDynamic.cs" />
161+
<Compile Include="LowLevel\DynamicNullTests.cs" />
161162
<Compile Include="Mapping\NotAnalyzedTest.cs" />
162163
<Compile Include="RawCalls\ReturnTypesTest.cs" />
163164
<Compile Include="Reproduce\Reproduce487Tests.cs" />
@@ -170,6 +171,7 @@
170171
<Compile Include="Reproduce\Reproduce319Tests.cs" />
171172
<Compile Include="Reproduce\Reproduce211Tests.cs" />
172173
<Compile Include="Reproduce\ReproduceConnectionStallsTests.cs" />
174+
<Compile Include="Search\FieldTests\FieldsTest.cs" />
173175
<Compile Include="Search\NamedFilter\NamedFilterTests.cs" />
174176
<Compile Include="Search\PercolateTests.cs" />
175177
<Compile Include="Search\CountTests.cs" />

0 commit comments

Comments
 (0)