1+ using System . Linq ;
2+ using System . Threading . Tasks ;
3+ using Xunit ;
4+
5+ namespace SolrNet . Linq . IntegrationTests
6+ {
7+ public class EnumeratedTests
8+ {
9+ [ Fact ]
10+ public void HasResults ( )
11+ {
12+ Product t1 = Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . First ( ) ;
13+ string id = t1 . Id ;
14+ Product t2 = Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . First ( p => p . Id != "qwe" ) ;
15+ Product t3 = Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . FirstOrDefault ( ) ;
16+ Product t4 = Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . FirstOrDefault ( p => p . Id != "qwe" ) ;
17+ Product t5 = Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . Single ( p => p . Id == id ) ;
18+ Product t6 = Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . SingleOrDefault ( p => p . Id == id ) ;
19+
20+ Assert . NotNull ( t1 ) ;
21+ Assert . NotNull ( t2 ) ;
22+ Assert . NotNull ( t3 ) ;
23+ Assert . NotNull ( t4 ) ;
24+ Assert . NotNull ( t5 ) ;
25+ Assert . NotNull ( t6 ) ;
26+
27+ Assert . Equal ( id , t2 . Id ) ;
28+ Assert . Equal ( id , t3 . Id ) ;
29+ Assert . Equal ( id , t4 . Id ) ;
30+ Assert . Equal ( id , t5 . Id ) ;
31+ Assert . Equal ( id , t6 . Id ) ;
32+ }
33+
34+ [ Fact ]
35+ public async Task HasResultsAsync ( )
36+ {
37+ Product t1 = await Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . FirstAsync ( ) ;
38+ string id = t1 . Id ;
39+ Product t2 = await Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . FirstAsync ( p => p . Id != "qwe" ) ;
40+ Product t3 = await Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . FirstOrDefaultAsync ( ) ;
41+ Product t4 = await Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . FirstOrDefaultAsync ( p => p . Id != "qwe" ) ;
42+ Product t5 = await Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . SingleAsync ( p => p . Id == id ) ;
43+ Product t6 = await Product . SolrOperations . Value . AsQueryable ( ) . OrderBy ( p => p . Id ) . SingleOrDefaultAsync ( p => p . Id == id ) ;
44+
45+ Assert . NotNull ( t1 ) ;
46+ Assert . NotNull ( t2 ) ;
47+ Assert . NotNull ( t3 ) ;
48+ Assert . NotNull ( t4 ) ;
49+ Assert . NotNull ( t5 ) ;
50+ Assert . NotNull ( t6 ) ;
51+
52+ Assert . Equal ( id , t2 . Id ) ;
53+ Assert . Equal ( id , t3 . Id ) ;
54+ Assert . Equal ( id , t4 . Id ) ;
55+ Assert . Equal ( id , t5 . Id ) ;
56+ Assert . Equal ( id , t6 . Id ) ;
57+ }
58+
59+ [ Fact ]
60+ public void OrDefault ( )
61+ {
62+ Product t1 = Product . SolrOperations . Value . AsQueryable ( ) . FirstOrDefault ( p => p . Id == "qwe" ) ;
63+ Product t2 = Product . SolrOperations . Value . AsQueryable ( ) . SingleOrDefault ( p => p . Id == "qwe" ) ;
64+
65+ Assert . Null ( t1 ) ;
66+ Assert . Null ( t2 ) ;
67+ }
68+
69+ [ Fact ]
70+ public async Task OrDefaultAsync ( )
71+ {
72+ Product t1 = await Product . SolrOperations . Value . AsQueryable ( ) . FirstOrDefaultAsync ( p => p . Id == "qwe" ) ;
73+ Product t2 = await Product . SolrOperations . Value . AsQueryable ( ) . SingleOrDefaultAsync ( p => p . Id == "qwe" ) ;
74+
75+ Assert . Null ( t1 ) ;
76+ Assert . Null ( t2 ) ;
77+ }
78+ }
79+ }
0 commit comments