@@ -20,12 +20,13 @@ public DateEqualToTests()
20
20
TestData = new TestData ( ) ;
21
21
}
22
22
23
- [ TestCase ( "SalaryDate" , "2024-10-29" , TestName = "'DateEqualTo' operation - Get expression (DateTime? value)" ) ]
23
+ [ TestCase ( "SalaryDate" , "2024-10-31" , TestName = "'DateEqualTo' operation - Get expression (DateTime? value)" ) ]
24
+ [ TestCase ( "SalaryDate" , "2024-10-30" , TestName = "'DateEqualTo' operation - Get expression (DateTime? value)" ) ]
24
25
public void GetExpressionDateTimeValueTest ( string propertyName , object value )
25
26
{
26
27
var dateValue = DateTime . Parse ( value . ToString ( ) ) ;
27
- dateValue = new DateTime ( dateValue . Year , dateValue . Month , dateValue . Day , 0 , 0 , 0 , DateTimeKind . Utc ) ;
28
- var endDate = dateValue . AddDays ( 1 ) . AddTicks ( - 1 ) ;
28
+ var startDate = dateValue . ToUniversalTime ( ) ;
29
+ var endDate = startDate . AddDays ( 1 ) . AddTicks ( - 1 ) ;
29
30
var operation = new DateEqualTo ( ) ;
30
31
var param = Expression . Parameter ( typeof ( Person ) , "x" ) ;
31
32
var member = Expression . Property ( param , propertyName ) ;
@@ -44,29 +45,30 @@ public void GetExpressionDateTimeValueTest(string propertyName, object value)
44
45
Assert . That ( ( shouldSubjectLeft . Left as MemberExpression ) . Member . Name , Is . EqualTo ( "Value" ) ) ;
45
46
Assert . That ( shouldSubjectLeft . NodeType , Is . EqualTo ( ExpressionType . GreaterThanOrEqual ) ) ;
46
47
Assert . That ( shouldSubjectLeft . Right , Is . AssignableFrom < ConstantExpression > ( ) ) ;
47
- Assert . That ( ( shouldSubjectLeft . Right as ConstantExpression ) . Value , Is . LessThanOrEqualTo ( dateValue ) ) ;
48
+ Assert . That ( ( shouldSubjectLeft . Right as ConstantExpression ) . Value , Is . GreaterThanOrEqualTo ( startDate ) ) ;
48
49
49
50
var shouldSubjectRight = ( BinaryExpression ) ( ( BinaryExpression ) expression . Right ) . Right ;
50
51
Assert . That ( ( shouldSubjectRight . Left as MemberExpression ) . Member . Name , Is . EqualTo ( "Value" ) ) ;
51
52
Assert . That ( shouldSubjectRight . NodeType , Is . EqualTo ( ExpressionType . LessThanOrEqual ) ) ;
52
53
Assert . That ( shouldSubjectRight . Right , Is . AssignableFrom < ConstantExpression > ( ) ) ;
53
- Assert . That ( ( shouldSubjectRight . Right as ConstantExpression ) . Value , Is . GreaterThanOrEqualTo ( dateValue ) ) ;
54
+ Assert . That ( ( shouldSubjectRight . Right as ConstantExpression ) . Value , Is . LessThanOrEqualTo ( endDate ) ) ;
54
55
55
56
//Testing the operation execution
56
57
var lambda = Expression . Lambda < Func < Person , bool > > ( expression , param ) ;
57
58
var people = TestData . People . Where ( lambda . Compile ( ) ) ;
58
- var solutionMethod = ( Func < Person , bool > ) GetType ( ) . GetMethod ( propertyName ) . Invoke ( this , [ dateValue , endDate ] ) ;
59
+ var solutionMethod = ( Func < Person , bool > ) GetType ( ) . GetMethod ( propertyName ) . Invoke ( this , [ startDate , endDate ] ) ;
59
60
var solution = TestData . People . Where ( solutionMethod ) ;
60
61
Assert . That ( people , Is . EquivalentTo ( solution ) ) ;
61
62
}
62
63
63
64
public static Func < Person , bool > SalaryDate ( DateTime startDate , DateTime endDate ) => x => x . SalaryDate != null && ( x . SalaryDate . Value >= startDate && x . SalaryDate . Value <= endDate ) ;
64
65
65
- [ TestCase ( "SalaryDateOffset" , "2024-10-29" , TestName = "'DateEqualTo Offset' operation - Get expression (DateTimeOffset? value)" ) ]
66
+ [ TestCase ( "SalaryDateOffset" , "2024-10-31" , TestName = "'DateEqualTo Offset' operation - Get expression (DateTimeOffset? value)" ) ]
67
+ [ TestCase ( "SalaryDateOffset" , "2024-10-30" , TestName = "'DateEqualTo Offset' operation - Get expression (DateTimeOffset? value)" ) ]
66
68
public void GetExpressionDateTimeOffsetValueTest ( string propertyName , object value )
67
69
{
68
70
var dateValue = DateTimeOffset . Parse ( value . ToString ( ) ) ;
69
- dateValue = new DateTimeOffset ( dateValue . Year , dateValue . Month , dateValue . Day , 0 , 0 , 0 , TimeSpan . Zero ) ;
71
+ var startDate = dateValue . ToUniversalTime ( ) ;
70
72
var endDate = dateValue . AddDays ( 1 ) . AddTicks ( - 1 ) ;
71
73
var operation = new DateEqualTo ( ) ;
72
74
var param = Expression . Parameter ( typeof ( Person ) , "x" ) ;
@@ -97,10 +99,10 @@ public void GetExpressionDateTimeOffsetValueTest(string propertyName, object val
97
99
//Testing the operation execution
98
100
var lambda = Expression . Lambda < Func < Person , bool > > ( expression , param ) ;
99
101
var people = TestData . People . Where ( lambda . Compile ( ) ) ;
100
- var solutionMethod = ( Func < Person , bool > ) GetType ( ) . GetMethod ( propertyName ) . Invoke ( this , [ dateValue , endDate ] ) ;
102
+ var solutionMethod = ( Func < Person , bool > ) GetType ( ) . GetMethod ( propertyName ) . Invoke ( this , [ startDate , endDate ] ) ;
101
103
var solution = TestData . People . Where ( solutionMethod ) ;
102
104
Assert . That ( people , Is . EquivalentTo ( solution ) ) ;
103
105
}
104
106
105
- public static Func < Person , bool > SalaryDateOffset ( DateTimeOffset startDate , DateTimeOffset endDate ) => x => x . SalaryDate != null && ( x . SalaryDate . Value >= startDate && x . SalaryDate . Value <= endDate ) ;
107
+ public static Func < Person , bool > SalaryDateOffset ( DateTimeOffset startDate , DateTimeOffset endDate ) => x => x . SalaryDateOffset != null && ( x . SalaryDateOffset . Value >= startDate && x . SalaryDateOffset . Value <= endDate ) ;
106
108
}
0 commit comments