@@ -11,15 +11,14 @@ namespace FreeSql.Tests.DynamicEntity
1111{
1212 public class DynamicEntityTest
1313 {
14- private static IFreeSql fsql = new FreeSqlBuilder ( ) . UseConnectionString ( DataType . PostgreSQL ,
15- "Host=192.168.0.36;Port=5432;Username=postgres;Password=123; Database=test;ArrayNullabilityMode=Always;Pooling=true;Minimum Pool Size=1 " )
14+ private static IFreeSql fsql = new FreeSqlBuilder ( ) . UseConnectionString ( DataType . Sqlite ,
15+ "data source=:memory: " )
1616 . UseMonitorCommand ( d => Console . WriteLine ( d . CommandText ) ) . Build ( ) ;
1717
1818 [ Fact ]
1919 public void NormalTest ( )
2020 {
21- Type type = DynamicCompileHelper . DynamicBuilder ( )
22- . Class ( "NormalUsers" )
21+ var table = fsql . CodeFirst . DynamicEntity ( "NormalUsers" )
2322 . Property ( "Id" , typeof ( string ) )
2423 . Property ( "Name" , typeof ( string ) )
2524 . Property ( "Address" , typeof ( string ) )
@@ -30,18 +29,17 @@ public void NormalTest()
3029 [ "Id" ] = Guid . NewGuid ( ) . ToString ( ) ,
3130 [ "Address" ] = "北京市"
3231 } ;
33- var instance = DynamicCompileHelper . CreateObjectByType ( type , dict ) ;
32+ var instance = table . CreateInstance ( dict ) ;
3433 //根据Type生成表
35- fsql . CodeFirst . SyncStructure ( type ) ;
36- fsql . Insert < object > ( ) . AsType ( type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
34+ fsql . CodeFirst . SyncStructure ( table . Type ) ;
35+ fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
3736 }
3837
3938 [ Fact ]
4039 public void AttributeTest ( )
4140 {
42- Type type = DynamicCompileHelper . DynamicBuilder ( )
43- . Class ( "AttributeUsers" , new TableAttribute ( ) { Name = "T_Attribute_User" } ,
44- new IndexAttribute ( "Name_Index" , "Name" , false ) )
41+ var table = fsql . CodeFirst . DynamicEntity ( "AttributeUsers" , new TableAttribute ( ) { Name = "T_Attribute_User" } ,
42+ new IndexAttribute ( "Name_Index1" , "Name" , false ) )
4543 . Property ( "Id" , typeof ( int ) ,
4644 new ColumnAttribute ( ) { IsPrimary = true , IsIdentity = true , Position = 1 } )
4745 . Property ( "Name" , typeof ( string ) ,
@@ -54,19 +52,18 @@ public void AttributeTest()
5452 [ "Name" ] = "张三" ,
5553 [ "Address" ] = "北京市"
5654 } ;
57- var instance = DynamicCompileHelper . CreateObjectByType ( type , dict ) ;
55+ var instance = table . CreateInstance ( dict ) ;
5856 //根据Type生成表
59- fsql . CodeFirst . SyncStructure ( type ) ;
60- var insertId = fsql . Insert < object > ( ) . AsType ( type ) . AppendData ( instance ) . ExecuteIdentity ( ) ;
61- var select = fsql . Select < object > ( ) . AsType ( type ) . ToList ( ) ;
57+ fsql . CodeFirst . SyncStructure ( table . Type ) ;
58+ var insertId = fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteIdentity ( ) ;
59+ var select = fsql . Select < object > ( ) . AsType ( table . Type ) . ToList ( ) ;
6260 }
6361
6462 [ Fact ]
6563 public void SuperClassTest ( )
6664 {
67- Type type = DynamicCompileHelper . DynamicBuilder ( )
68- . Class ( "Roles" , new TableAttribute ( ) { Name = "T_Role" } ,
69- new IndexAttribute ( "Name_Index" , "Name" , false ) )
65+ var table = fsql . CodeFirst . DynamicEntity ( "Roles" , new TableAttribute ( ) { Name = "T_Role" } ,
66+ new IndexAttribute ( "Name_Index2" , "Name" , false ) )
7067 . Extend ( typeof ( BaseModel ) )
7168 . Property ( "Id" , typeof ( int ) ,
7269 new ColumnAttribute ( ) { IsPrimary = true , IsIdentity = true , Position = 1 } )
@@ -79,10 +76,10 @@ public void SuperClassTest()
7976 [ "UpdateTime" ] = DateTime . Now ,
8077 [ "UpdatePerson" ] = "admin"
8178 } ;
82- var instance = DynamicCompileHelper . CreateObjectByType ( type , dict ) ;
79+ var instance = table . CreateInstance ( dict ) ;
8380 //根据Type生成表
84- fsql . CodeFirst . SyncStructure ( type ) ;
85- fsql . Insert < object > ( ) . AsType ( type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
81+ fsql . CodeFirst . SyncStructure ( table . Type ) ;
82+ fsql . Insert < object > ( ) . AsType ( table . Type ) . AppendData ( instance ) . ExecuteAffrows ( ) ;
8683 }
8784 }
8885 public class BaseModel
0 commit comments