77using FreeSql . Extensions . DynamicEntity ;
88using Newtonsoft . Json ;
99using Xunit ;
10+ using Xunit . Abstractions ;
1011
1112namespace FreeSql . Tests . DynamicEntity
1213{
1314 public class DynamicEntityTest
1415 {
15- private static IFreeSql fsql = new FreeSqlBuilder ( ) . UseConnectionString ( DataType . Sqlite ,
16- "data source=:memory:" )
17- . UseMonitorCommand ( d => Console . WriteLine ( d . CommandText ) ) . Build ( ) ;
16+ private readonly ITestOutputHelper _output ;
17+
18+ private static IFreeSql _fsql ;
19+
20+ public DynamicEntityTest ( ITestOutputHelper output )
21+ {
22+ _output = output ;
23+ _fsql = new FreeSqlBuilder ( ) . UseConnectionString ( DataType . Sqlite ,
24+ "data source=:memory:" )
25+ . UseMonitorCommand ( d => _output . WriteLine ( d . CommandText ) ) . Build ( ) ;
26+ }
1827
1928 [ Fact ]
2029 public void NormalTest ( )
2130 {
22- var table = fsql . CodeFirst . DynamicEntity ( "NormalUsers" )
31+ var table = _fsql . CodeFirst . DynamicEntity ( "NormalUsers" )
2332 . Property ( "Id" , typeof ( string ) )
2433 . Property ( "Name" , typeof ( string ) )
2534 . Property ( "Address" , typeof ( string ) )
@@ -32,15 +41,15 @@ public void NormalTest()
3241 } ;
3342 var instance = table . CreateInstance ( dict ) ;
3443 //根据Type生成表
35- fsql . CodeFirst . SyncStructure ( table . Type ) ;
36- fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
37- var objects = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
44+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
45+ _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
46+ var objects = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
3847 }
3948
4049 [ Fact ]
4150 public void AttributeTest ( )
4251 {
43- var table = fsql . CodeFirst . DynamicEntity ( "AttributeUsers" ,
52+ var table = _fsql . CodeFirst . DynamicEntity ( "AttributeUsers" ,
4453 new TableAttribute ( ) { Name = "T_Attribute_User" } ,
4554 new IndexAttribute ( "Name_Index1" , "Name" , false ) )
4655 . Property ( "Id" , typeof ( int ) ,
@@ -57,15 +66,15 @@ public void AttributeTest()
5766 } ;
5867 var instance = table . CreateInstance ( dict ) ;
5968 //根据Type生成表
60- fsql . CodeFirst . SyncStructure ( table . Type ) ;
61- var insertId = fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteIdentity ( ) ;
62- var select = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
69+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
70+ var insertId = _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteIdentity ( ) ;
71+ var select = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
6372 }
6473
6574 [ Fact ]
6675 public void SuperClassTest ( )
6776 {
68- var table = fsql . CodeFirst . DynamicEntity ( "Roles" , new TableAttribute ( ) { Name = "T_Role" } ,
77+ var table = _fsql . CodeFirst . DynamicEntity ( "Roles" , new TableAttribute ( ) { Name = "T_Role" } ,
6978 new IndexAttribute ( "Name_Index2" , "Name" , false ) )
7079 . Extend ( typeof ( BaseModel ) )
7180 . Property ( "Id" , typeof ( int ) ,
@@ -81,23 +90,23 @@ public void SuperClassTest()
8190 } ;
8291 var instance = table . CreateInstance ( dict ) ;
8392 //根据Type生成表
84- fsql . CodeFirst . SyncStructure ( table . Type ) ;
85- fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
86- var objects = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
93+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
94+ _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
95+ var objects = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
8796 }
8897
8998 [ Fact ]
9099 public void SuperClassVirtualOverrideTest ( )
91100 {
92- var table = fsql . CodeFirst . DynamicEntity ( "Role_VirtualOverride" ,
101+ var table = _fsql . CodeFirst . DynamicEntity ( "Role_VirtualOverride" ,
93102 new TableAttribute ( ) { Name = "T_Role_VirtualOverride" } ,
94103 new IndexAttribute ( "Name_Index2" , "Name" , false ) )
95104 . Extend ( typeof ( BaseModelOverride ) )
96105 . Property ( "Id" , typeof ( int ) ,
97106 new ColumnAttribute ( ) { IsPrimary = true , IsIdentity = true , Position = 1 } )
98107 . Property ( "Name" , typeof ( string ) ,
99108 new ColumnAttribute ( ) { StringLength = 20 , Position = 2 } )
100- . Property ( "Operators" , typeof ( string ) , true ) //重写 virtual 属性
109+ . Property ( "Operators" , typeof ( string ) , true , new ColumnAttribute ( ) { StringLength = 20 } ) //重写 virtual 属性
101110 . Build ( ) ;
102111 var dict = new Dictionary < string , object >
103112 {
@@ -108,15 +117,15 @@ public void SuperClassVirtualOverrideTest()
108117 } ;
109118 var instance = table . CreateInstance ( dict ) ;
110119 //根据Type生成表
111- fsql . CodeFirst . SyncStructure ( table . Type ) ;
112- fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
113- var objects = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
120+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
121+ _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
122+ var objects = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
114123 }
115124
116125 [ Fact ]
117126 public void SuperClassBaseModelAbstractTest ( )
118127 {
119- var table = fsql . CodeFirst . DynamicEntity ( "Role_AbstractOverride" ,
128+ var table = _fsql . CodeFirst . DynamicEntity ( "Role_AbstractOverride" ,
120129 new TableAttribute ( ) { Name = "T_Role_AbstractOverride" } ,
121130 new IndexAttribute ( "Name_Index2" , "Name" , false ) )
122131 . Extend ( typeof ( BaseModelAbstract ) )
@@ -135,15 +144,15 @@ public void SuperClassBaseModelAbstractTest()
135144 } ;
136145 var instance = table . CreateInstance ( dict ) ;
137146 //根据Type生成表
138- fsql . CodeFirst . SyncStructure ( table . Type ) ;
139- fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
140- var objects = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
147+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
148+ _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
149+ var objects = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
141150 }
142151
143152 [ Fact ]
144153 public void SuperClassBaseModelAbstractAndVirtualTest ( )
145154 {
146- var table = fsql . CodeFirst . DynamicEntity ( "Role_AbstractAndVirtualOverride" ,
155+ var table = _fsql . CodeFirst . DynamicEntity ( "Role_AbstractAndVirtualOverride" ,
147156 new TableAttribute ( ) { Name = "Role_AbstractAndVirtualOverride" } ,
148157 new IndexAttribute ( "Name_Index2" , "Name" , false ) )
149158 . Extend ( typeof ( BaseModelAbstractAndVirtual ) )
@@ -164,15 +173,15 @@ public void SuperClassBaseModelAbstractAndVirtualTest()
164173 } ;
165174 var instance = table . CreateInstance ( dict ) ;
166175 //根据Type生成表
167- fsql . CodeFirst . SyncStructure ( table . Type ) ;
168- fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
169- var objects = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
176+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
177+ _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
178+ var objects = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
170179 }
171180
172181 [ Fact ]
173182 public void DefaultValueTest ( )
174183 {
175- var table = fsql . CodeFirst . DynamicEntity ( "NormalUsers" )
184+ var table = _fsql . CodeFirst . DynamicEntity ( "NormalUsers" )
176185 . Property ( "Id" , typeof ( string ) )
177186 . Property ( "Age" , typeof ( int ) , false , 12 )
178187 . Property ( "Longs" , typeof ( long ) , false , 16666 )
@@ -190,9 +199,9 @@ public void DefaultValueTest()
190199 } ;
191200 var instance = table . CreateInstance ( dict ) ;
192201 //根据Type生成表
193- fsql . CodeFirst . SyncStructure ( table . Type ) ;
194- fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
195- var objects = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
202+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
203+ _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
204+ var objects = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
196205 }
197206
198207 [ Fact ]
@@ -215,7 +224,7 @@ public void Issue1591Test()
215224 , false ) ;
216225 attributes . Add ( indexAttribute ) ;
217226
218- var table = fsql . CodeFirst . DynamicEntity ( "AttributeUsers" , attributes . ToArray ( ) )
227+ var table = _fsql . CodeFirst . DynamicEntity ( "AttributeUsers" , attributes . ToArray ( ) )
219228 . Property ( "Id" , typeof ( int ) ,
220229 new ColumnAttribute ( ) { IsPrimary = true , IsIdentity = true , Position = 1 } )
221230 . Property ( "Name" , typeof ( string ) ,
@@ -232,9 +241,9 @@ public void Issue1591Test()
232241 } ;
233242 var instance = table . CreateInstance ( dict ) ;
234243 //根据Type生成表
235- fsql . CodeFirst . SyncStructure ( table . Type ) ;
236- var insertId = fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteIdentity ( ) ;
237- var select = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
244+ _fsql . CodeFirst . SyncStructure ( table . Type ) ;
245+ var insertId = _fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteIdentity ( ) ;
246+ var select = _fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
238247 }
239248 }
240249
0 commit comments