11using System ;
2+ using System . Collections . Generic ;
23using System . Linq ;
4+ using System . Runtime . Serialization ;
5+ using SolrNet . Attributes ;
6+ using SolrNet . Commands . Parameters ;
37using Xunit ;
48
59namespace SolrNet . Linq . IntegrationTests
610{
11+ public class Product2
12+ {
13+ public string Id { get ; set ; }
14+
15+ public ICollection < string > Categories { get ; set ; }
16+
17+ public decimal Price { get ; set ; }
18+
19+ public double Qwe { get ; set ; }
20+ }
721 public class SelectTests
822 {
923 [ Fact ]
1024 public void AnonymousClass ( )
1125 {
12- var t1 = Product . SolrOperations . Value . AsQueryable ( ) . Where ( p => p . Id != null )
26+ var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
27+ {
28+ Assert . Equal ( "Qwe:pow(2,2)" , qo . Fields . ElementAt ( 0 ) ) ;
29+ Assert . Equal ( "Id:id" , qo . Fields . ElementAt ( 1 ) ) ;
30+ Assert . Equal ( "Price:price" , qo . Fields . ElementAt ( 2 ) ) ;
31+ Assert . Equal ( "Categories:cat" , qo . Fields . ElementAt ( 3 ) ) ;
32+ } ) . Where ( p => p . Id != null )
1333 . Select ( p => new { p . Id , p . Price , p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
1434 . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
1535 . OrderBy ( arg => arg . Id )
1636 . FirstOrDefault ( ) ;
1737
1838 Assert . NotNull ( t1 ) ;
1939 }
40+
41+ [ Fact ]
42+ public void Product2 ( )
43+ {
44+ var t1 = Product . SolrOperations . Value . AsQueryable ( lo => lo . SetupQueryOptions = qo =>
45+ {
46+ Assert . Equal ( 4 , qo . Fields . Count ) ;
47+ Assert . Equal ( "Qwe:pow(2,2)" , qo . Fields . ElementAt ( 0 ) ) ;
48+ Assert . Equal ( "Id:id" , qo . Fields . ElementAt ( 1 ) ) ;
49+ Assert . Equal ( "Price:price" , qo . Fields . ElementAt ( 2 ) ) ;
50+ Assert . Equal ( "Categories:cat" , qo . Fields . ElementAt ( 3 ) ) ;
51+ } ) . Where ( p => p . Id != null )
52+ . Select ( p => new Product2 { Id = p . Id , Price = p . Price , Categories = p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
53+ . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
54+ . OrderBy ( arg => arg . Id )
55+ . FirstOrDefault ( ) ;
56+
57+ Assert . NotNull ( t1 ) ;
58+
59+ var t2 = Product . SolrOperations . Value . AsQueryable ( ) . Where ( p => p . Id != null )
60+ . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
61+ . OrderBy ( arg => arg . Id )
62+ . FirstOrDefault ( ) ;
63+
64+ Assert . NotNull ( t2 ) ;
65+ Assert . Equal ( t2 . Id , t1 . Id ) ;
66+
67+ SolrQueryResults < Product2 > t3 = Product . SolrOperations . Value . AsQueryable ( ) . Where ( p => p . Id != null )
68+ . Select ( p => new Product2 { Id = p . Id , Price = p . Price , Categories = p . Categories , Qwe = Math . Pow ( 2 , 2 ) } )
69+ . Where ( arg => arg . Categories . Any ( s => s == "electronics" ) )
70+ . OrderBy ( arg => arg . Id ) . Take ( 1 ) . ToSolrQueryResults ( ) ;
71+
72+ Assert . Single ( t3 ) ;
73+ Assert . Equal ( t1 . Id , t3 . Single ( ) . Id ) ;
74+ }
2075 }
2176}
0 commit comments