Skip to content

Commit 4e36d6c

Browse files
committed
- 增加DynamicEntity - SuperClass单元测试
1 parent 6b86fc4 commit 4e36d6c

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

FreeSql.Tests/FreeSql.Tests/DynamicEntity/DynamicEntityTest.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ public void NormalTest()
2121
{
2222
Type type = DynamicCompileHelper.DynamicBuilder()
2323
.Class("NormalUsers")
24-
.Property("Id", typeof(int))
24+
.Property("Id", typeof(string))
2525
.Property("Name", typeof(string))
2626
.Property("Address", typeof(string))
2727
.Build();
2828
var dict = new Dictionary<string, object>
2929
{
3030
["Name"] = "张三",
31-
["Id"] = 1,
31+
["Id"] = Guid.NewGuid().ToString(),
3232
["Address"] = "北京市"
3333
};
3434
var instance = DynamicCompileHelper.CreateObjectByType(type, dict);
@@ -58,7 +58,46 @@ public void AttributeTest()
5858
var instance = DynamicCompileHelper.CreateObjectByType(type, dict);
5959
//根据Type生成表
6060
fsql.CodeFirst.SyncStructure(type);
61+
var insertId = fsql.Insert<object>().AsType(type).AppendData(instance).ExecuteIdentity();
62+
var select = fsql.Select<object>().AsType(type).ToList();
63+
}
64+
65+
[Fact]
66+
public void SuperClassTest()
67+
{
68+
Type type = DynamicCompileHelper.DynamicBuilder()
69+
.Class("Roles", new TableAttribute() { Name = "T_Role" },
70+
new IndexAttribute("Name_Index", "Name", false))
71+
.SuperClass(typeof(BaseModel))
72+
.Property("Id", typeof(int),
73+
new ColumnAttribute() { IsPrimary = true, IsIdentity = true, Position = 1 })
74+
.Property("Name", typeof(string),
75+
new ColumnAttribute() { StringLength = 20, Position = 2 })
76+
.Build();
77+
var dict = new Dictionary<string, object>
78+
{
79+
["Name"] = "系统管理员",
80+
["UpdateTime"] = DateTime.Now,
81+
["UpdatePerson"] = "admin"
82+
};
83+
var instance = DynamicCompileHelper.CreateObjectByType(type, dict);
84+
//根据Type生成表
85+
fsql.CodeFirst.SyncStructure(type);
6186
fsql.Insert<object>().AsType(type).AppendData(instance).ExecuteAffrows();
6287
}
6388
}
89+
public class BaseModel
90+
{
91+
[Column(Position = 99)]
92+
public DateTime UpdateTime
93+
{
94+
get; set;
95+
}
96+
97+
[Column(Position = 100, StringLength = 20)]
98+
public string UpdatePerson
99+
{
100+
get; set;
101+
}
102+
}
64103
}

0 commit comments

Comments
 (0)