Fluent Nhibernate 映射的单元测试
我正在尝试了解社区的其他成员如何测试他们的 Fluent Nhibernate 映射。假设我有以下映射:
public UserHeaderMap()
{
Table("USER_HEADER");
Id(x => x.Id, "USER_ID");
Map(x => x.LoginName, "LOGIN_NAME");
Map(x => x.UserPassword, "USER_PASSWORD");
Map(x => x.UserEmail, "USER_EMAIL");
Map(x => x.UserLanguage, "USER_LANGUAGE");
Map(x => x.UserEnabled, "USER_ENABLED");
HasManyToMany(x => x.Groups)
.Table("USER_GROUP_COMPOSITE")
.ParentKeyColumn("USER_ID")
.ChildKeyColumn("GROUP_ID")
.Cascade.All()
.Inverse();
}
public class GroupHeaderMap : ClassMap<GroupHeader>
{
public GroupHeaderMap()
{
Table("GROUP_HEADER");
Id(x => x.Id, "GROUP_ID");
Map(x => x.Name, "GROUP_NAME");
Map(x => x.Description, "GROUP_DESCRIPTION");
HasManyToMany(x => x.Users)
.Table("USER_GROUP_COMPOSITE")
.ParentKeyColumn("GROUP_ID")
.ChildKeyColumn("USER_ID");
}
}
您会为这些编写哪些单元测试?您会使用 PersistenceSpecification 类来对这些进行单元测试吗?
编辑:
我想使用 SqlLite,但是如果我不从映射生成架构怎么办?我仍然可以将架构加载到 SqlLite 中吗?我还想知道测试 SqlLite 是否真的足够。我们的产品至少需要在 MS SQL 和 Oracle 上运行。仅在 SqlLite 数据库上进行测试是否可以满足我的要求?另外,您通常是否测试已映射的每个实体(构造函数、属性等)?
I'm trying to get a feel for how the rest of the community tests their Fluent Nhibernate mappings. So let's say I have the following mappings:
public UserHeaderMap()
{
Table("USER_HEADER");
Id(x => x.Id, "USER_ID");
Map(x => x.LoginName, "LOGIN_NAME");
Map(x => x.UserPassword, "USER_PASSWORD");
Map(x => x.UserEmail, "USER_EMAIL");
Map(x => x.UserLanguage, "USER_LANGUAGE");
Map(x => x.UserEnabled, "USER_ENABLED");
HasManyToMany(x => x.Groups)
.Table("USER_GROUP_COMPOSITE")
.ParentKeyColumn("USER_ID")
.ChildKeyColumn("GROUP_ID")
.Cascade.All()
.Inverse();
}
public class GroupHeaderMap : ClassMap<GroupHeader>
{
public GroupHeaderMap()
{
Table("GROUP_HEADER");
Id(x => x.Id, "GROUP_ID");
Map(x => x.Name, "GROUP_NAME");
Map(x => x.Description, "GROUP_DESCRIPTION");
HasManyToMany(x => x.Users)
.Table("USER_GROUP_COMPOSITE")
.ParentKeyColumn("GROUP_ID")
.ChildKeyColumn("USER_ID");
}
}
What all unit tests would you write for these? Would you use PersistenceSpecification class to unit test these?
Edit:
I want to use SqlLite but what if I'm not generating my schema from my mappings? Can I still load my schema into SqlLite somehow? Also I'm wondering if testing SqlLite is really enough. Our product needs to run on at least MS SQL and Oracle. Will testing only on a SqlLite database meet my requirements? Also do you usually test each and every entity that you have mapped (Constructors, Properties, etc)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Fluent nhibernate 有内置测试方法。使用它们,您可以执行以下操作
此测试将
这将检查属性映射。
另外,我建议使用 SqlLite 并在内存中测试真实的 SQL 查询来验证级联规则。
Fluent nhibernate has build-in testing methods. With them you can do the following
This test will
This will check property mappings.
Also I would suggest to use SqlLite and test real SQL queries in memory to verify cascading rules.