@@ -79,57 +79,51 @@ public CustomSqlTests(DialectContext context) : base(context) {}
7979 public void Can_create_field_with_custom_sql ( )
8080 {
8181 OrmLiteConfig . BeforeExecFilter = cmd => cmd . GetDebugString ( ) . Print ( ) ;
82-
83- using ( var db = OpenDbConnection ( ) )
84- {
85- db . DropAndCreateTable < PocoTable > ( ) ;
8682
87- var createTableSql = db . GetLastSql ( ) . NormalizeSql ( ) ;
83+ using var db = OpenDbConnection ( ) ;
84+ db . DropAndCreateTable < PocoTable > ( ) ;
8885
89- createTableSql . Print ( ) ;
86+ var createTableSql = db . GetLastSql ( ) . NormalizeSql ( ) ;
9087
91- if ( Dialect != Dialect . Firebird )
92- {
93- Assert . That ( createTableSql , Does . Contain ( "charcolumn char(20) null" ) ) ;
94- Assert . That ( createTableSql , Does . Contain ( "decimalcolumn decimal(18,4) null" ) ) ;
95- }
96- else
97- {
98- Assert . That ( createTableSql , Does . Contain ( "charcolumn char(20)" ) ) ;
99- Assert . That ( createTableSql , Does . Contain ( "decimalcolumn decimal(18,4)" ) ) ;
100- }
88+ createTableSql . Print ( ) ;
89+
90+ if ( Dialect != Dialect . Firebird )
91+ {
92+ Assert . That ( createTableSql , Does . Contain ( "charcolumn char(20) null" ) ) ;
93+ Assert . That ( createTableSql , Does . Contain ( "decimalcolumn decimal(18,4) null" ) ) ;
94+ }
95+ else
96+ {
97+ Assert . That ( createTableSql , Does . Contain ( "charcolumn char(20)" ) ) ;
98+ Assert . That ( createTableSql , Does . Contain ( "decimalcolumn decimal(18,4)" ) ) ;
10199 }
102100 }
103101
104102 [ Test ]
105103 public void Does_execute_CustomSql_before_table_created ( )
106104 {
107- using ( var db = OpenDbConnection ( ) )
105+ using var db = OpenDbConnection ( ) ;
106+ try
108107 {
109- try
110- {
111- db . CreateTable < ModelWithPreCreateSql > ( ) ;
112- Assert . Fail ( "Should throw" ) ;
113- }
114- catch ( Exception )
115- {
116- Assert . That ( ! db . TableExists ( "ModelWithPreCreateSql" . SqlColumn ( DialectProvider ) ) ) ;
117- }
108+ db . CreateTable < ModelWithPreCreateSql > ( ) ;
109+ Assert . Fail ( "Should throw" ) ;
110+ }
111+ catch ( Exception )
112+ {
113+ Assert . That ( ! db . TableExists ( "ModelWithPreCreateSql" . SqlColumn ( DialectProvider ) ) ) ;
118114 }
119115 }
120116
121117 [ Test ]
122118 [ IgnoreDialect ( Dialect . AnyOracle | Dialect . AnyPostgreSql , "multiple SQL statements need to be wrapped in an anonymous block" ) ]
123119 public void Does_execute_CustomSql_after_table_created ( )
124120 {
125- using ( var db = OpenDbConnection ( ) )
126- {
127- db . DropAndCreateTable < ModelWithSeedDataSql > ( ) ;
121+ using var db = OpenDbConnection ( ) ;
122+ db . DropAndCreateTable < ModelWithSeedDataSql > ( ) ;
128123
129- var seedDataNames = db . Select < ModelWithSeedDataSql > ( ) . ConvertAll ( x => x . Name ) ;
124+ var seedDataNames = db . Select < ModelWithSeedDataSql > ( ) . ConvertAll ( x => x . Name ) ;
130125
131- Assert . That ( seedDataNames , Is . EquivalentTo ( new [ ] { "Foo" , "Bar" } ) ) ;
132- }
126+ Assert . That ( seedDataNames , Is . EquivalentTo ( new [ ] { "Foo" , "Bar" } ) ) ;
133127 }
134128
135129 [ Test ]
@@ -141,49 +135,43 @@ public void Does_execute_CustomSql_after_table_created_using_dynamic_attribute()
141135 "INSERT INTO {0} (Name) VALUES ('Foo');" . Fmt ( "DynamicAttributeSeedData" . SqlTable ( DialectProvider ) ) +
142136 "INSERT INTO {0} (Name) VALUES ('Bar');" . Fmt ( "DynamicAttributeSeedData" . SqlTable ( DialectProvider ) ) ) ) ;
143137
144- using ( var db = OpenDbConnection ( ) )
145- {
146- db . DropAndCreateTable < DynamicAttributeSeedData > ( ) ;
138+ using var db = OpenDbConnection ( ) ;
139+ db . DropAndCreateTable < DynamicAttributeSeedData > ( ) ;
147140
148- var seedDataNames = db . Select < DynamicAttributeSeedData > ( ) . ConvertAll ( x => x . Name ) ;
141+ var seedDataNames = db . Select < DynamicAttributeSeedData > ( ) . ConvertAll ( x => x . Name ) ;
149142
150- Assert . That ( seedDataNames , Is . EquivalentTo ( new [ ] { "Foo" , "Bar" } ) ) ;
151- }
143+ Assert . That ( seedDataNames , Is . EquivalentTo ( new [ ] { "Foo" , "Bar" } ) ) ;
152144 }
153145
154146 [ Test ]
155147 public void Does_execute_CustomSql_before_table_dropped ( )
156148 {
157- using ( var db = OpenDbConnection ( ) )
149+ using var db = OpenDbConnection ( ) ;
150+ db . CreateTable < ModelWithPreDropSql > ( ) ;
151+ try
158152 {
159- db . CreateTable < ModelWithPreDropSql > ( ) ;
160- try
161- {
162- db . DropTable < ModelWithPreDropSql > ( ) ;
163- Assert . Fail ( "Should throw" ) ;
164- }
165- catch ( Exception )
166- {
167- Assert . That ( db . TableExists ( "ModelWithPreDropSql" . SqlTableRaw ( DialectProvider ) ) ) ;
168- }
153+ db . DropTable < ModelWithPreDropSql > ( ) ;
154+ Assert . Fail ( "Should throw" ) ;
155+ }
156+ catch ( Exception )
157+ {
158+ Assert . That ( db . TableExists ( "ModelWithPreDropSql" . SqlTableRaw ( DialectProvider ) ) ) ;
169159 }
170160 }
171161
172162 [ Test ]
173163 public void Does_execute_CustomSql_after_table_dropped ( )
174164 {
175- using ( var db = OpenDbConnection ( ) )
165+ using var db = OpenDbConnection ( ) ;
166+ db . CreateTable < ModelWithPostDropSql > ( ) ;
167+ try
176168 {
177- db . CreateTable < ModelWithPostDropSql > ( ) ;
178- try
179- {
180- db . DropTable < ModelWithPostDropSql > ( ) ;
181- Assert . Fail ( "Should throw" ) ;
182- }
183- catch ( Exception )
184- {
185- Assert . That ( ! db . TableExists ( "ModelWithPostDropSql" ) ) ;
186- }
169+ db . DropTable < ModelWithPostDropSql > ( ) ;
170+ Assert . Fail ( "Should throw" ) ;
171+ }
172+ catch ( Exception )
173+ {
174+ Assert . That ( ! db . TableExists ( "ModelWithPostDropSql" ) ) ;
187175 }
188176 }
189177
@@ -200,69 +188,62 @@ public class CustomSelectTest
200188 [ Test ]
201189 public void Can_select_custom_field_expressions ( )
202190 {
203- using ( var db = OpenDbConnection ( ) )
204- {
205- db . DropAndCreateTable < CustomSelectTest > ( ) ;
191+ using var db = OpenDbConnection ( ) ;
192+ db . DropAndCreateTable < CustomSelectTest > ( ) ;
206193
207- db . Insert ( new CustomSelectTest { Id = 1 , Width = 10 , Height = 5 } ) ;
194+ db . Insert ( new CustomSelectTest { Id = 1 , Width = 10 , Height = 5 } ) ;
208195
209- var row = db . SingleById < CustomSelectTest > ( 1 ) ;
196+ var row = db . SingleById < CustomSelectTest > ( 1 ) ;
210197
211- Assert . That ( row . Area , Is . EqualTo ( 10 * 5 ) ) ;
212- }
198+ Assert . That ( row . Area , Is . EqualTo ( 10 * 5 ) ) ;
213199 }
214200
215201 [ Test ]
216202 public void Can_Count_Distinct ( )
217203 {
218- using ( var db = OpenDbConnection ( ) )
219- {
220- db . DropAndCreateTable < LetterFrequency > ( ) ;
204+ using var db = OpenDbConnection ( ) ;
205+ db . DropAndCreateTable < LetterFrequency > ( ) ;
221206
222- var rows = "A,B,B,C,C,C,D,D,E" . Split ( ',' ) . Map ( x => new LetterFrequency { Letter = x } ) ;
207+ var rows = "A,B,B,C,C,C,D,D,E" . Split ( ',' ) . Map ( x => new LetterFrequency { Letter = x } ) ;
223208
224- db . InsertAll ( rows ) ;
209+ db . InsertAll ( rows ) ;
225210
226- var count = db . Count ( db . From < LetterFrequency > ( ) . Select ( x => x . Letter ) ) ;
227- Assert . That ( count , Is . EqualTo ( rows . Count ) ) ;
211+ var count = db . Count ( db . From < LetterFrequency > ( ) . Select ( x => x . Letter ) ) ;
212+ Assert . That ( count , Is . EqualTo ( rows . Count ) ) ;
228213
229- count = db . Scalar < long > ( db . From < LetterFrequency > ( ) . Select ( x => Sql . Count ( x . Letter ) ) ) ;
230- Assert . That ( count , Is . EqualTo ( rows . Count ) ) ;
214+ count = db . Scalar < long > ( db . From < LetterFrequency > ( ) . Select ( x => Sql . Count ( x . Letter ) ) ) ;
215+ Assert . That ( count , Is . EqualTo ( rows . Count ) ) ;
231216
232- var distinctCount = db . Scalar < long > ( db . From < LetterFrequency > ( ) . Select ( x => Sql . CountDistinct ( x . Letter ) ) ) ;
233- Assert . That ( distinctCount , Is . EqualTo ( rows . Map ( x => x . Letter ) . Distinct ( ) . Count ( ) ) ) ;
217+ var distinctCount = db . Scalar < long > ( db . From < LetterFrequency > ( ) . Select ( x => Sql . CountDistinct ( x . Letter ) ) ) ;
218+ Assert . That ( distinctCount , Is . EqualTo ( rows . Map ( x => x . Letter ) . Distinct ( ) . Count ( ) ) ) ;
234219
235- distinctCount = db . Scalar < long > ( db . From < LetterFrequency > ( ) . Select ( "COUNT(DISTINCT Letter)" ) ) ;
236- Assert . That ( distinctCount , Is . EqualTo ( rows . Map ( x => x . Letter ) . Distinct ( ) . Count ( ) ) ) ;
237- }
220+ distinctCount = db . Scalar < long > ( db . From < LetterFrequency > ( ) . Select ( "COUNT(DISTINCT Letter)" ) ) ;
221+ Assert . That ( distinctCount , Is . EqualTo ( rows . Map ( x => x . Letter ) . Distinct ( ) . Count ( ) ) ) ;
238222 }
239223
240224 [ Test ]
241225 public void Does_select_aliases_on_constant_expressions ( )
242226 {
243- using ( var db = OpenDbConnection ( ) )
244- {
245- db . DropAndCreateTable < LetterFrequency > ( ) ;
246- db . Insert ( new LetterFrequency { Letter = "A" } ) ;
247-
248- var q = db . From < LetterFrequency > ( )
249- . Select ( x => new
250- {
251- param = 1 ,
252- descr = x . Letter ,
253- str = "hi" ,
254- date = DateTime . UtcNow
255- } ) ;
256-
257- var results = db . Select < Dictionary < string , object > > ( q ) [ 0 ] ;
227+ using var db = OpenDbConnection ( ) ;
228+ db . DropAndCreateTable < LetterFrequency > ( ) ;
229+ db . Insert ( new LetterFrequency { Letter = "A" } ) ;
230+
231+ var q = db . From < LetterFrequency > ( )
232+ . Select ( x => new
233+ {
234+ param = 1 ,
235+ descr = x . Letter ,
236+ str = "hi" ,
237+ date = DateTime . UtcNow
238+ } ) ;
239+
240+ var results = db . Select < Dictionary < string , object > > ( q ) [ 0 ] ;
258241
259- Assert . That ( results [ "param" ] , Is . EqualTo ( 1 ) ) ;
260- Assert . That ( results [ "descr" ] , Is . EqualTo ( "A" ) ) ;
261- Assert . That ( results [ "str" ] , Is . EqualTo ( "hi" ) ) ;
262- Assert . That ( results [ "date" ] , Is . Not . Empty ) ;
263- }
242+ Assert . That ( results [ "param" ] , Is . EqualTo ( 1 ) ) ;
243+ Assert . That ( results [ "descr" ] , Is . EqualTo ( "A" ) ) ;
244+ Assert . That ( results [ "str" ] , Is . EqualTo ( "hi" ) ) ;
245+ Assert . That ( results [ "date" ] , Is . Not . Empty ) ;
264246 }
265247
266-
267248 }
268249}
0 commit comments