@@ -35,59 +35,127 @@ public DateSegmentCriteriaTest(ITestOutputHelper output)
3535 {
3636 _output = output ;
3737 _min = DateTime . Parse ( "2000-1-1 10:10:10" ) ;
38- _max = DateTime . Parse ( "2000-1-2 10:10:10" ) ;
38+ _max = DateTime . Parse ( "2000-1-3 10:10:10" ) ;
3939 }
4040
4141 /// <summary>
42- /// 测试 - 获取查询条件
42+ /// 测试 - 获取查询条件 - 不包含边界
4343 /// </summary>
4444 [ Fact ]
45- public void Test_GetPredicate ( )
45+ public void Test_GetCondition_Neither ( )
46+ {
47+ var result = new StringBuilder ( ) ;
48+ result . Append ( "t => ((t.DateValue >= Convert(Parse(\" 2000/1/2 0:00:00\" ), DateTime))" ) ;
49+ result . Append ( " AndAlso (t.DateValue < Convert(Parse(\" 2000/1/3 0:00:00\" ), DateTime)))" ) ;
50+
51+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Neither ) ;
52+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
53+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
54+ }
55+
56+ /// <summary>
57+ /// 测试 - 获取查询条件 - 不包含边界【可空】
58+ /// </summary>
59+ [ Fact ]
60+ public void Test_GetCondition_Neither_With_Nullable ( )
61+ {
62+ var result = new StringBuilder ( ) ;
63+ result . Append ( "t => ((t.NullableDateValue >= Convert(Parse(\" 2000/1/2 0:00:00\" ), Nullable`1))" ) ;
64+ result . Append ( " AndAlso (t.NullableDateValue < Convert(Parse(\" 2000/1/3 0:00:00\" ), Nullable`1)))" ) ;
65+
66+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Neither ) ;
67+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
68+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
69+ }
70+
71+ /// <summary>
72+ /// 测试 - 获取查询条件 - 包含左边
73+ /// </summary>
74+ [ Fact ]
75+ public void Test_GetCondition_Left ( )
4676 {
4777 var result = new StringBuilder ( ) ;
4878 result . Append ( "t => ((t.DateValue >= Convert(Parse(\" 2000/1/1 0:00:00\" ), DateTime))" ) ;
4979 result . Append ( " AndAlso (t.DateValue < Convert(Parse(\" 2000/1/3 0:00:00\" ), DateTime)))" ) ;
50- var criteria = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Both ) ;
51- _output . WriteLine ( criteria . GetCondition ( ) . ToString ( ) ) ;
52- Assert . Equal ( result . ToString ( ) , criteria . GetCondition ( ) . ToString ( ) ) ;
5380
54- result = new StringBuilder ( ) ;
81+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Left ) ;
82+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
83+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
84+ }
85+
86+ /// <summary>
87+ /// 测试 - 获取查询条件 - 包含左边【可空】
88+ /// </summary>
89+ [ Fact ]
90+ public void Test_GetCondition_Left_With_Nullable ( )
91+ {
92+ var result = new StringBuilder ( ) ;
5593 result . Append ( "t => ((t.NullableDateValue >= Convert(Parse(\" 2000/1/1 0:00:00\" ), Nullable`1))" ) ;
5694 result . Append ( " AndAlso (t.NullableDateValue < Convert(Parse(\" 2000/1/3 0:00:00\" ), Nullable`1)))" ) ;
57- var criteria2 = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Both ) ;
58- _output . WriteLine ( criteria2 . GetCondition ( ) . ToString ( ) ) ;
59- Assert . Equal ( result . ToString ( ) , criteria2 . GetCondition ( ) . ToString ( ) ) ;
95+
96+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Left ) ;
97+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
98+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
6099 }
61100
62101 /// <summary>
63- /// 测试 - 获取查询条件 - 设置边界
102+ /// 测试 - 获取查询条件 - 包含右边
64103 /// </summary>
65104 [ Fact ]
66- public void Test_GetPredicate_Boundary ( )
105+ public void Test_GetCondition_Right ( )
67106 {
68107 var result = new StringBuilder ( ) ;
69- result . Append ( "t => ((t.DateValue > Convert(Parse(\" 2000/1/1 0:00:00\" ), DateTime))" ) ;
70- result . Append ( " AndAlso (t.DateValue < Convert(Parse(\" 2000/1/3 0:00:00\" ), DateTime)))" ) ;
71- var criteria = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Neither ) ;
72- Assert . Equal ( result . ToString ( ) , criteria . GetCondition ( ) . ToString ( ) ) ;
108+ result . Append ( "t => ((t.DateValue >= Convert(Parse(\" 2000/1/2 0:00:00\" ), DateTime))" ) ;
109+ result . Append ( " AndAlso (t.DateValue < Convert(Parse(\" 2000/1/4 0:00:00\" ), DateTime)))" ) ;
110+
111+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Right ) ;
112+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
113+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
114+ }
73115
74- result = new StringBuilder ( ) ;
116+ /// <summary>
117+ /// 测试 - 获取查询条件 - 包含右边【可空】
118+ /// </summary>
119+ [ Fact ]
120+ public void Test_GetCondition_Right_With_Nullable ( )
121+ {
122+ var result = new StringBuilder ( ) ;
123+ result . Append ( "t => ((t.NullableDateValue >= Convert(Parse(\" 2000/1/2 0:00:00\" ), Nullable`1))" ) ;
124+ result . Append ( " AndAlso (t.NullableDateValue < Convert(Parse(\" 2000/1/4 0:00:00\" ), Nullable`1)))" ) ;
125+
126+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Right ) ;
127+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
128+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
129+ }
130+
131+ /// <summary>
132+ /// 测试 - 获取查询条件 - 包含两边
133+ /// </summary>
134+ [ Fact ]
135+ public void Test_GetCondition_Both ( )
136+ {
137+ var result = new StringBuilder ( ) ;
75138 result . Append ( "t => ((t.DateValue >= Convert(Parse(\" 2000/1/1 0:00:00\" ), DateTime))" ) ;
76- result . Append ( " AndAlso (t.DateValue < Convert(Parse(\" 2000/1/3 0:00:00\" ), DateTime)))" ) ;
77- criteria = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Left ) ;
78- Assert . Equal ( result . ToString ( ) , criteria . GetCondition ( ) . ToString ( ) ) ;
139+ result . Append ( " AndAlso (t.DateValue < Convert(Parse(\" 2000/1/4 0:00:00\" ), DateTime)))" ) ;
79140
80- result = new StringBuilder ( ) ;
81- result . Append ( "t => ((t.NullableDateValue > Convert(Parse(\" 2000/1/1 0:00:00\" ), Nullable`1))" ) ;
82- result . Append ( " AndAlso (t.NullableDateValue <= Convert(Parse(\" 2000/1/3 0:00:00\" ), Nullable`1)))" ) ;
83- var criteria2 = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Right ) ;
84- Assert . Equal ( result . ToString ( ) , criteria2 . GetCondition ( ) . ToString ( ) ) ;
141+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime > ( t => t . DateValue , _min , _max , Boundary . Both ) ;
142+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
143+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
144+ }
85145
86- result = new StringBuilder ( ) ;
146+ /// <summary>
147+ /// 测试 - 获取查询条件 - 包含两边【可空】
148+ /// </summary>
149+ [ Fact ]
150+ public void Test_GetCondition_Both_With_Nullable ( )
151+ {
152+ var result = new StringBuilder ( ) ;
87153 result . Append ( "t => ((t.NullableDateValue >= Convert(Parse(\" 2000/1/1 0:00:00\" ), Nullable`1))" ) ;
88- result . Append ( " AndAlso (t.NullableDateValue <= Convert(Parse(\" 2000/1/3 0:00:00\" ), Nullable`1)))" ) ;
89- criteria2 = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Both ) ;
90- Assert . Equal ( result . ToString ( ) , criteria2 . GetCondition ( ) . ToString ( ) ) ;
154+ result . Append ( " AndAlso (t.NullableDateValue < Convert(Parse(\" 2000/1/4 0:00:00\" ), Nullable`1)))" ) ;
155+
156+ var condition = new DateSegmentCondition < AggregateRootSample , DateTime ? > ( t => t . NullableDateValue , _min , _max , Boundary . Both ) ;
157+ _output . WriteLine ( condition . GetCondition ( ) . ToString ( ) ) ;
158+ Assert . Equal ( result . ToString ( ) , condition . GetCondition ( ) . ToString ( ) ) ;
91159 }
92160 }
93161}
0 commit comments