加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 如何测试流畅的NHibernate的PersistenceSpecification.Ver

发布时间:2020-12-15 06:53:18 所属栏目:百科 来源:网络整理
导读:你将如何测试这种情况? 我刚刚开始研究NHibernate,并在TDD上进行了第一个bash.到目前为止,我非常喜欢它,并且一直在使用流畅的Nhibernate来映射类. 但是,当使用“验证规则”中的VerifyTheMappings方法时,我似乎正在陷入僵局. 本质上我有两个类,即收件人和收
你将如何测试这种情况?

我刚刚开始研究NHibernate,并在TDD上进行了第一个bash.到目前为止,我非常喜欢它,并且一直在使用流畅的Nhibernate来映射类.

但是,当使用“验证规则”中的VerifyTheMappings方法时,我似乎正在陷入僵局.

本质上我有两个类,即收件人和收件人列表. 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",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'

我可以看到错误是因为我传递一个List,而返回的列表是一个PersistentGenericBag,因此会抛出一个错误.我不知道如果你不能通过一个IList,你会怎么想呢测试一下?

任何帮助将不胜感激.

解决方法

嗯我愚蠢地使用了错误的方法来进行PeristenceSpecification.

我应该使用CheckList不是CheckProperty.

咄!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读