-
Notifications
You must be signed in to change notification settings - Fork 332
Expand file tree
/
Copy pathFindApiTestBase.cs
More file actions
2183 lines (2049 loc) · 96 KB
/
FindApiTestBase.cs
File metadata and controls
2183 lines (2049 loc) · 96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using System.Web;
using Azure.DataApiBuilder.Config.ObjectModel;
using Azure.DataApiBuilder.Core.Resolvers;
using Azure.DataApiBuilder.Service.Exceptions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Azure.DataApiBuilder.Service.Tests.SqlTests.RestApiTests.Find
{
/// <summary>
/// Test GET REST Api validating expected results are obtained.
/// </summary>
[TestClass]
public abstract class FindApiTestBase : RestApiTestBase
{
protected static readonly int _numRecordsReturnedFromTieBreakTable = 2;
public abstract string GetDefaultSchema();
public abstract string GetDefaultSchemaForEdmModel();
#region Positive Tests
/// <summary>
/// Tests the REST Api for FindById operation without a query string.
/// </summary>
[TestMethod]
public async Task FindByPKTest()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "id/2",
queryString: string.Empty,
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindByIdTest")
);
}
/// <summary>
/// Tests the REST Api for FindByDateTimePk operation without a query string.
/// </summary>
[TestMethod]
public virtual async Task FindByDateTimePKTest()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "categoryid/2/pieceid/1/instant/2023-08-21T15:11:04",
queryString: string.Empty,
entityNameOrPath: _tableWithDateTimePK,
sqlQuery: GetQuery("FindByDateTimePKTest")
);
}
/// <summary>
/// Tests the REST Api for find many operation on stored procedure
/// Stored procedure result is not necessarily json.
/// </summary>
[TestMethod]
public virtual async Task FindManyStoredProcedureTest()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _integrationProcedureFindMany_EntityName,
operationType: EntityActionOperation.Execute,
restHttpVerb: SupportedHttpVerb.Get,
sqlQuery: GetQuery("FindManyStoredProcedureTest"),
expectJson: false
);
}
/// <summary>
/// Tests the REST Api for find one operation using required parameter
/// For Find operations, parameters must be passed in query string
/// </summary>
[TestMethod]
public virtual async Task FindOneStoredProcedureTestUsingParameter()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?id=1",
entityNameOrPath: _integrationProcedureFindOne_EntityName,
operationType: EntityActionOperation.Execute,
restHttpVerb: SupportedHttpVerb.Get,
sqlQuery: GetQuery("FindOneStoredProcedureTestUsingParameter"),
expectJson: false
);
}
/// <summary>
/// Tests the REST Api for Find operations on empty result sets
/// 1. GET an entity with no rows (empty table)
/// 2. GET an entity with rows, filtered to none by query parameter
/// Should be a 200 response with an empty array
/// </summary>
[TestMethod]
public async Task FindEmptyResultSet()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _emptyTableEntityName,
sqlQuery: GetQuery("FindEmptyTable")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=1 ne 1",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindEmptyResultSetWithQueryFilter")
);
}
/// <summary>
/// Tests the Rest Api to validate that unique unicode
/// characters work in queries.
/// </summary>
/// <returns></returns>
[TestMethod]
public virtual async Task FindOnTableWithUniqueCharacters()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _integrationUniqueCharactersEntity,
sqlQuery: GetQuery("FindOnTableWithUniqueCharacters"));
}
/// <summary>
/// Tests the Rest Api to validate that queries work
/// when there is the same table name in two different
/// schemas. In this test we have two tables both
/// named magazines but with one in the schema "foo" and
/// the other in the schema "bar".
/// </summary>
[TestMethod]
public virtual async Task FindOnTableWithNamingCollision()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _collisionEntity,
sqlQuery: GetQuery("FindOnTableWithNamingCollision"));
}
/// <summary>
/// Validates that a Find request on a single item with $select with only non-PK fields
/// returns only the selected fields and does not contain PK fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldsWithoutPKOnATable()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "id/1",
queryString: "?$select=title",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindByIdWithSelectFieldsWithoutPKOnTable")
);
}
/// <summary>
/// Validates that a Find request on a list of items with $select with only non-PK fields
/// returns only those fields and does not contain PK fields.
/// </summary>
[TestMethod]
public async Task FindTestWithSelectFieldsWithoutPKOnATable()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=title",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindWithSelectFieldsWithoutPKOnTable")
);
}
/// <summary>
/// Validates that a Find request against a table with a composite PK on a single item
/// with $select containing some PK fields returns only the selected fields
/// and does not contain all the PK fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldWithSomePKFieldsOnATableWithCompositePK()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "categoryid/1/pieceid/1",
queryString: "?$select=categoryid,categoryName",
entityNameOrPath: _Composite_NonAutoGenPK_EntityPath,
sqlQuery: GetQuery("FindByIdWithSelectFieldsWithSomePKOnTableWithCompositePK")
);
}
/// <summary>
/// Validates that a Find request against a table with a composite PK on a list of items
/// with $select containing some PK fields returns only the selected fields
/// and does not contain all the PK fields.
/// </summary>
[TestMethod]
public async Task FindTestWithSelectFieldsContainingSomePKOnATableWithCompositePK()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=categoryid,categoryName",
entityNameOrPath: _Composite_NonAutoGenPK_EntityPath,
sqlQuery: GetQuery("FindWithSelectFieldsWithSomePKOnTableWithCompositePK")
);
}
/// <summary>
/// Validates that a Find request against a table with a composite PK on a single item
/// with $select containing no PK fields returns only the selected fields
/// and does not contain any PK fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldsWithoutPKOnATableWithCompositePK()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "categoryid/1/pieceid/1",
queryString: "?$select=categoryName",
entityNameOrPath: _Composite_NonAutoGenPK_EntityPath,
sqlQuery: GetQuery("FindByIdWithSelectFieldsWithoutPKOnTableWithCompositePK")
);
}
/// <summary>
/// Validates that a Find request against a table with a composite PK on a list of items
/// with $select containing no PK fields returns only the selected fields
/// and does not contain any PK fields.
/// </summary>
[TestMethod]
public async Task FindTestWithSelectFieldsWithoutPKOnATableWithCompositePK()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=categoryName",
entityNameOrPath: _Composite_NonAutoGenPK_EntityPath,
sqlQuery: GetQuery("FindWithSelectFieldsWithoutPKOnTableWithCompositePK")
);
}
/// <summary>
/// Validates the repsonse when both $select and $orderby query strings are
/// used with Find API reqeusts. The response is expected to contain only the
/// fields requested in $select clause.
/// This test is executed against a table.
/// </summary>
[TestMethod]
public async Task FindWithSelectAndOrderByQueryStringsOnATable()
{
// Validates that a Find request on a table with $select and $orderby query strings
// returns only the fields selected in $select query string and does not contain
// $orderby fields.
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=id,title&$orderby=publisher_id",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindWithSelectAndOrderbyQueryStringsOnTables")
);
}
/// <summary>
/// Validates the repsonse when both $select and $orderby query strings are
/// used with Find API reqeusts. The response is expected to contain only the
/// fields requested in $select clause.
/// This test is executed against a view.
/// </summary>
[TestMethod]
public async Task FindWithSelectAndOrderByQueryStringsOnAView()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=categoryid,categoryName&$orderby=piecesAvailable",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindWithSelectAndOrderbyQueryStringsOnViews")
);
}
/// <summary>
/// Validates the response when a Find request to select all items is executed
/// against a view.
/// </summary>
[TestMethod]
public async Task FindTestOnAView()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _simple_all_books,
sqlQuery: GetQuery("FindViewAll")
);
}
/// <summary>
/// Validates the response when a Find request is executed against a view
/// which has mapping defined on the key field.
/// </summary>
[TestMethod]
public async Task FindTestOnAViewWithMappingDefinedOnKeyField()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=book_id",
entityNameOrPath: _book_view_with_key_and_mapping,
sqlQuery: GetQuery("FindViewWithKeyAndMapping")
);
}
/// <summary>
/// Validates the response when a Find request to select a single item is
/// executed against a view with multiple key-fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestOnAViewWithMultipleKeyFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "categoryid/2/pieceid/1",
queryString: string.Empty,
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindViewSelected")
);
}
/// <summary>
/// Validates that a Find request against a view on a list of items with
/// $select with only non-key fields
/// returns only the selected fields and does not contain key fields.
/// </summary>
[TestMethod]
public async Task FindTestWithSelectFieldsWithoutKeyFieldsOnView()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=title",
entityNameOrPath: _simple_all_books,
sqlQuery: GetQuery("FindTestWithSelectFieldsWithoutKeyFieldsOnView")
);
}
/// <summary>
/// Validates that a Find request against a view with multiple key-fields on a list of items with
/// $select with some key fields
/// returns only the selected fields and does not contain all the key fields.
/// </summary>
[TestMethod]
public async Task FindTestWithSelectFieldsWithSomeKeyFieldsOnViewWithMultipleKeyFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=categoryid,categoryName",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindTestWithSelectFieldsWithSomeKeyFieldsOnViewWithMultipleKeyFields")
);
}
/// <summary>
/// Validates that a Find request against a view with multiple key fields on a list of items with
/// $select with no key fields returns only the selected fields and
/// does not contain any key fields.
/// </summary>
[TestMethod]
public async Task FindTestWithSelectFieldsWithoutKeyFieldsOnViewWithMultipleKeyFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=categoryName",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindTestWithSelectFieldsWithoutKeyFieldsOnViewWithMultipleKeyFields")
);
}
/// <summary>
/// Validates that a Find request against a view on a single item with
/// $select with key and non-key fields
/// returns only the selected fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldsOnView()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "id/1",
queryString: "?$select=id,title",
entityNameOrPath: _simple_all_books,
sqlQuery: GetQuery("FindByIdTestWithSelectFieldsOnView")
);
}
/// <summary>
/// Validates that a Find request against a view on a single item with
/// $select with only non-key fields returns only the selected fields
/// and does not contain key fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldsOnViewWithoutKeyFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "id/1",
queryString: "?$select=title",
entityNameOrPath: _simple_all_books,
sqlQuery: GetQuery("FindByIdTestWithSelectFieldsOnViewWithoutKeyFields")
);
}
/// <summary>
/// Validates that a Find request against a view with multiple key-fields on a single item with
/// $select with some key fields returns only the selected fields
/// and does not contain all the key fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldsWithSomeKeyFieldsOnViewWithMultipleKeyFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "categoryid/1/pieceid/1",
queryString: "?$select=categoryid,categoryName",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindByIdTestWithSelectFieldsWithSomeKeyFieldsOnViewWithMultipleKeyFields")
);
}
/// <summary>
/// Validates that a Find request against a view with multiple key fields on a single item with
/// $select with no key fields
/// returns only the selected fields and does not contain any key fields.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithSelectFieldsWithoutKeyFieldsOnViewWithMultipleKeyFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "categoryid/1/pieceid/1",
queryString: "?$select=categoryName",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindByIdTestWithSelectFieldsWithoutKeyFieldsOnViewWithMultipleKeyFields")
);
}
///<summary>
/// Tests the Rest Api for GET operations on Database Views,
/// either simple or composite,having filter clause.
///</summary>
[TestMethod]
public virtual async Task FindTestWithQueryStringOnViews()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id ge 4",
entityNameOrPath: _simple_all_books,
sqlQuery: GetQuery("FindTestWithFilterQueryOneGeFilterOnView")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=pieceid eq 1",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindTestWithFilterQueryStringOneEqFilterOnView")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=not (categoryid gt 1)",
entityNameOrPath: _simple_subset_stocks,
sqlQuery: GetQuery("FindTestWithFilterQueryOneNotFilterOnView")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter= id lt 5",
entityNameOrPath: _composite_subset_bookPub,
sqlQuery: GetQuery("FindTestWithFilterQueryOneLtFilterOnView")
);
}
/// <summary>
/// Tests the REST Api for FindById operation with a query string
/// including the field names.
/// </summary>
[TestMethod]
public async Task FindByIdTestWithQueryStringFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "id/1",
queryString: "?$select=id,title",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindByIdTestWithQueryStringFields))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a query string with 1 field
/// including the field names.
/// </summary>
[TestMethod]
public async Task FindTestWithQueryStringOneField()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=id",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithQueryStringOneField))
);
}
/// <summary>
/// Tests the REST Api for Find operation with an empty query string
/// including the field names.
/// </summary>
[TestMethod]
public async Task FindTestWithQueryStringAllFields()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithQueryStringAllFields))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a single filter, executes
/// a test for all of the comparison operators and the unary NOT operator.
/// </summary>
[TestMethod]
public async Task FindTestsWithFilterQueryStringOneOpFilter()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id eq 1",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryStringOneEqFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=2 eq id",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryStringValueFirstOneEqFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id gt 3",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneGtFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id ge 4",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneGeFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id lt 5",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneLtFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id le 4",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneLeFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id ne 3",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneNeFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=not (id lt 2)",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneNotFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=not (title eq null)",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneRightNullEqFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=null ne title",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery("FindTestWithFilterQueryOneLeftNullNeFilter")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=color eq null and ownername eq 'Abhishek'",
entityNameOrPath: _entityWithVarcharMax,
sqlQuery: GetQuery("FindTestFilterForVarcharColumnWithNullAndNonNullValues"),
clientRoleHeader: "authorizationHandlerTester"
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=habitat eq 'sand'",
entityNameOrPath: _integrationBrokenMappingEntity,
sqlQuery: GetQuery("FindTestFilterForVarcharColumnWithNotMaximumSize")
);
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=habitat eq 'forestland'",
entityNameOrPath: _integrationBrokenMappingEntity,
sqlQuery: GetQuery("FindTestFilterForVarcharColumnWithNotMaximumSizeAndNoTruncation")
);
}
/// <summary>
/// Tests the REST Api for Find operation with two filters separated with AND
/// comparisons connected with OR.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringSingleAndFilter()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id lt 3 and id gt 1",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringSingleAndFilter))
);
}
/// <summary>
/// Tests the REST Api for Find operation with two filters separated with OR
/// comparisons connected with OR.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringSingleOrFilter()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id lt 3 or id gt 4",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringSingleOrFilter))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter query string with multiple
/// comparisons connected with AND.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringMultipleAndFilters()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id lt 4 and id gt 1 and title ne 'Awesome book'",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringMultipleAndFilters))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter query string with multiple
/// comparisons connected with OR.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringMultipleOrFilters()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id eq 1 or id eq 2 or id eq 3",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringMultipleOrFilters))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter query string with multiple
/// comparisons connected with AND and those comparisons connected with OR.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringMultipleAndOrFilters()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=(id gt 2 and id lt 4) or (title eq 'Awesome book')",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringMultipleAndOrFilters))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter query string with multiple
/// comparisons connected with AND OR and including NOT.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringMultipleNotAndOrFilters()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=(not (id lt 3) or id lt 4) or not (title eq 'Awesome book')",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringMultipleNotAndOrFilters))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter containing special characters
/// like ampersand (&) that need to be URL-encoded. This validates that the fix for
/// the double-decoding issue is working correctly.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterContainingSpecialCharacters()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=title eq 'filter & test'",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterContainingSpecialCharacters))
);
}
/// <summary>
/// Tests the REST Api for Find operation with filters containing various special characters
/// that need URL encoding: plus (+), equals (=), and percent (%).
/// Validates that multiple types of special characters are handled correctly.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterContainingMultipleSpecialCharacters()
{
// Test with plus and equals signs
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=title eq 'A+B=C'",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterContainingMultipleSpecialCharacters))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter containing ampersand
/// in a different context to ensure robustness across various data patterns.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterContainingAmpersandInPhrase()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=title eq 'Tom & Jerry'",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterContainingAmpersandInPhrase))
);
}
/// <summary>
/// Tests the REST Api for Find operation with a filter containing percent sign (%)
/// which has special meaning in URL encoding and SQL LIKE patterns.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterContainingPercentSign()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=title eq '100% Complete'",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterContainingPercentSign))
);
}
/// <summary>
/// Tests the REST Api for Find operation where we compare one field
/// to the bool returned from another comparison.
/// </summary>
[TestMethod]
public async Task FindTestWithFilterQueryStringBoolResultFilter()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$filter=id eq (publisher_id gt 1)",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFilterQueryStringSingleAndFilter)),
exceptionExpected: true,
expectedErrorMessage: "A binary operator with incompatible types was detected. " +
"Found operand types 'Edm.Int32' and 'Edm.Boolean' for operator kind 'Equal'.",
expectedStatusCode: HttpStatusCode.BadRequest
);
}
[TestMethod]
public async Task FindTestWithPrimaryKeyContainingForeignKey()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: "id/567/book_id/1",
queryString: "?$select=id,content",
entityNameOrPath: _entityWithCompositePrimaryKey,
sqlQuery: GetQuery(nameof(FindTestWithPrimaryKeyContainingForeignKey))
);
}
/// <summary>
/// Tests the REST Api for Find operation using $first to
/// limit the number of records returned with a single primary
/// key in the table.
/// </summary>
[TestMethod]
public async Task FindTestWithFirstSingleKeyPagination()
{
string after = SqlPaginationUtil.Base64Encode($"[{{\"EntityName\":\"Book\",\"FieldName\":\"id\",\"FieldValue\":1,\"Direction\":0}}]");
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$first=1",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithFirstSingleKeyPagination)),
expectedAfterQueryString: $"&$after={after}",
paginated: true
);
}
/// <summary>
/// Validates that a proper nextLink is created for FindMany requests which do not
/// restrict results with query parameters. Engine default paging mechanisms are used
/// when > 100 records will be present in result set.
/// expectedAfterQueryString starts with ?$, and not &$, because it is the only query parameter.
/// </summary>
[TestMethod]
public async Task FindTest_NoQueryParams_PaginationNextLink()
{
string after = SqlPaginationUtil.Base64Encode($"[{{\"EntityName\":\"Bookmarks\",\"FieldName\":\"id\",\"FieldValue\":100,\"Direction\":0}}]");
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _integrationPaginationEntityName,
sqlQuery: GetQuery(nameof(FindTest_NoQueryParams_PaginationNextLink)),
expectedAfterQueryString: $"?$after={after}",
paginated: true
);
}
/// <summary>
/// Validates that when first is set to -1, we return the maximum records
/// as specified by max page size. In this case, the expected result is that
/// all the records are returned from the db.
/// </summary>
[TestMethod]
public async Task FindTest_Negative1QueryParams_Pagination()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$first=-1",
entityNameOrPath: _integrationPaginationEntityName,
sqlQuery: GetQuery(nameof(FindTest_Negative1QueryParams_Pagination))
);
}
/// <summary>
/// Validates that a proper nextLink is created for FindMany requests which do not
/// restrict results with query parameters. Engine default paging mechanisms are used
/// when > 100 records will be present in result set.
/// expectedAfterQueryString starts with &$, and not ?$, because it is
/// 1) Not the only query parameter.
/// 2) Not the first query parameter.
/// </summary>
[TestMethod]
public async Task FindTest_OrderByNotFirstQueryParam_PaginationNextLink()
{
string after = SqlPaginationUtil.Base64Encode($"[{{\"EntityName\":\"Bookmarks\",\"FieldName\":\"id\",\"FieldValue\":100,\"Direction\":0}}]");
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=id",
entityNameOrPath: _integrationPaginationEntityName,
sqlQuery: GetQuery(nameof(FindTest_OrderByNotFirstQueryParam_PaginationNextLink)),
expectedAfterQueryString: $"&$after={after}",
paginated: true
);
}
/// <summary>
/// Tests the REST Api for Find operation using $first to
/// limit the number of records returned with multiple column
/// primary key in the table.
/// </summary>
[TestMethod]
public async Task FindTestWithFirstMultiKeyPagination()
{
string after = $"[{{\"EntityName\":\"Review\",\"FieldName\":\"book_id\",\"FieldValue\":1,\"Direction\":0}}," +
$"{{\"EntityName\":\"Review\",\"FieldName\":\"id\",\"FieldValue\":567,\"Direction\":0}}]";
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$first=1",
entityNameOrPath: _entityWithCompositePrimaryKey,
sqlQuery: GetQuery(nameof(FindTestWithFirstMultiKeyPagination)),
expectedAfterQueryString: $"&$after={SqlPaginationUtil.Base64Encode(after)}",
paginated: true
);
}
/// <summary>
/// Tests the REST Api for Find operation using $after to
/// get the desired page with a single column primary key.
/// </summary>
[TestMethod]
public async Task FindTestWithAfterSingleKeyPagination()
{
string after = SqlPaginationUtil.Base64Encode($"[{{\"EntityName\":\"Books\",\"FieldName\":\"id\",\"FieldValue\":7,\"Direction\":0}}]");
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: $"?$after={after}",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithAfterSingleKeyPagination))
);
}
/// <summary>
/// Tests the REST Api for Find operation using $after to
/// get the desired page with a multi column primary key.
/// </summary>
[TestMethod]
public async Task FindTestWithAfterMultiKeyPagination()
{
string after = $"[{{\"EntityName\":\"Reviews\",\"FieldName\":\"book_id\",\"FieldValue\":1,\"Direction\":0}}," +
$"{{\"EntityName\":\"Reviews\",\"FieldName\":\"id\",\"FieldValue\":567,\"Direction\":0}}]";
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: $"?$after={SqlPaginationUtil.Base64Encode(after)}",
entityNameOrPath: _entityWithCompositePrimaryKey,
sqlQuery: GetQuery(nameof(FindTestWithAfterMultiKeyPagination))
);
}
/// <summary>
/// Tests the REST Api for Find operation using pagination
/// to verify that we return an $after cursor that has the
/// single primary key column.
/// </summary>
[TestMethod]
public async Task FindTestWithPaginationVerifSinglePrimaryKeyInAfter()
{
string after = SqlPaginationUtil.Base64Encode($"[{{\"EntityName\":\"Book\",\"FieldName\":\"id\",\"FieldValue\":1,\"Direction\":0}}]");
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: $"?$first=1",
entityNameOrPath: _integrationEntityName,
sqlQuery: GetQuery(nameof(FindTestWithPaginationVerifSinglePrimaryKeyInAfter)),
expectedAfterQueryString: $"&$after={after}",
paginated: true
);
}
/// <summary>
/// Tests the REST Api for Find operation using pagination
/// to verify that we return an $after cursor that has all the
/// multiple primary key columns.
/// </summary>
[TestMethod]
public async Task FindTestWithPaginationVerifMultiplePrimaryKeysInAfter()
{
string after = $"[{{\"EntityName\":\"Review\",\"FieldName\":\"book_id\",\"FieldValue\":1,\"Direction\":0}}," +
$"{{\"EntityName\":\"Review\",\"FieldName\":\"id\",\"FieldValue\":567,\"Direction\":0}}]";
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: $"?$first=1",
entityNameOrPath: _entityWithCompositePrimaryKey,
sqlQuery: GetQuery(nameof(FindTestWithPaginationVerifMultiplePrimaryKeysInAfter)),
expectedAfterQueryString: $"&$after={SqlPaginationUtil.Base64Encode(after)}",
paginated: true
);
}
/// <summary>
/// Tests the REST Api for Find operation using sorting
/// with integer type and null values.
/// </summary>
[TestMethod]
public async Task FindTestWithIntTypeNullValuesOrderByAsc()
{
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: "?$select=typeid,int_types&$orderby=int_types",
entityNameOrPath: _integrationTypeEntity,
sqlQuery: GetQuery(nameof(FindTestWithIntTypeNullValuesOrderByAsc))
);
}
/// <summary>
/// Validates that a proper nextLink is created for FindMany requests which do not
/// restrict results with query parameters AND the entity under test has mapped columns, including primary key column(s).
/// Engine default paging mechanisms are used when > 100 records will be present in result set.
/// expectedAfterQueryString starts with ?$, and not &$, because it is the only query parameter.
/// </summary>
[TestMethod]
public async Task FindMany_MappedColumn_NoOrderByQueryParameter()
{
string after = SqlPaginationUtil.Base64Encode($"[{{\"EntityName\":\"MappedBookmarks\",\"FieldName\":\"bkid\",\"FieldValue\":100,\"Direction\":0}}]");
await SetupAndRunRestApiTest(
primaryKeyRoute: string.Empty,
queryString: string.Empty,
entityNameOrPath: _integrationMappedPaginationEntityName,
sqlQuery: GetQuery(nameof(FindMany_MappedColumn_NoOrderByQueryParameter)),
paginated: true,
expectedAfterQueryString: $"?$after={after}"
);
}
/// <summary>
/// Tests the REST Api for Find operation for all records.
/// order by title in ascending order.
/// </summary>
[TestMethod]
public async Task FindTestWithQueryStringAllFieldsOrderByAsc()
{