@@ -10,17 +10,20 @@ namespace EPiServer.ContentGraph.UnitTests
10
10
{
11
11
public class GenerateQueryTests
12
12
{
13
- TypeQueryBuilder < RequestTypeObject > typeQueryBuilder ;
13
+ private TypeQueryBuilder < RequestTypeObject > typeQueryBuilder ;
14
+
14
15
public GenerateQueryTests ( )
15
16
{
16
17
typeQueryBuilder = new TypeQueryBuilder < RequestTypeObject > ( ) ;
17
18
}
19
+
18
20
[ Fact ]
19
21
public void SelectNoneOfFieldsShouldThrowException ( )
20
22
{
21
23
typeQueryBuilder . Limit ( 100 ) . Skip ( 0 ) ;
22
24
Assert . Throws < ArgumentNullException > ( ( ) => typeQueryBuilder . ToQuery ( ) ) ;
23
25
}
26
+
24
27
[ Fact ]
25
28
public void SelectFields ( )
26
29
{
@@ -33,6 +36,20 @@ public void SelectFields()
33
36
Assert . Contains ( expectedFields , query . GetQuery ( ) . Query ) ;
34
37
query = query . BuildQueries ( ) ;
35
38
}
39
+
40
+ [ Fact ]
41
+ public void SelectFieldWithAlias ( )
42
+ {
43
+ string expectedFields = @"{items{property1:Property1 property2:Property2}}" ;
44
+ typeQueryBuilder . Field ( x => x . Property1 , "property1" ) . Field ( x => x . Property2 , "property2" ) ;
45
+ GraphQueryBuilder query = typeQueryBuilder . ToQuery ( ) ;
46
+
47
+ Assert . NotNull ( query . GetQuery ( ) ) ;
48
+ //check selected fields
49
+ Assert . Contains ( expectedFields , query . GetQuery ( ) . Query ) ;
50
+ query = query . BuildQueries ( ) ;
51
+ }
52
+
36
53
[ Fact ]
37
54
public void SelectNestedFields ( )
38
55
{
@@ -49,7 +66,7 @@ public void SelectNestedFields()
49
66
}
50
67
51
68
[ Theory ]
52
- [ InlineData ( 0 , 100 ) ]
69
+ [ InlineData ( 0 , 100 ) ]
53
70
[ InlineData ( 0 , int . MaxValue ) ]
54
71
public void QueryWithPaging ( int skip , int limit )
55
72
{
@@ -86,6 +103,7 @@ public void FacetsQuery()
86
103
Assert . Contains ( expectedFields , query . GetQuery ( ) . Query ) ;
87
104
Assert . Equal ( $ "RequestTypeObject{{{expectedFields} { expectedFacets } }}", query . GetQuery ( ) . Query ) ;
88
105
}
106
+
89
107
[ Fact ]
90
108
public void FacetsQueryWithFilter ( )
91
109
{
@@ -129,6 +147,7 @@ public void AutocompleteQuery()
129
147
Assert . Contains ( expectedAutoComplete , query . GetQuery ( ) . Query ) ;
130
148
Assert . Equal ( $ "RequestTypeObject{{{expectedFields} { expectedFacets } { expectedAutoComplete } }}", query . GetQuery ( ) . Query ) ;
131
149
}
150
+
132
151
[ Fact ]
133
152
public void SubtypeQueryTests ( )
134
153
{
@@ -150,6 +169,7 @@ public void SubtypeQueryTests()
150
169
Assert . Contains ( expectedFields , query . GetQuery ( ) . Query ) ;
151
170
Assert . Equal ( $ "RequestTypeObject{{{expectedFields} { expectedFacets } }}", query . GetQuery ( ) . Query ) ;
152
171
}
172
+
153
173
[ Fact ]
154
174
public void LinkQueryTests ( )
155
175
{
@@ -158,8 +178,8 @@ public void LinkQueryTests()
158
178
string expectedFacets = @"facets{Property3{NestedProperty{name count}}}" ;
159
179
TypeQueryBuilder < SubTypeObject > linkQuery = new TypeQueryBuilder < SubTypeObject > ( )
160
180
. Field ( x => x . SubProperty )
161
- . Where ( x=> x . SubProperty , new StringFilterOperators ( ) . Match ( "test" ) )
162
- . Facet ( x=> x . Property3 ) ;
181
+ . Where ( x => x . SubProperty , new StringFilterOperators ( ) . Match ( "test" ) )
182
+ . Facet ( x => x . Property3 ) ;
163
183
164
184
typeQueryBuilder
165
185
. Field ( x => x . Property1 )
@@ -195,7 +215,7 @@ public void Multiple_types_query()
195
215
. ToQuery ( )
196
216
. BuildQueries ( ) ;
197
217
}
198
-
218
+
199
219
var query = graphQueryBuilder . GetQuery ( ) ;
200
220
Assert . Contains ( expectedQuery1 , query . Query ) ;
201
221
Assert . Contains ( expectedQuery2 , query . Query ) ;
0 commit comments