@@ -14,7 +14,7 @@ public class Product2
1414
1515 public decimal Price { get ; set ; }
1616
17- public double Qwe { get ; set ; }
17+ public double Score { get ; set ; }
1818 }
1919 public class SelectTests
2020 {
@@ -23,10 +23,9 @@ public void AnonymousClass()
2323 {
2424 var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
2525 {
26- Assert . Equal ( "Qwe:pow(2,2)" , qo . Fields . ElementAt ( 0 ) ) ;
27- Assert . Equal ( "Id:id" , qo . Fields . ElementAt ( 1 ) ) ;
28- Assert . Equal ( "Price:price" , qo . Fields . ElementAt ( 2 ) ) ;
29- Assert . Equal ( "Categories:cat" , qo . Fields . ElementAt ( 3 ) ) ;
26+ Assert . Equal ( "id" , qo . Fields . ElementAt ( 0 ) ) ;
27+ Assert . Equal ( "price" , qo . Fields . ElementAt ( 1 ) ) ;
28+ Assert . Equal ( "cat" , qo . Fields . ElementAt ( 2 ) ) ;
3029 } ) . Where ( p => p . Id != null )
3130 . Select ( p => new { p . Id , p . Price , p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
3231 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
@@ -40,13 +39,57 @@ public void AnonymousClass()
4039 Assert . True ( t1 . Price > 0 ) ;
4140 }
4241
42+ [ Fact ]
43+ public void AnonymousMemberWithConversion ( )
44+ {
45+ var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
46+ {
47+ Assert . Equal ( "id" , qo . Fields . ElementAt ( 0 ) ) ;
48+ Assert . Equal ( "price" , qo . Fields . ElementAt ( 1 ) ) ;
49+ Assert . Equal ( "cat" , qo . Fields . ElementAt ( 2 ) ) ;
50+ } ) . Where ( p => p . Id != null )
51+ . Select ( p => new { p . Id , Price = ( int ) p . Price , p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
52+ . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
53+ . OrderBy ( arg => arg . Id )
54+ . FirstOrDefault ( ) ;
55+
56+ Assert . NotNull ( t1 ) ;
57+ Assert . NotNull ( t1 . Id ) ;
58+ Assert . Equal ( 4 , t1 . Qwe ) ;
59+ Assert . True ( t1 . Categories . Count > 0 ) ;
60+ Assert . True ( t1 . Price > 0 ) ;
61+ }
62+
63+ [ Fact ]
64+ public void AnonymousWithConstAndNext ( )
65+ {
66+ var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
67+ {
68+ Assert . Equal ( "id" , qo . Fields . ElementAt ( 0 ) ) ;
69+ Assert . Equal ( "price" , qo . Fields . ElementAt ( 1 ) ) ;
70+ Assert . Equal ( "cat" , qo . Fields . ElementAt ( 2 ) ) ;
71+ } ) . Where ( p => p . Id != null )
72+ . Select ( p => new { p . Id , p . Price , p . Categories , Qwe = "qwe" , Next = new { p . Id } } )
73+ . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
74+ . OrderBy ( arg => arg . Id )
75+ . FirstOrDefault ( ) ;
76+
77+ Assert . NotNull ( t1 ) ;
78+ Assert . NotNull ( t1 . Id ) ;
79+ Assert . NotNull ( t1 . Next ) ;
80+ Assert . Equal ( t1 . Next . Id , t1 . Id ) ;
81+ Assert . Equal ( "qwe" , t1 . Qwe ) ;
82+ Assert . True ( t1 . Categories . Count > 0 ) ;
83+ Assert . True ( t1 . Price > 0 ) ;
84+ }
85+
4386 [ Fact ]
4487 public void AnonymousIdAndScore ( )
4588 {
4689 var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
4790 {
48- Assert . Equal ( "Score:score " , qo . Fields . ElementAt ( 0 ) ) ;
49- Assert . Equal ( "Id:id " , qo . Fields . ElementAt ( 1 ) ) ;
91+ Assert . Equal ( "id " , qo . Fields . ElementAt ( 0 ) ) ;
92+ Assert . Equal ( "v0:score " , qo . Fields . ElementAt ( 1 ) ) ;
5093 } )
5194 . Select ( p => new { p . Id , Score = SolrExpr . Fields . Score ( ) } )
5295 . OrderBy ( arg => arg . Score )
@@ -58,23 +101,23 @@ public void AnonymousIdAndScore()
58101 }
59102
60103 [ Fact ]
61- public void AnonymousOrderByProduct ( )
104+ public void AnonymousOrderByScore ( )
62105 {
63106 var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
64107 {
65- Assert . Equal ( "Qwe:pow(2,2) " , qo . Fields . ElementAt ( 0 ) ) ;
66- Assert . Equal ( "Id:id " , qo . Fields . ElementAt ( 1 ) ) ;
67- Assert . Equal ( "Price:price " , qo . Fields . ElementAt ( 2 ) ) ;
68- Assert . Equal ( "Categories:cat " , qo . Fields . ElementAt ( 3 ) ) ;
108+ Assert . Equal ( "id " , qo . Fields . ElementAt ( 0 ) ) ;
109+ Assert . Equal ( "price " , qo . Fields . ElementAt ( 1 ) ) ;
110+ Assert . Equal ( "cat " , qo . Fields . ElementAt ( 2 ) ) ;
111+ Assert . Equal ( "v0:score " , qo . Fields . ElementAt ( 3 ) ) ;
69112 } ) . Where ( p => p . Id != null )
70- . Select ( p => new { p . Id , p . Price , p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
113+ . Select ( p => new { p . Id , p . Price , p . Categories , Score = SolrExpr . Fields . Score ( ) } )
71114 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
72- . OrderBy ( arg => arg . Id ) . ThenBy ( arg=> arg . Qwe )
115+ . OrderBy ( arg => arg . Id ) . ThenBy ( arg=> arg . Score )
73116 . FirstOrDefault ( ) ;
74117
75118 Assert . NotNull ( t1 ) ;
76119 Assert . NotNull ( t1 . Id ) ;
77- Assert . Equal ( 4 , t1 . Qwe ) ;
120+ Assert . Equal ( 1 , t1 . Score ) ;
78121 Assert . True ( t1 . Categories . Count > 0 ) ;
79122 Assert . True ( t1 . Price > 0 ) ;
80123 }
@@ -102,11 +145,11 @@ public void MultipleSelects()
102145 {
103146 Assert . Equal ( 1 , qo . Fields . Count ) ;
104147 Assert . Equal ( 3 , qo . FilterQueries . Count ) ;
105- Assert . Equal ( "Id: id" , qo . Fields . ElementAt ( 0 ) ) ;
148+ Assert . Equal ( "id" , qo . Fields . ElementAt ( 0 ) ) ;
106149 } ) . Where ( p => p . Id != null )
107- . Select ( p => new { p . Id , p . Price , p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
150+ . Select ( p => new { p . Id , p . Price , p . Categories } )
108151 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
109- . OrderBy ( arg => arg . Id ) . ThenBy ( arg => arg . Qwe )
152+ . OrderBy ( arg => arg . Id )
110153 . Select ( arg => new { arg . Id } )
111154 . FirstOrDefault ( arg2 => arg2 . Id != null ) ;
112155
@@ -126,7 +169,6 @@ public void Transformers()
126169 ValFloat = SolrExpr . Transformers . Value ( ( float ) 2 ) ,
127170 ValDouble = SolrExpr . Transformers . Value ( ( double ) 3 ) ,
128171 ValDate = SolrExpr . Transformers . Value ( dateTime ) ,
129- ExplNl = SolrExpr . Transformers . ExplainNl ( ) ,
130172 ExplText = SolrExpr . Transformers . ExplainText ( ) ,
131173 ExplHtml = SolrExpr . Transformers . ExplainHtml ( ) ,
132174 DocId = SolrExpr . Transformers . DocId ( )
@@ -140,7 +182,7 @@ public void Transformers()
140182 Assert . Equal ( dateTime , t1 . ValDate ) ;
141183
142184 Assert . NotNull ( t1 . ExplText ) ;
143- Assert . NotNull ( t1 . ExplNl ) ;
185+
144186 Assert . NotNull ( t1 . ExplHtml ) ;
145187
146188 Assert . Equal ( 1 , t1 . DocId ) ;
@@ -152,22 +194,21 @@ public void Product2()
152194 var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
153195 {
154196 Assert . Equal ( 4 , qo . Fields . Count ) ;
155- Assert . Equal ( "Qwe:pow(2,2) " , qo . Fields . ElementAt ( 0 ) ) ;
156- Assert . Equal ( "Id:id " , qo . Fields . ElementAt ( 1 ) ) ;
157- Assert . Equal ( "Price:price " , qo . Fields . ElementAt ( 2 ) ) ;
158- Assert . Equal ( "Categories:cat " , qo . Fields . ElementAt ( 3 ) ) ;
197+ Assert . Equal ( "id " , qo . Fields . ElementAt ( 0 ) ) ;
198+ Assert . Equal ( "price " , qo . Fields . ElementAt ( 1 ) ) ;
199+ Assert . Equal ( "cat " , qo . Fields . ElementAt ( 2 ) ) ;
200+ Assert . Equal ( "v0:score " , qo . Fields . ElementAt ( 3 ) ) ;
159201
160- Assert . Equal ( 3 , qo . OrderBy . Count ) ;
202+ Assert . Equal ( 2 , qo . OrderBy . Count ) ;
161203 Assert . Equal ( "id" , qo . OrderBy . ElementAt ( 0 ) . FieldName ) ;
162- Assert . Equal ( "pow(2,2)" , qo . OrderBy . ElementAt ( 1 ) . FieldName ) ;
163- Assert . Equal ( "pow(2,3)" , qo . OrderBy . ElementAt ( 2 ) . FieldName ) ;
204+ Assert . Equal ( "score" , qo . OrderBy . ElementAt ( 1 ) . FieldName ) ;
164205
165206 Assert . Equal ( 2 , qo . FilterQueries . Count ) ;
166207
167208 } ) . Where ( p => p . Id != null )
168- . Select ( p => new Product2 { Id = p . Id , Price = p . Price , Categories = p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
209+ . Select ( p => new Product2 { Id = p . Id , Price = p . Price , Categories = p . Categories , Score = SolrExpr . Fields . Score ( ) } )
169210 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
170- . OrderBy ( arg => arg . Id ) . ThenBy ( arg => arg . Qwe ) . ThenBy ( arg => Math . Pow ( 2 , 3 ) )
211+ . OrderBy ( arg => arg . Id ) . ThenBy ( arg => arg . Score )
171212 . FirstOrDefault ( ) ;
172213
173214 Assert . NotNull ( t1 ) ;
@@ -182,7 +223,7 @@ public void Product2()
182223 Assert . Equal ( t2 . Id , t1 . Id ) ;
183224
184225 SolrQueryResults < Product2 > t3 = Product . SolrOperations . Value . AsQueryable ( ) . Where ( p => p . Id != null )
185- . Select ( p => new Product2 { Id = p . Id , Price = p . Price , Categories = p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
226+ . Select ( p => new Product2 { Id = p . Id , Price = p . Price , Categories = p . Categories } )
186227 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
187228 . OrderBy ( arg => arg . Id ) . Take ( 1 ) . ToSolrQueryResults ( ) ;
188229
@@ -201,15 +242,14 @@ public void Product2WithMemberProduct()
201242 Assert . Equal ( "Id:id" , qo . Fields . ElementAt ( 2 ) ) ;
202243 Assert . Equal ( "Categories:cat" , qo . Fields . ElementAt ( 3 ) ) ;
203244
204- Assert . Equal ( 3 , qo . OrderBy . Count ) ;
245+ Assert . Equal ( 2 , qo . OrderBy . Count ) ;
205246 Assert . Equal ( "id" , qo . OrderBy . ElementAt ( 0 ) . FieldName ) ;
206247 Assert . Equal ( "sum(price,1)" , qo . OrderBy . ElementAt ( 1 ) . FieldName ) ;
207- Assert . Equal ( "pow(2,3)" , qo . OrderBy . ElementAt ( 2 ) . FieldName ) ;
208248 } ) . Where ( p => p . Id != null )
209249 . Select ( p =>
210- new Product2 { Id = p . Id , Price = p . Price + 1 , Categories = p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
250+ new Product2 { Id = p . Id , Price = p . Price + 1 , Categories = p . Categories } )
211251 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
212- . OrderBy ( arg => arg . Id ) . ThenBy ( arg => arg . Price ) . ThenBy ( arg => Math . Pow ( 2 , 3 ) )
252+ . OrderBy ( arg => arg . Id ) . ThenBy ( arg => arg . Price )
213253 . FirstOrDefault ( ) ) ;
214254 }
215255 }
0 commit comments