Skip to content

Commit f280955

Browse files
committed
Fixed "exists" result not being properly set
Fixed issue where "exists" result from single GET request was not being properly mapped to GetResponse.
1 parent a16bad2 commit f280955

File tree

2 files changed

+113
-104
lines changed

2 files changed

+113
-104
lines changed
Lines changed: 72 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,72 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Text;
5-
using NUnit.Framework;
6-
using Newtonsoft.Json;
7-
using Newtonsoft.Json.Linq;
8-
9-
using Nest;
10-
using Newtonsoft.Json.Converters;
11-
using Nest.Resolvers.Converters;
12-
using Nest.Tests.MockData.Domain;
13-
using FluentAssertions;
14-
namespace Nest.Tests.Integration.Core.Get
15-
{
16-
[TestFixture]
17-
public class GetFullTests : CleanStateIntegrationTests
18-
{
19-
private void DefaultAssertations(IGetResponse<ElasticSearchProject> result)
20-
{
21-
result.IsValid.Should().BeTrue();
22-
result.Id.Should().Be("1");
23-
result.Index.Should().Be("nest_test_data");
24-
result.Type.Should().Be("elasticsearchprojects");
25-
result.Version.Should().Be("1");
26-
}
27-
28-
[Test]
29-
public void GetSimple()
30-
{
31-
var result = this._client.GetFull<ElasticSearchProject>(1);
32-
this.DefaultAssertations(result);
33-
34-
35-
}
36-
[Test]
37-
public void GetWithPathInfo()
38-
{
39-
var result = this._client.GetFull<ElasticSearchProject>("nest_test_data", "elasticsearchprojects", 1);
40-
this.DefaultAssertations(result);
41-
}
42-
43-
[Test]
44-
public void GetUsingDescriptorWithTypeAndFields()
45-
{
46-
var result = this._client.GetFull<ElasticSearchProject>(g => g
47-
.Index("nest_test_data")
48-
.Type("elasticsearchprojects")
49-
.Id(1)
50-
.Fields(p=>p.Content, p=>p.Name, p=>p.Id, p=>p.DoubleValue)
51-
);
52-
this.DefaultAssertations(result);
53-
54-
result.Source.Should().BeNull();
55-
result.Fields.Should().NotBeNull();
56-
result.Fields.FieldValues.Should().NotBeNull().And.HaveCount(4);
57-
result.Fields.FieldValue<string>(p => p.Name).Should().Be("pyelasticsearch");
58-
result.Fields.FieldValue<int>(p => p.Id).Should().Be(1);
59-
result.Fields.FieldValue<double>(p => p.DoubleValue).Should().BeApproximately(31.931359384177D, 0.00000001D);
60-
61-
}
62-
}
63-
}
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using Newtonsoft.Json;
7+
using Newtonsoft.Json.Linq;
8+
9+
using Nest;
10+
using Newtonsoft.Json.Converters;
11+
using Nest.Resolvers.Converters;
12+
using Nest.Tests.MockData.Domain;
13+
using FluentAssertions;
14+
namespace Nest.Tests.Integration.Core.Get
15+
{
16+
[TestFixture]
17+
public class GetFullTests : CleanStateIntegrationTests
18+
{
19+
private void DefaultAssertations(IGetResponse<ElasticSearchProject> result)
20+
{
21+
result.IsValid.Should().BeTrue();
22+
result.Id.Should().Be("1");
23+
result.Index.Should().Be("nest_test_data");
24+
result.Type.Should().Be("elasticsearchprojects");
25+
result.Version.Should().Be("1");
26+
result.Exists.Should().BeTrue();
27+
}
28+
29+
[Test]
30+
public void GetSimple()
31+
{
32+
var result = this._client.GetFull<ElasticSearchProject>(1);
33+
this.DefaultAssertations(result);
34+
35+
36+
}
37+
[Test]
38+
public void GetWithPathInfo()
39+
{
40+
var result = this._client.GetFull<ElasticSearchProject>("nest_test_data", "elasticsearchprojects", 1);
41+
this.DefaultAssertations(result);
42+
}
43+
44+
[Test]
45+
public void GetUsingDescriptorWithTypeAndFields()
46+
{
47+
var result = this._client.GetFull<ElasticSearchProject>(g => g
48+
.Index("nest_test_data")
49+
.Type("elasticsearchprojects")
50+
.Id(1)
51+
.Fields(p=>p.Content, p=>p.Name, p=>p.Id, p=>p.DoubleValue)
52+
);
53+
this.DefaultAssertations(result);
54+
55+
result.Source.Should().BeNull();
56+
result.Fields.Should().NotBeNull();
57+
result.Fields.FieldValues.Should().NotBeNull().And.HaveCount(4);
58+
result.Fields.FieldValue<string>(p => p.Name).Should().Be("pyelasticsearch");
59+
result.Fields.FieldValue<int>(p => p.Id).Should().Be(1);
60+
result.Fields.FieldValue<double>(p => p.DoubleValue).Should().BeApproximately(31.931359384177D, 0.00000001D);
61+
62+
}
63+
64+
[Test]
65+
public void GetMissing()
66+
{
67+
int doesNotExistId = 1234567;
68+
var result = this._client.GetFull<ElasticSearchProject>(doesNotExistId);
69+
result.Exists.Should().BeFalse();
70+
}
71+
}
72+
}
Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
using Nest.Domain;
2-
using Newtonsoft.Json;
3-
4-
namespace Nest
5-
{
6-
public interface IGetResponse<T> : IResponse where T : class
7-
{
8-
bool Exists { get; }
9-
string Index { get; }
10-
string Type { get; }
11-
string Id { get; }
12-
string Version { get; }
13-
T Source { get; }
14-
FieldSelection<T> Fields { get; }
15-
}
16-
17-
[JsonObject]
18-
public class GetResponse<T> : BaseResponse, IGetResponse<T> where T : class
19-
{
20-
[JsonProperty(PropertyName = "_index")]
21-
public string Index { get; private set; }
22-
23-
[JsonProperty(PropertyName = "_type")]
24-
public string Type { get; private set; }
25-
26-
[JsonProperty(PropertyName = "_id")]
27-
public string Id { get; private set; }
28-
29-
[JsonProperty(PropertyName = "_version")]
30-
public string Version { get; private set; }
31-
32-
[JsonProperty(PropertyName = "_exists")]
33-
public bool Exists { get; private set; }
34-
35-
[JsonProperty(PropertyName = "_source")]
36-
public T Source { get; private set; }
37-
38-
[JsonProperty(PropertyName = "fields")]
39-
public FieldSelection<T> Fields { get; internal set; }
40-
}
41-
}
1+
using Nest.Domain;
2+
using Newtonsoft.Json;
3+
4+
namespace Nest
5+
{
6+
public interface IGetResponse<T> : IResponse where T : class
7+
{
8+
bool Exists { get; }
9+
string Index { get; }
10+
string Type { get; }
11+
string Id { get; }
12+
string Version { get; }
13+
T Source { get; }
14+
FieldSelection<T> Fields { get; }
15+
}
16+
17+
[JsonObject]
18+
public class GetResponse<T> : BaseResponse, IGetResponse<T> where T : class
19+
{
20+
[JsonProperty(PropertyName = "_index")]
21+
public string Index { get; private set; }
22+
23+
[JsonProperty(PropertyName = "_type")]
24+
public string Type { get; private set; }
25+
26+
[JsonProperty(PropertyName = "_id")]
27+
public string Id { get; private set; }
28+
29+
[JsonProperty(PropertyName = "_version")]
30+
public string Version { get; private set; }
31+
32+
[JsonProperty(PropertyName = "exists")]
33+
public bool Exists { get; private set; }
34+
35+
[JsonProperty(PropertyName = "_source")]
36+
public T Source { get; private set; }
37+
38+
[JsonProperty(PropertyName = "fields")]
39+
public FieldSelection<T> Fields { get; internal set; }
40+
}
41+
}

0 commit comments

Comments
 (0)