@@ -177,6 +177,52 @@ public void As_Dynamic_ActingOnIt_WithType()
177
177
Check . That ( countAsDynamic ) . Equals ( 1 ) ;
178
178
}
179
179
180
+ [ Fact ]
181
+ public void As_Dynamic_ActingOnProperty ( )
182
+ {
183
+ // Assign
184
+ var qry = new [ ]
185
+ {
186
+ new Department
187
+ {
188
+ Employee = new Worker { Name = "1" }
189
+ } ,
190
+ new Department
191
+ {
192
+ Employee = new Boss { Name = "b" }
193
+ }
194
+ } . AsQueryable ( ) ;
195
+
196
+ // Act
197
+ int countAsDynamic = qry . Count ( "As(Employee, \" System.Linq.Dynamic.Core.Tests.Entities.Worker\" ) != null" ) ;
198
+
199
+ // Assert
200
+ countAsDynamic . Should ( ) . Be ( 1 ) ;
201
+ }
202
+
203
+ [ Fact ]
204
+ public void As_Dynamic_ActingOnProperty_WithType ( )
205
+ {
206
+ // Assign
207
+ var qry = new [ ]
208
+ {
209
+ new Department
210
+ {
211
+ Employee = new Worker { Name = "1" }
212
+ } ,
213
+ new Department
214
+ {
215
+ Employee = new Boss { Name = "b" }
216
+ }
217
+ } . AsQueryable ( ) ;
218
+
219
+ // Act
220
+ int countAsDynamic = qry . Count ( "As(Employee, @0) != null" , typeof ( Worker ) ) ;
221
+
222
+ // Assert
223
+ countAsDynamic . Should ( ) . Be ( 1 ) ;
224
+ }
225
+
180
226
public class AS_A { }
181
227
public class AS_B : AS_A
182
228
{
@@ -190,7 +236,7 @@ public void As_UnaryExpression()
190
236
// Arrange
191
237
var a = new AS_A ( ) ;
192
238
var b = new AS_B { MyProperty = "x" } ;
193
- var lst = new List < AS_A > ( )
239
+ var lst = new List < AS_A >
194
240
{
195
241
a ,
196
242
b
@@ -289,7 +335,7 @@ public void CastToType_Dynamic_ActingOnIt()
289
335
// Assign
290
336
var qry = new BaseEmployee [ ]
291
337
{
292
- new Worker { Name = "1" , Other = "x" } ,
338
+ new Worker { Name = "1" , Other = "x" } ,
293
339
new Worker { Name = "2" }
294
340
} . AsQueryable ( ) ;
295
341
@@ -307,7 +353,7 @@ public void IsAndCastToType_Dynamic_ActingOnIt_And_GetProperty()
307
353
// Assign
308
354
var qry = new BaseEmployee [ ]
309
355
{
310
- new Worker { Name = "1" , Other = "x" } ,
356
+ new Worker { Name = "1" , Other = "x" } ,
311
357
new Boss { Name = "2" , Function = "y" }
312
358
} . AsQueryable ( ) ;
313
359
@@ -323,14 +369,14 @@ public void IsAndCastToType_Dynamic_ActingOnIt_And_GetProperty()
323
369
public void IsAndCastToType_Dynamic_ActingOnProperty_And_GetProperty ( )
324
370
{
325
371
// Assign
326
- var qry = new [ ]
372
+ var qry = new [ ]
327
373
{
328
- new EmployeeWrapper { Employee = new Worker { Name = "1" , Other = "x" } } ,
374
+ new EmployeeWrapper { Employee = new Worker { Name = "1" , Other = "x" } } ,
329
375
new EmployeeWrapper { Employee = new Boss { Name = "2" , Function = "y" } }
330
376
} . AsQueryable ( ) ;
331
377
332
378
// Act
333
- var cast = qry . Select ( c => c . Employee is Worker ? ( ( Worker ) c . Employee ) . Other : "-" ) . ToArray ( ) ;
379
+ var cast = qry . Select ( c => c . Employee is Worker ? ( ( Worker ) c . Employee ) . Other : "-" ) . ToArray ( ) ;
334
380
var castDynamic = qry . Select ( "iif(Is(Employee, \" System.Linq.Dynamic.Core.Tests.Entities.Worker\" ), Cast(Employee, \" System.Linq.Dynamic.Core.Tests.Entities.Worker\" ).Other, \" -\" )" ) . ToDynamicArray ( ) ;
335
381
336
382
// Assert
0 commit comments