|
| 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 | +} |
0 commit comments