Skip to content

Commit 619191c

Browse files
committed
conditionlesstests
1 parent 4b6e46c commit 619191c

19 files changed

+556
-115
lines changed

src/Nest.Tests.Unit/BaseJsonTests.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ public BaseJsonTests()
2727
this._client = new ElasticClient(this._settings);
2828
}
2929

30-
protected void JsonEquals(object o, MethodBase method)
30+
protected void JsonEquals(object o, MethodBase method, string fileName = null)
3131
{
3232
var type = method.DeclaringType;
3333
var @namespace = method.DeclaringType.Namespace;
34-
var folder = @namespace.Replace("Nest.Tests.Unit.", "").Replace(".", "\\");
35-
var file = Path.Combine(folder, method.Name + ".json");
34+
var folder = @namespace.Replace("Nest.Tests.Unit.", "").Replace(".", "\\");
35+
36+
var file = Path.Combine(folder, (fileName ?? method.Name) + ".json");
37+
file = Path.Combine(Environment.CurrentDirectory.Replace("bin\\Debug", "").Replace("bin\\Release", ""), file);
38+
3639
var json = TestElasticClient.Serialize(o);
3740
var expected = File.ReadAllText(file);
3841
Assert.True(json.JsonEquals(expected), json);

src/Nest.Tests.Unit/Nest.Tests.Unit.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
<Compile Include="Mapping\Attribute\NestedMappingTests.cs" />
115115
<Compile Include="Properties\AssemblyInfo.cs" />
116116
<Compile Include="PropertyVisitorTests.cs" />
117-
<Compile Include="QueryJson\ConditionLess\InsideBoolCallsTests.cs" />
117+
<Compile Include="QueryJson\ConditionLess\ConditionLessTests.cs" />
118118
<Compile Include="QueryJson\QueriesInQueries\QueriesInQueriesTests.cs" />
119119
<Compile Include="QueryTests\BoolQueryJson.cs" />
120120
<Compile Include="QueryTests\BoostingQueryJson.cs" />
@@ -352,7 +352,7 @@
352352
<None Include="QueryJson\Bool\StaticBoolTest.json">
353353
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
354354
</None>
355-
<None Include="QueryJson\ConditionLess\NullTermShouldBeMatchAll.json" />
355+
<None Include="QueryJson\ConditionLess\MatchAll.json" />
356356
<None Include="QueryJson\InsideBoolCalls\InsideMust.json" />
357357
<None Include="QueryJson\InsideBoolCalls\InsideMustNot.json" />
358358
<None Include="QueryJson\InsideBoolCalls\InsideShould.json" />
Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
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+
14+
namespace Nest.Tests.Unit.QueryJson.ConditionLess
15+
{
16+
[TestFixture]
17+
public class ConditionLessTests : BaseJsonTests
18+
{
19+
public class Criteria
20+
{
21+
public string Name1 { get; set; }
22+
public string Name2 { get; set; }
23+
public int? Int1 { get; set; }
24+
public DateTime? Date { get; set; }
25+
}
26+
private readonly Criteria _c = new Criteria();
27+
28+
private void DoConditionlessQuery(Func<QueryDescriptor<ElasticSearchProject>, BaseQuery> query)
29+
{
30+
var criteria = new Criteria { };
31+
var s = new SearchDescriptor<ElasticSearchProject>()
32+
.From(0)
33+
.Take(10)
34+
.Query(query);
35+
36+
this.JsonEquals(s, System.Reflection.MethodInfo.GetCurrentMethod(), "MatchAll");
37+
}
38+
39+
[Test]
40+
public void QueryString()
41+
{
42+
this.DoConditionlessQuery(q => q.QueryString(qs => qs.Query(_c.Name1)));
43+
}
44+
45+
[Test]
46+
public void Terms()
47+
{
48+
this.DoConditionlessQuery(q => q.Terms(p => p.Name, new string[] { _c.Name1 }));
49+
this.DoConditionlessQuery(q => q.Terms(p => p.Name, _c.Name1, _c.Name2));
50+
}
51+
52+
53+
[Test]
54+
public void TermsDescriptor()
55+
{
56+
this.DoConditionlessQuery(q => q.TermsDescriptor(qs=>qs.OnField(p=>p.Name).Terms(_c.Name1)));
57+
}
58+
59+
[Test]
60+
public void Fuzzy()
61+
{
62+
this.DoConditionlessQuery(q => q.Fuzzy(fq=>fq.OnField(p=>p.Name).Value(_c.Name1)));
63+
}
64+
65+
[Test]
66+
public void FuzzyNumeric()
67+
{
68+
this.DoConditionlessQuery(q => q.FuzzyNumeric(fnq=>fnq.OnField(p=>p.LOC).Value(_c.Int1)));
69+
}
70+
71+
[Test]
72+
public void FuzzyDate()
73+
{
74+
this.DoConditionlessQuery(q => q.FuzzyDate(fdq=>fdq.OnField(p=>p.StartedOn).Value(_c.Date)));
75+
}
76+
77+
[Test]
78+
public void Text()
79+
{
80+
this.DoConditionlessQuery(q => q.Text(tq=>tq.OnField(p=>p.Name).QueryString(_c.Name1)));
81+
}
82+
83+
[Test]
84+
public void TextPhrase()
85+
{
86+
this.DoConditionlessQuery(q => q.Text(tq => tq.OnField(p => p.Name).QueryString(_c.Name1)));
87+
}
88+
89+
[Test]
90+
public void TextPhrasePrefix()
91+
{
92+
this.DoConditionlessQuery(q => q.Text(tq => tq.OnField(p => p.Name).QueryString(_c.Name1)));
93+
}
94+
95+
[Test]
96+
public void Nested()
97+
{
98+
this.DoConditionlessQuery(q => q
99+
.Nested(qn=>qn
100+
.Path(p=>p.Followers)
101+
.Query(nqq=>nqq
102+
.Text(tq => tq
103+
.OnField(p => p.Name)
104+
.QueryString(_c.Name1)
105+
)
106+
)
107+
)
108+
);
109+
}
110+
111+
[Test]
112+
public void Indices()
113+
{
114+
this.DoConditionlessQuery(q => q
115+
.Indices(iq=>iq
116+
.Indices(new [] {"_all" })
117+
.Query(tq => tq.Terms(p => p.Name, _c.Name1))
118+
)
119+
);
120+
this.DoConditionlessQuery(q => q
121+
.Indices(iq => iq
122+
.Indices(new[] { "_all" })
123+
.Query(tq => tq.Terms(p => p.Name, _c.Name1))
124+
.NoMatchQuery(tq => tq.Terms(p => p.Name, _c.Name1))
125+
)
126+
);
127+
}
128+
129+
[Test]
130+
public void Range()
131+
{
132+
//From and to are allowed to be null only field is not not
133+
this.DoConditionlessQuery(q => q.Range(rq => rq.OnField(string.Empty).From(0).To(1)));
134+
}
135+
136+
[Test]
137+
public void FuzzyLikeThis()
138+
{
139+
this.DoConditionlessQuery(q => q.FuzzyLikeThis(fq=>fq.OnFields(p=>p.Name).LikeText(_c.Name1)));
140+
}
141+
142+
[Test]
143+
public void MoreLikeThis()
144+
{
145+
this.DoConditionlessQuery(q => q.MoreLikeThis(mlt=>mlt.OnFields(p=>p.Name).LikeText(_c.Name1)));
146+
}
147+
148+
[Test]
149+
public void HasChild<K>()
150+
{
151+
this.DoConditionlessQuery(q => q.HasChild<Person>(hcq=>hcq.Query(qq=>qq.Terms(p=> p.FirstName, _c.Name1))));
152+
}
153+
154+
[Test]
155+
public void TopChildren<K>()
156+
{
157+
this.DoConditionlessQuery(q => q.TopChildren<Person>(hcq=>hcq.Query(qq=>qq.Terms(p=> p.FirstName, _c.Name1))));
158+
}
159+
160+
[Test]
161+
public void Filtered()
162+
{
163+
//TODO test .Filter
164+
this.DoConditionlessQuery(q => q.Filtered(fq=>fq.Query(qff=>qff.Terms(p=> p.Name, _c.Name1))));
165+
}
166+
167+
[Test]
168+
public void Dismax()
169+
{
170+
this.DoConditionlessQuery(q => q.Dismax(dq => dq.Queries(qff => qff.Terms(p => p.Name, _c.Name1))));
171+
}
172+
173+
[Test]
174+
public void ConstantScore()
175+
{
176+
this.DoConditionlessQuery(q => q.ConstantScore(cq=>cq.Query(qff=>qff.Terms(p=> p.Name, _c.Name1))));
177+
}
178+
179+
[Test]
180+
public void CustomBoostFactor()
181+
{
182+
this.DoConditionlessQuery(q => q.CustomBoostFactor(cbfq => cbfq.Query(qff => qff.Terms(p => p.Name, _c.Name1))));
183+
}
184+
185+
[Test]
186+
public void CustomScore()
187+
{
188+
this.DoConditionlessQuery(q => q.CustomScore(csq=>csq.Query(qff=>qff.Terms(p=> p.Name, _c.Name1))));
189+
}
190+
191+
//[Test]
192+
//public void Bool()
193+
//{
194+
// this.DoConditionlessQuery(q => q.Bool());
195+
//}
196+
197+
[Test]
198+
public void Boosting()
199+
{
200+
this.DoConditionlessQuery(q => q.Boosting(bq => bq.Positive(qff => qff.Terms(p => p.Name, _c.Name1))));
201+
this.DoConditionlessQuery(q => q.Boosting(bq => bq.Negative(qff => qff.Terms(p => p.Name, _c.Name1))));
202+
}
203+
204+
205+
[Test]
206+
public void Term()
207+
{
208+
this.DoConditionlessQuery(q => q.Term(p => p.Name, _c.Name1));
209+
}
210+
211+
[Test]
212+
public void TermString()
213+
{
214+
this.DoConditionlessQuery(q => q.Term(string.Empty, _c.Name1));
215+
}
216+
217+
[Test]
218+
public void Wildcard()
219+
{
220+
this.DoConditionlessQuery(q => q.Wildcard(p => p.Name, _c.Name1));
221+
}
222+
223+
[Test]
224+
public void WildcardString()
225+
{
226+
this.DoConditionlessQuery(q => q.Wildcard(string.Empty, _c.Name1));
227+
}
228+
229+
[Test]
230+
public void Prefix()
231+
{
232+
this.DoConditionlessQuery(q => q.Prefix(p => p.Name, _c.Name1));
233+
}
234+
235+
[Test]
236+
public void PrefixString()
237+
{
238+
this.DoConditionlessQuery(q => q.Prefix(string.Empty, _c.Name1));
239+
}
240+
241+
//[Test]
242+
//public void Ids()
243+
//{
244+
// this.DoConditionlessQuery(q => q.Ids());
245+
//}
246+
247+
//[Test]
248+
//public void Ids()
249+
//{
250+
// this.DoConditionlessQuery(q => q.Ids());
251+
//}
252+
253+
//[Test]
254+
//public void Ids()
255+
//{
256+
// this.DoConditionlessQuery(q => q.Ids());
257+
//}
258+
259+
//[Test]
260+
//public void SpanTerm()
261+
//{
262+
// this.DoConditionlessQuery(q => q.SpanTerm());
263+
//}
264+
265+
//[Test]
266+
//public void SpanTerm()
267+
//{
268+
// this.DoConditionlessQuery(q => q.SpanTerm());
269+
//}
270+
271+
//[Test]
272+
//public void SpanFirst()
273+
//{
274+
// this.DoConditionlessQuery(q => q.SpanFirst());
275+
//}
276+
277+
//[Test]
278+
//public void SpanNear()
279+
//{
280+
// this.DoConditionlessQuery(q => q.SpanNear());
281+
//}
282+
283+
//[Test]
284+
//public void SpanOr()
285+
//{
286+
// this.DoConditionlessQuery(q => q.SpanOr());
287+
//}
288+
289+
//[Test]
290+
//public void SpanNot()
291+
//{
292+
// this.DoConditionlessQuery(q => q.SpanNot());
293+
//}
294+
295+
296+
297+
}
298+
}

src/Nest.Tests.Unit/QueryJson/ConditionLess/InsideBoolCallsTests.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"from": 0,
3+
"size": 10,
4+
"query": { }
5+
}
6+

0 commit comments

Comments
 (0)