File tree Expand file tree Collapse file tree 2 files changed +40
-3
lines changed
NHibernate.Test/NHSpecificTest/NH2982 Expand file tree Collapse file tree 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 1
- using NUnit . Framework ;
1
+ using System ;
2
+ using NUnit . Framework ;
2
3
using NHibernate . Criterion ;
3
4
4
5
namespace NHibernate . Test . NHSpecificTest . NH2982
@@ -65,5 +66,29 @@ public void SimpleExpressionWithPrimitive()
65
66
var restriction = Restrictions . Eq ( "A" , 5 ) ;
66
67
Assert . AreEqual ( "A = 5" , restriction . ToString ( ) ) ;
67
68
}
69
+
70
+ [ Test ]
71
+ public void SimpleExpressionWithNullablePrimitive ( )
72
+ {
73
+ int ? value = null ;
74
+ value = 5 ;
75
+ var restriction = Restrictions . Eq ( "A" , value ) ;
76
+ Assert . AreEqual ( "A = 5" , restriction . ToString ( ) ) ;
77
+ }
78
+
79
+ [ Test ]
80
+ public void SimpleExpressionWithString ( )
81
+ {
82
+ var restriction = Restrictions . Like ( "A" , "Test" ) ;
83
+ Assert . AreEqual ( "A like Test" , restriction . ToString ( ) ) ;
84
+ }
85
+
86
+ [ Test ]
87
+ public void SimpleExpressionWithNullableDate ( )
88
+ {
89
+ DateTime ? date = new DateTime ( 2012 , 1 , 1 ) ;
90
+ var restriction = Restrictions . Eq ( "A" , date ) ;
91
+ Assert . AreEqual ( "A = " + date , restriction . ToString ( ) ) ;
92
+ }
68
93
}
69
94
}
Original file line number Diff line number Diff line change @@ -173,12 +173,24 @@ protected virtual string Op
173
173
get { return op ; }
174
174
}
175
175
176
- string ValueToStrings ( )
176
+ private static readonly System . Type [ ] CallToStringTypes = new [ ]
177
177
{
178
- if ( value != null && value . GetType ( ) . IsPrimitive )
178
+ typeof ( DateTime ) ,
179
+ typeof ( string ) ,
180
+ } ;
181
+
182
+ private string ValueToStrings ( )
183
+ {
184
+ if ( value == null )
185
+ {
186
+ return "null" ;
187
+ }
188
+ var type = value . GetType ( ) ;
189
+ if ( type . IsPrimitive || CallToStringTypes . Any ( t => t . IsAssignableFrom ( type ) ) )
179
190
{
180
191
return value . ToString ( ) ;
181
192
}
193
+
182
194
return ObjectHelpers . IdentityToString ( value ) ;
183
195
}
184
196
}
You can’t perform that action at this time.
0 commit comments