44using System . Collections ;
55using System . Collections . Generic ;
66using System . Linq ;
7- using System . Text ;
8- using System . Threading ;
97
108namespace Mvc . JQuery . DataTables . Tests
119{
@@ -15,7 +13,7 @@ public class Linq
1513 internal const int SomeModelPropertyCount = 4 ;
1614 internal const int SomeViewPropertyCount = 4 ;
1715 private const int TotalRecords = 100 ;
18- private const int DisplayLength = 5 ;
16+ internal const int DisplayLength = 5 ;
1917
2018 protected IQueryable < SomeModel > SomeModelQueryable { get ; set ; }
2119
@@ -34,49 +32,19 @@ public Linq()
3432 }
3533 SomeModelQueryable = dataSet . AsQueryable ( ) ;
3634 }
37-
38- [ Test ( Description = "Simple Ordering ") ]
39- public void SimpleOrder ( )
35+
36+ [ Test , TestCaseSource ( typeof ( MyFactoryClass ) , "TestCases ") ]
37+ public virtual int [ ] ExecuteParams ( DataTablesParam dataTablesParam )
4038 {
41- var dataTablesParam = EmptyParam ( ) ;
42- dataTablesParam . sSortDir [ 0 ] = "asc" ;
43- dataTablesParam . iSortingCols = 1 ;
44- var result = DataTablesResult . Create ( SomeModelQueryable , //DataContext.Models,
39+ var result = DataTablesResult . Create ( SomeModelQueryable ,
4540 dataTablesParam ,
4641 model => model ) ;
4742 var data = ( DataTablesData ) result . Data ;
48- Assert . AreEqual ( data . RecordIds ( ) , Enumerable . Range ( 1 , DisplayLength ) . ToArray ( ) ) ;
43+ return data . RecordIds ( ) ;
4944 }
50- [ Test ( Description = "Simple Ordering with transform to view model" ) ]
51- public void SimpleOrderAndTransform ( )
52- {
53- var dataTablesParam = EmptyParam ( ) ;
54- dataTablesParam . sSortDir [ 0 ] = "asc" ;
55- dataTablesParam . iSortingCols = 1 ;
56- Assert . AreEqual ( ExecuteParams ( dataTablesParam ) . RecordIds ( ) , Enumerable . Range ( 1 , DisplayLength ) . ToArray ( ) ) ;
57- }
58-
59- [ Test ( Description = "Single Record Text Search" ) ]
60- public void SingleRecordSearch ( )
61- {
62- var dataTablesParam = EmptyParam ( ) ;
63- //dataTablesParam.sSortDir[0] = "asc";
64- dataTablesParam . sSearch = "Name 10" ;
6545
66- Assert . AreEqual ( ExecuteParams ( dataTablesParam ) . RecordIds ( ) , new int [ ] { 10 } ) ;
67- }
68- [ Test ( Description = "Combination of Sort, Filter & Paginate" ) ]
69- public void SortFilterPage ( )
70- {
71- var dataTablesParam = EmptyParam ( ) ;
72- dataTablesParam . iSortingCols = 1 ;
73- dataTablesParam . iSortCol [ 0 ] = 2 ;
74- dataTablesParam . sSearchColumns [ 3 ] = "25~35" ;
75- dataTablesParam . iDisplayStart = 6 ;
76- var result = ExecuteParams ( dataTablesParam ) . RecordIds ( ) ;
77- Assert . AreEqual ( ExecuteParams ( dataTablesParam ) . RecordIds ( ) , new int [ ] { 17 , 21 , 25 , 77 , 81 } ) ;
78- }
79- private DataTablesData ExecuteParams ( DataTablesParam dataTablesParam )
46+ [ Test , TestCaseSource ( typeof ( MyFactoryClass ) , "TestCases" ) ]
47+ public virtual int [ ] ExecuteParamsAndTransform ( DataTablesParam dataTablesParam )
8048 {
8149 var result = DataTablesResult . Create ( SomeModelQueryable ,
8250 dataTablesParam ,
@@ -87,10 +55,44 @@ private DataTablesData ExecuteParams(DataTablesParam dataTablesParam)
8755 ViewScale = model . Scale ,
8856 Id = model . Id
8957 } ) ;
90- return ( DataTablesData ) result . Data ;
58+ var data = ( DataTablesData ) result . Data ;
59+ return data . RecordIds ( ) ;
9160 }
61+ }
62+ public static class MyFactoryClass
63+ {
64+ public static IEnumerable TestCases
65+ {
66+ get
67+ {
68+ var dataTablesParam = EmptyParam ( ) ;
69+ dataTablesParam . sSortDir [ 0 ] = "asc" ;
70+ dataTablesParam . iSortingCols = 1 ;
71+ yield return new TestCaseData ( dataTablesParam )
72+ . Returns ( Enumerable . Range ( 1 , Linq . DisplayLength ) . ToArray ( ) )
73+ . SetName ( "SimpleOrder" )
74+ . SetDescription ( "Simple Ordering" ) ;
75+
76+ dataTablesParam = EmptyParam ( ) ;
77+ dataTablesParam . sSearch = "Name 10" ;
78+ yield return new TestCaseData ( dataTablesParam )
79+ . Returns ( new int [ ] { 10 } )
80+ . SetName ( "SingleRecordSearch" )
81+ . SetDescription ( "Single Record Text Search" ) ;
9282
93- protected static DataTablesParam EmptyParam ( int columns = SomeModelPropertyCount )
83+ dataTablesParam = EmptyParam ( ) ;
84+ dataTablesParam . iSortingCols = 1 ;
85+ dataTablesParam . iSortCol [ 0 ] = 2 ;
86+ dataTablesParam . sSearchColumns [ 3 ] = "25~35" ;
87+ dataTablesParam . iDisplayStart = 6 ;
88+ yield return new TestCaseData ( dataTablesParam )
89+ . Returns ( new int [ ] { 17 , 21 , 25 , 77 , 81 } )
90+ . SetName ( "SortFilterPage" )
91+ . SetDescription ( "Combination of Sort, Filter & Paginate" ) ;
92+ }
93+ }
94+
95+ public static DataTablesParam EmptyParam ( int columns = Linq . SomeModelPropertyCount )
9496 {
9597 return new DataTablesParam
9698 {
@@ -99,8 +101,8 @@ protected static DataTablesParam EmptyParam(int columns = SomeModelPropertyCount
99101 bSearchable = LinqTestStaticMethods . Populate < bool > ( true , columns ) ,
100102 bSortable = LinqTestStaticMethods . Populate < bool > ( true , columns ) ,
101103 iColumns = columns ,
102- iDisplayLength = DisplayLength ,
103- iSortingCols = 1 ,
104+ iDisplayLength = Linq . DisplayLength ,
105+ iSortingCols = 1 ,
104106 iSortCol = LinqTestStaticMethods . Populate < int > ( 0 , columns ) ,
105107 sEcho = 1 ,
106108 sSearchColumns = LinqTestStaticMethods . Populate < string > ( "" , columns ) ,
@@ -109,6 +111,7 @@ protected static DataTablesParam EmptyParam(int columns = SomeModelPropertyCount
109111 } ;
110112 }
111113 }
114+
112115 public static class LinqTestStaticMethods
113116 {
114117 public static int [ ] RecordIds ( this DataTablesData data )
0 commit comments