Skip to content

Commit a56b688

Browse files
committed
Fix #1447: Add explanation to validate response
Also found a bug where Valid had an incorrect json property name
1 parent ccd6a81 commit a56b688

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

src/Nest/Domain/Hit/ValidationExplanation.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ public class ValidationExplanation
1010
{
1111
[JsonProperty(PropertyName = "index")]
1212
public string Index { get; internal set; }
13-
[JsonProperty(PropertyName = "description")]
13+
14+
[JsonProperty(PropertyName = "valid")]
1415
public bool Valid { get; internal set; }
16+
1517
[JsonProperty(PropertyName = "error")]
16-
public string Error { get; internal set; }
17-
18+
public string Error { get; internal set; }
19+
20+
[JsonProperty(PropertyName = "explanation")]
21+
public string Explanation { get; internal set; }
1822
}
1923
}

src/Tests/Nest.Tests.Integration/Core/ValidateTests.cs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using Nest.Tests.MockData.Domain;
33
using System.Linq;
44
using Elasticsearch.Net;
5+
using FluentAssertions;
56

67
namespace Nest.Tests.Integration.Core
78
{
@@ -16,26 +17,42 @@ public void TestValidation()
1617
.Term(f=>f.Country, "netherlands")
1718
)
1819
);
19-
Assert.NotNull(response);
20-
Assert.True(response.IsValid);
21-
Assert.True(response.Valid);
20+
response.Should().NotBeNull();
21+
response.IsValid.Should().BeTrue();
22+
response.Valid.Should().BeTrue();
2223
}
2324
[Test]
24-
public void TestValidationWithExplain()
25+
public void TestValidationWithExplain_Invalid()
2526
{
2627
var response = this.Client.Validate<ElasticsearchProject>(q => q
2728
.Explain()
2829
.Q("loc:asdasd")
2930
);
30-
Assert.NotNull(response);
31-
Assert.True(response.IsValid);
32-
Assert.False(response.Valid);
33-
Assert.NotNull(response.Explanations);
34-
Assert.True(response.Explanations.HasAny());
31+
response.Should().NotBeNull();
32+
response.IsValid.Should().BeTrue();
33+
response.Valid.Should().BeFalse();
34+
response.Explanations.Should().NotBeNull().And.NotBeEmpty();
3535
var explanation = response.Explanations.First();
36-
Assert.AreEqual(explanation.Index, Settings.DefaultIndex);
37-
Assert.False(explanation.Valid);
38-
Assert.False(explanation.Error.IsNullOrEmpty());
36+
explanation.Index.Should().BeEquivalentTo(Settings.DefaultIndex);
37+
explanation.Valid.Should().BeFalse();
38+
explanation.Error.Should().NotBeNullOrEmpty();
39+
}
40+
41+
[Test]
42+
public void TestValidationWithExplanation_Valid()
43+
{
44+
var response = this.Client.Validate<ElasticsearchProject>(v => v
45+
.Explain()
46+
.Q("name:elasticsearch")
47+
);
48+
response.Should().NotBeNull();
49+
response.IsValid.Should().BeTrue();
50+
response.Explanations.Should().NotBeNull().And.NotBeEmpty();
51+
var explanation = response.Explanations.First();
52+
explanation.Index.Should().BeEquivalentTo(Settings.DefaultIndex);
53+
explanation.Valid.Should().BeTrue();
54+
explanation.Error.Should().BeNullOrEmpty();
55+
explanation.Explanation.Should().NotBeNullOrEmpty();
3956
}
4057
}
4158
}

0 commit comments

Comments
 (0)