您将如何测试此场景?
我刚刚开始调查NHibernate,并在TDD举行了我的第一次聚会。到目前为止,我非常喜欢它,并且一直在使用fluent-Nhibernate对类进行映射。
基本上我有两个类,RecipientList和RecipientList。RecipientList类具有到具有流畅的“HasMany”关系的收件人的映射:
public class RecipientListMap : ClassMap<RecipientList>
{
public RecipientListMap()
{
Id(x => x.ID);
Map(x => x.ApplicationID);
Map(x => x.Name);
Map(x => x.IsDeleted);
HasMany<Recipient>(x => x.Recipients).WithKeyColumn("RecipientListID").AsList().LazyLoad();
}
}
但是,当我在测试中使用以下代码时:
private IList<Recipient> _recipients = new List<Recipient>()
{
new Recipient { FirstName = "Joe", LastName = "Bloggs", Email = "joe@bloggs.com", IsDeleted = false },
new Recipient { FirstName = "John", LastName = "Doe", Email = "john@doe.com", IsDeleted = false },
new Recipient { FirstName = "Jane", LastName = "Smith", Email = "john@smith.com", IsDeleted = false }
};
[Test]
public void Can_Add_RecipientList_To_Database()
{
new PersistenceSpecification<RecipientList>(Session)
.CheckProperty(x => x.Name, "My List")
.CheckProperty(x => x.Columns, "My columns")
.CheckProperty(x => x.IsDeleted, false)
.CheckProperty(x => x.ApplicationID, Guid.NewGuid())
.CheckProperty(x => x.Recipients, _recipients)
.VerifyTheMappings();
}
出现以下错误:
failed: System.ApplicationException : Expected 'System.Collections.Generic.List`1[Project.Data.Domains.Recipients.Recipient]' but got 'NHibernate.Collection.Generic.PersistentGenericBag`1[Project.Data.Domains.Recipients.Recipient]' for Property 'Recipients'
我可以看到错误是因为我传入了一个列表,而返回的列表是一个PersistentGenericBag,因此抛出了一个错误。我不明白如果你不能通过IList考试,你打算怎么测试这个?
任何帮助都将不胜感激。