@@ -97,7 +97,7 @@ public void ApplyFiltering_DisableNullHandlingUsingMapper()
97
97
}
98
98
99
99
[ Fact ]
100
- public void ApplyFiltering_DuplicateFiledName ( )
100
+ public void ApplyFiltering_DuplicatefieldName ( )
101
101
{
102
102
const string gq = "name=John|name=Sara" ;
103
103
var actual = _fakeRepository . AsQueryable ( )
@@ -457,6 +457,7 @@ public void ApplyFiltering_GreaterThanBetweenTwoStrings()
457
457
Assert . Equal ( expected , actual ) ;
458
458
Assert . True ( actual . Any ( ) ) ;
459
459
}
460
+
460
461
461
462
[ Fact ] // issue #27
462
463
public void ApplyFiltering_LessThanBetweenTwoStrings ( )
@@ -551,6 +552,43 @@ public void ApplyFiltering_NotEqual_ProcessingNullOrDefaultValueNonStringTypes()
551
552
Assert . Equal ( expected , actual ) ;
552
553
Assert . True ( actual . Any ( ) ) ;
553
554
}
555
+
556
+ [ Fact ] // issue #33
557
+ public void ApplyFiltering_WithSpaces ( )
558
+ {
559
+ var actual = _fakeRepository . AsQueryable ( ) . ApplyFiltering ( "name =ali reza" ) . ToList ( ) ;
560
+ var expected = _fakeRepository . Where ( q => q . Name == "ali reza" ) . ToList ( ) ;
561
+
562
+ Assert . Equal ( expected . Count , actual . Count ) ;
563
+ Assert . Equal ( expected , actual ) ;
564
+ Assert . True ( actual . Any ( ) ) ;
565
+ }
566
+
567
+
568
+ [ Fact ] // issue #34
569
+ public void ApplyFiltering_UnmappedFields_ShouldThrowException ( )
570
+ {
571
+ var gm = new GridifyMapper < TestClass > ( )
572
+ . AddMap ( "Id" , q => q . Id ) ;
573
+
574
+ var exp = Assert . Throws < GridifyMapperException > ( ( ) => _fakeRepository . AsQueryable ( ) . ApplyFiltering ( "name=John,id>0" , gm ) . ToList ( ) ) ;
575
+ Assert . Equal ( "Mapping 'name' not found" , exp . Message ) ;
576
+ }
577
+
578
+ [ Fact ] // issue #34
579
+ public void ApplyFiltering_UnmappedFields_ShouldSkipWhenIgnored ( )
580
+ {
581
+ var gm = new GridifyMapper < TestClass > ( configuration => configuration . IgnoreNotMappedFields = true )
582
+ . AddMap ( "Id" , q => q . Id ) ;
583
+
584
+ // name=*a filter should be ignored
585
+ var actual = _fakeRepository . AsQueryable ( ) . ApplyFiltering ( "name=*a, id>15" , gm ) . ToList ( ) ;
586
+ var expected = _fakeRepository . Where ( q => q . Id > 15 ) . ToList ( ) ;
587
+
588
+ Assert . Equal ( expected . Count , actual . Count ) ;
589
+ Assert . Equal ( expected , actual ) ;
590
+ Assert . True ( actual . Any ( ) ) ;
591
+ }
554
592
555
593
#endregion
556
594
@@ -644,12 +682,38 @@ public void ApplyOrdering_EmptyOrderBy_ShouldSkip()
644
682
[ Fact ]
645
683
public void ApplyOrdering_NullGridifyQuery_ShouldSkip ( )
646
684
{
685
+ GridifyQuery gq = null ;
647
686
var actual = _fakeRepository . AsQueryable ( )
648
- . ApplyOrdering ( null )
687
+ . ApplyOrdering ( gq )
649
688
. ToList ( ) ;
650
689
var expected = _fakeRepository . ToList ( ) ;
651
690
Assert . Equal ( expected , actual ) ;
652
691
}
692
+
693
+ [ Fact ] // issue #34
694
+ public void ApplyOrdering_UnmappedFields_ShouldThrowException ( )
695
+ {
696
+ var gm = new GridifyMapper < TestClass > ( )
697
+ . AddMap ( "Id" , q => q . Id ) ;
698
+
699
+ var exp = Assert . Throws < GridifyMapperException > ( ( ) => _fakeRepository . AsQueryable ( ) . ApplyOrdering ( "name,id" , gm ) . ToList ( ) ) ;
700
+ Assert . Equal ( "Mapping 'name' not found" , exp . Message ) ;
701
+ }
702
+
703
+ [ Fact ] // issue #34
704
+ public void ApplyOrdering_UnmappedFields_ShouldSkipWhenIgnored ( )
705
+ {
706
+ var gm = new GridifyMapper < TestClass > ( configuration => configuration . IgnoreNotMappedFields = true )
707
+ . AddMap ( "Id" , q => q . Id ) ;
708
+
709
+ // name orderBy should be ignored
710
+ var actual = _fakeRepository . AsQueryable ( ) . ApplyOrdering ( "name,id" , gm ) . ToList ( ) ;
711
+ var expected = _fakeRepository . OrderBy ( q => q . Id ) . ToList ( ) ;
712
+
713
+ Assert . Equal ( expected . Count , actual . Count ) ;
714
+ Assert . Equal ( expected , actual ) ;
715
+ Assert . True ( actual . Any ( ) ) ;
716
+ }
653
717
654
718
#endregion
655
719
@@ -784,7 +848,8 @@ private static IEnumerable<TestClass> GetSampleData()
784
848
lst . Add ( new TestClass ( 23 , "LI | AM" , null ) ) ;
785
849
lst . Add ( new TestClass ( 24 , "(LI,AM)" , null , tag : string . Empty ) ) ;
786
850
lst . Add ( new TestClass ( 25 , "Case/i" , null , tag : string . Empty ) ) ;
787
- lst . Add ( new TestClass ( 26 , "/iCase" , null ) ) ;
851
+ lst . Add ( new TestClass ( 26 , "/iCase" , null ) ) ;
852
+ lst . Add ( new TestClass ( 27 , "ali reza" , null ) ) ;
788
853
789
854
return lst ;
790
855
}
0 commit comments