@@ -37,23 +37,28 @@ protected override void OnTearDown()
3737 }
3838
3939 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 )
4048 {
4149 var sb = new StringBuilder ( ) ;
4250 var guidType = Dialect . GetTypeName ( SqlTypeFactory . Guid ) ;
4351 var stringType = Dialect . GetTypeName ( SqlTypeFactory . GetAnsiString ( 255 ) ) ;
4452
4553 var catalog = GetQuotedDefaultCatalog ( ) ;
4654 var schema = GetQuotedDefaultSchema ( ) ;
47- var table = GetQualifiedName ( catalog , schema , "LocaleEntity ") ;
55+ var table = GetQualifiedName ( catalog , schema , $ " { name } Entity ") ;
4856
4957 sb . Append ( $ "{ Dialect . CreateTableString } { table } (") ;
5058
5159 // Generate columns
5260 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 } , ") ;
5762
5863 // Add the primary key contraint for the identity column
5964 sb . Append ( $ ", { Dialect . PrimaryKeyString } ( Id )") ;
@@ -81,7 +86,7 @@ private string GetQuotedDefaultCatalog()
8186 var t = cfg . GetType ( ) ;
8287 var getQuotedDefaultCatalog = t . GetMethod ( "GetQuotedDefaultCatalog" , BindingFlags . Instance | BindingFlags . NonPublic ) ;
8388
84- return ( string ) getQuotedDefaultCatalog . Invoke ( cfg , [ Dialect ] ) ;
89+ return ( string ) getQuotedDefaultCatalog . Invoke ( cfg , [ Dialect ] ) ;
8590 }
8691
8792 private string GetQuotedDefaultSchema ( )
@@ -97,19 +102,19 @@ private string GetQualifiedName(string catalog, string schema, string name)
97102 return Dialect . Qualify ( catalog , schema , name ) ;
98103 }
99104
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 ( )
102108 {
103- DateTime leapDay = new DateTime ( 2024 , 2 , 29 , new GregorianCalendar ( GregorianCalendarTypes . USEnglish ) ) ;
104109 object id ;
105110
106111 CurrentCulture = from ;
107112 using ( var session = OpenSession ( ) )
108113 using ( var tx = session . BeginTransaction ( ) )
109114 {
110- var entity = new LocaleEntity ( )
115+ var entity = new U ( )
111116 {
112- DateTimeValue = leapDay
117+ Value = expectedValue
113118 } ;
114119
115120 id = session . Save ( entity ) ;
@@ -120,96 +125,45 @@ public void TestDateTime(CultureInfo from, CultureInfo to)
120125 using ( var session = OpenSession ( ) )
121126 using ( var tx = session . BeginTransaction ( ) )
122127 {
123- var entity = session . Get < LocaleEntity > ( id ) ;
128+ var entity = session . Get < U > ( id ) ;
124129
125- Assert . AreEqual ( leapDay , entity . DateTimeValue ) ;
130+ assert ( expectedValue , entity . Value ) ;
126131 }
127132 }
128133
129134 [ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
130- public void TestDecimal ( CultureInfo from , CultureInfo to )
135+ public void TestDateTime ( CultureInfo from , CultureInfo to )
131136 {
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 ) ) ;
143138
144- id = session . Save ( entity ) ;
145- tx . Commit ( ) ;
146- }
139+ PerformTest < DateTime , DateTimeEntity > ( from , to , leapDay , ( expected , actual ) => Assert . AreEqual ( expected , actual ) ) ;
140+ }
147141
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 ;
153146
154- Assert . AreEqual ( decimalValue , entity . DecimalValue ) ;
155- }
147+ PerformTest < decimal , DecimalEntity > ( from , to , decimalValue , ( expected , actual ) => Assert . AreEqual ( expected , actual ) ) ;
156148 }
157149
158150 [ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
159151 public void TestDouble ( CultureInfo from , CultureInfo to )
160152 {
161153 double doubleValue = 12.3d ;
162- object id ;
163154
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+ ) ;
185158 }
186159
160+ [ Test , TestCaseSource ( nameof ( GetTestCases ) ) ]
161+
187162 public void TestInteger ( CultureInfo from , CultureInfo to )
188163 {
189164 int integerValue = 123 ;
190- object id ;
191165
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 ) ) ;
213167 }
214168
215169 private CultureInfo CurrentCulture
0 commit comments