@@ -37,23 +37,28 @@ protected override void OnTearDown()
37
37
}
38
38
39
39
protected override void CreateSchema ( )
40
+ {
41
+ CreateTable ( "Integer" ) ;
42
+ CreateTable ( "DateTime" ) ;
43
+ CreateTable ( "Double" ) ;
44
+ CreateTable ( "Decimal" ) ;
45
+ }
46
+
47
+ private void CreateTable ( string name )
40
48
{
41
49
var sb = new StringBuilder ( ) ;
42
50
var guidType = Dialect . GetTypeName ( SqlTypeFactory . Guid ) ;
43
51
var stringType = Dialect . GetTypeName ( SqlTypeFactory . GetAnsiString ( 255 ) ) ;
44
52
45
53
var catalog = GetQuotedDefaultCatalog ( ) ;
46
54
var schema = GetQuotedDefaultSchema ( ) ;
47
- var table = GetQualifiedName ( catalog , schema , "LocaleEntity ") ;
55
+ var table = GetQualifiedName ( catalog , schema , $ " { name } Entity ") ;
48
56
49
57
sb . Append ( $ "{ Dialect . CreateTableString } { table } (") ;
50
58
51
59
// Generate columns
52
60
sb . Append ( $ "Id { guidType } , ") ;
53
- sb . Append ( $ "IntegerValue { stringType } , ") ;
54
- sb . Append ( $ "DateTimeValue { stringType } , ") ;
55
- sb . Append ( $ "DoubleValue { stringType } , ") ;
56
- sb . Append ( $ "DecimalValue { stringType } ") ;
61
+ sb . Append ( $ "Value { stringType } , ") ;
57
62
58
63
// Add the primary key contraint for the identity column
59
64
sb . Append ( $ ", { Dialect . PrimaryKeyString } ( Id )") ;
@@ -81,7 +86,7 @@ private string GetQuotedDefaultCatalog()
81
86
var t = cfg . GetType ( ) ;
82
87
var getQuotedDefaultCatalog = t . GetMethod ( "GetQuotedDefaultCatalog" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
83
88
84
- return ( string ) getQuotedDefaultCatalog . Invoke ( cfg , [ Dialect ] ) ;
89
+ return ( string ) getQuotedDefaultCatalog . Invoke ( cfg , [ Dialect ] ) ;
85
90
}
86
91
87
92
private string GetQuotedDefaultSchema ( )
@@ -97,19 +102,19 @@ private string GetQualifiedName(string catalog, string schema, string name)
97
102
return Dialect . Qualify ( catalog , schema , name ) ;
98
103
}
99
104
100
- [ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
101
- public void TestDateTime ( CultureInfo from , CultureInfo to )
105
+ private void PerformTest < T , U > ( CultureInfo from , CultureInfo to , T expectedValue , Action < T , T > assert )
106
+ where T : struct
107
+ where U : Entity < T > , new ( )
102
108
{
103
- DateTime leapDay = new DateTime ( 2024 , 2 , 29 , new GregorianCalendar ( GregorianCalendarTypes . USEnglish ) ) ;
104
109
object id ;
105
110
106
111
CurrentCulture = from ;
107
112
using ( var session = OpenSession ( ) )
108
113
using ( var tx = session . BeginTransaction ( ) )
109
114
{
110
- var entity = new LocaleEntity ( )
115
+ var entity = new U ( )
111
116
{
112
- DateTimeValue = leapDay
117
+ Value = expectedValue
113
118
} ;
114
119
115
120
id = session . Save ( entity ) ;
@@ -120,96 +125,45 @@ public void TestDateTime(CultureInfo from, CultureInfo to)
120
125
using ( var session = OpenSession ( ) )
121
126
using ( var tx = session . BeginTransaction ( ) )
122
127
{
123
- var entity = session . Get < LocaleEntity > ( id ) ;
128
+ var entity = session . Get < U > ( id ) ;
124
129
125
- Assert . AreEqual ( leapDay , entity . DateTimeValue ) ;
130
+ assert ( expectedValue , entity . Value ) ;
126
131
}
127
132
}
128
133
129
134
[ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
130
- public void TestDecimal ( CultureInfo from , CultureInfo to )
135
+ public void TestDateTime ( CultureInfo from , CultureInfo to )
131
136
{
132
- decimal decimalValue = 12.3m ;
133
- object id ;
134
-
135
- CurrentCulture = from ;
136
- using ( var session = OpenSession ( ) )
137
- using ( var tx = session . BeginTransaction ( ) )
138
- {
139
- var entity = new LocaleEntity ( )
140
- {
141
- DecimalValue = decimalValue
142
- } ;
137
+ DateTime leapDay = new DateTime ( 2024 , 2 , 29 , new GregorianCalendar ( GregorianCalendarTypes . USEnglish ) ) ;
143
138
144
- id = session . Save ( entity ) ;
145
- tx . Commit ( ) ;
146
- }
139
+ PerformTest < DateTime , DateTimeEntity > ( from , to , leapDay , ( expected , actual ) => Assert . AreEqual ( expected , actual ) ) ;
140
+ }
147
141
148
- CurrentCulture = to ;
149
- using ( var session = OpenSession ( ) )
150
- using ( var tx = session . BeginTransaction ( ) )
151
- {
152
- var entity = session . Get < LocaleEntity > ( id ) ;
142
+ [ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
143
+ public void TestDecimal ( CultureInfo from , CultureInfo to )
144
+ {
145
+ decimal decimalValue = 12.3m ;
153
146
154
- Assert . AreEqual ( decimalValue , entity . DecimalValue ) ;
155
- }
147
+ PerformTest < decimal , DecimalEntity > ( from , to , decimalValue , ( expected , actual ) => Assert . AreEqual ( expected , actual ) ) ;
156
148
}
157
149
158
150
[ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
159
151
public void TestDouble ( CultureInfo from , CultureInfo to )
160
152
{
161
153
double doubleValue = 12.3d ;
162
- object id ;
163
154
164
- CurrentCulture = from ;
165
- using ( var session = OpenSession ( ) )
166
- using ( var tx = session . BeginTransaction ( ) )
167
- {
168
- var entity = new LocaleEntity ( )
169
- {
170
- DoubleValue = doubleValue
171
- } ;
172
-
173
- id = session . Save ( entity ) ;
174
- tx . Commit ( ) ;
175
- }
176
-
177
- CurrentCulture = to ;
178
- using ( var session = OpenSession ( ) )
179
- using ( var tx = session . BeginTransaction ( ) )
180
- {
181
- var entity = session . Get < LocaleEntity > ( id ) ;
182
-
183
- Assert . True ( Math . Abs ( doubleValue - entity . DoubleValue ) < double . Epsilon , $ "Expected: { doubleValue } \n But was: { entity . DoubleValue } \n ") ;
184
- }
155
+ PerformTest < double , DoubleEntity > ( from , to , doubleValue ,
156
+ ( expected , actual ) => Assert . True ( Math . Abs ( expected - actual ) < double . Epsilon , $ "Expected: { expected } \n But was: { actual } \n ")
157
+ ) ;
185
158
}
186
159
160
+ [ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
161
+
187
162
public void TestInteger ( CultureInfo from , CultureInfo to )
188
163
{
189
164
int integerValue = 123 ;
190
- object id ;
191
165
192
- CurrentCulture = from ;
193
- using ( var session = OpenSession ( ) )
194
- using ( var tx = session . BeginTransaction ( ) )
195
- {
196
- var entity = new LocaleEntity ( )
197
- {
198
- IntegerValue = integerValue
199
- } ;
200
-
201
- id = session . Save ( entity ) ;
202
- tx . Commit ( ) ;
203
- }
204
-
205
- CurrentCulture = to ;
206
- using ( var session = OpenSession ( ) )
207
- using ( var tx = session . BeginTransaction ( ) )
208
- {
209
- var entity = session . Get < LocaleEntity > ( id ) ;
210
-
211
- Assert . AreEqual ( integerValue , entity . IntegerValue ) ;
212
- }
166
+ PerformTest < int , IntegerEntity > ( from , to , integerValue , ( expected , actual ) => Assert . AreEqual ( expected , actual ) ) ;
213
167
}
214
168
215
169
private CultureInfo CurrentCulture
0 commit comments