Skip to content

Commit 0bee7a5

Browse files
committed
Appending small changes to #2021
- moved tests into their own namespace so they can be easily ran as a single unit - Rebased against 2.x and removed newly introduces InvokeQuery()'s - Renamed fluent Assign of the QueryCotainerDescriptor to WrapInContainer, since thats what it is doing and to mimic the OIS equivalent.
1 parent 5ffa70d commit 0bee7a5

File tree

6 files changed

+145
-121
lines changed

6 files changed

+145
-121
lines changed

Diff for: src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Dsl.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public partial class QueryContainer : IQueryContainer, IDescriptor
1616
bool IQueryContainer.IsStrict { get; set; }
1717
internal bool IsStrict => Self.IsStrict;
1818

19-
bool IQueryContainer.IsWritable { get { return Self.IsVerbatim || !Self.IsConditionless; } }
19+
bool IQueryContainer.IsWritable => Self.IsVerbatim || !Self.IsConditionless;
2020
internal bool IsWritable => Self.IsWritable;
2121

2222
bool IQueryContainer.IsVerbatim { get; set; }

Diff for: src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs

+64-65
Large diffs are not rendered by default.

Diff for: src/Nest/XPack/Graph/Explore/GraphExploreRequest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public partial class GraphExploreDescriptor<T> : IGraphExploreRequest<T>
4242
public GraphExploreDescriptor() : this(typeof(T)){}
4343

4444
public GraphExploreDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> querySelector) =>
45-
Assign(a => a.Query = querySelector?.InvokeQuery(new QueryContainerDescriptor<T>()));
45+
Assign(a => a.Query = querySelector?.Invoke(new QueryContainerDescriptor<T>()));
4646

4747
public GraphExploreDescriptor<T> Vertices(Func<GraphVerticesDescriptor<T>, IPromise<IList<IGraphVertexDefinition>>> selector) =>
4848
Assign(a => a.Vertices = selector?.Invoke(new GraphVerticesDescriptor<T>())?.Value);

Diff for: src/Nest/XPack/Graph/Explore/Request/Hop.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class HopDescriptor<T> : DescriptorBase<HopDescriptor<T>, IHop>, IHop
3232
IHop IHop.Connections { get; set; }
3333

3434
public HopDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> querySelector) =>
35-
Assign(a => a.Query = querySelector?.InvokeQuery(new QueryContainerDescriptor<T>()));
35+
Assign(a => a.Query = querySelector?.Invoke(new QueryContainerDescriptor<T>()));
3636

3737
public HopDescriptor<T> Vertices(Func<GraphVerticesDescriptor<T>, IPromise<IList<IGraphVertexDefinition>>> selector) =>
3838
Assign(a => a.Vertices = selector?.Invoke(new GraphVerticesDescriptor<T>())?.Value);

Diff for: src/Nest/XPack/Shield/Role/PutRole/IndicesPrivileges.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public IndicesPrivilegesDescriptor<T> Fields(Func<FieldsDescriptor<T>, IPromise<
6161
public IndicesPrivilegesDescriptor<T> Fields(Fields fields) => Assign(a => a.Fields = fields);
6262

6363
public IndicesPrivilegesDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> query) =>
64-
Assign(a => a.Query = query?.InvokeQuery(new QueryContainerDescriptor<T>()));
64+
Assign(a => a.Query = query?.Invoke(new QueryContainerDescriptor<T>()));
6565

6666
}
6767
}

Diff for: src/Tests/QueryDsl/VerbatimAndStrictQueryUsageTests.cs renamed to src/Tests/QueryDsl/Verbatim/VerbatimAndStrictQueryUsageTests.cs

+77-52
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,75 @@
1010
using Tests.Framework.MockData;
1111
using Xunit;
1212

13-
namespace Tests.QueryDsl
13+
namespace Tests.QueryDsl.Verbatim
1414
{
15-
/** Setting `IsStrict` on the outer query container is a noop */
15+
/** `IsVerbatim` should be set on individual queries to take effect */
16+
public class CompoundVerbatimQueryUsageTests : QueryDslUsageTestsBase
17+
{
18+
protected override bool SupportsDeserialization => false;
19+
20+
public CompoundVerbatimQueryUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
21+
22+
protected override object QueryJson => new
23+
{
24+
@bool = new
25+
{
26+
must = new object[]
27+
{
28+
new
29+
{
30+
term = new
31+
{
32+
description = new
33+
{
34+
value = ""
35+
}
36+
}
37+
},
38+
new
39+
{
40+
term = new
41+
{
42+
name = new
43+
{
44+
value = "foo"
45+
}
46+
}
47+
}
48+
}
49+
}
50+
};
51+
52+
protected override QueryContainer QueryInitializer =>
53+
new TermQuery
54+
{
55+
IsVerbatim = true,
56+
Field = "description",
57+
Value = ""
58+
}
59+
&& new TermQuery
60+
{
61+
Field = "name",
62+
Value = "foo"
63+
};
64+
65+
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
66+
.Bool(b => b
67+
.Must(qt => qt
68+
.Term(t => t
69+
.Verbatim()
70+
.Field(p => p.Description)
71+
.Value("")
72+
), qt => qt
73+
.Term(t => t
74+
.Field(p => p.Name)
75+
.Value("foo")
76+
)
77+
)
78+
);
79+
}
80+
81+
/** Setting `IsStrict` on the outer query container does not cascade */
1682
public class QueryContainerStrictQueryUsageTests : QueryDslUsageTestsBase
1783
{
1884
protected override bool SupportsDeserialization => false;
@@ -83,7 +149,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
83149
#pragma warning restore 618
84150
}
85151

86-
/** Setting `IsVerbatim` on the outer query container is a noop */
152+
/** Setting `IsVerbatim` on the outer query container does not cascase */
87153
public class QueryContainerVerbatimQueryUsageTests : QueryDslUsageTestsBase
88154
{
89155
protected override bool SupportsDeserialization => false;
@@ -154,69 +220,28 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
154220
#pragma warning restore 618
155221
}
156222

157-
/** `IsVerbatim` should be set on individual queries to take effect */
158-
public class CompoundVerbatimQueryUsageTests : QueryDslUsageTestsBase
223+
/** Setting `IsVerbatim` on a compound query is still supported though */
224+
public class QueryContainerVerbatimSupportedUsageTests : QueryDslUsageTestsBase
159225
{
160226
protected override bool SupportsDeserialization => false;
161227

162-
public CompoundVerbatimQueryUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
228+
public QueryContainerVerbatimSupportedUsageTests(ReadOnlyCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
163229

164230
protected override object QueryJson => new
165231
{
166232
@bool = new
167233
{
168-
must = new object[]
169-
{
170-
new
171-
{
172-
term = new
173-
{
174-
description = new
175-
{
176-
value = ""
177-
}
178-
}
179-
},
180-
new
181-
{
182-
term = new
183-
{
184-
name = new
185-
{
186-
value = "foo"
187-
}
188-
}
189-
}
190-
}
191234
}
192235
};
193236

194-
protected override QueryContainer QueryInitializer =>
195-
new TermQuery
196-
{
197-
IsVerbatim = true,
198-
Field = "description",
199-
Value = ""
200-
}
201-
&& new TermQuery
202-
{
203-
Field = "name",
204-
Value = "foo"
205-
};
237+
protected override QueryContainer QueryInitializer => new BoolQuery
238+
{
239+
IsVerbatim = true,
240+
};
206241

207242
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
208243
.Bool(b => b
209-
.Must(qt => qt
210-
.Term(t => t
211-
.Verbatim()
212-
.Field(p => p.Description)
213-
.Value("")
214-
), qt => qt
215-
.Term(t => t
216-
.Field(p => p.Name)
217-
.Value("foo")
218-
)
219-
)
244+
.Verbatim()
220245
);
221246
}
222247

0 commit comments

Comments
 (0)