简体   繁体   English

为测试创建NHibernate Not Found对象

[英]Create NHibernate Not Found Object for Tests

When you try to load an object with a bad ID, NHibernate returns a proxy that will throw ObjectNotFoundExceptions when you try to access any of its properties. 当您尝试加载具有错误ID的对象时,NHibernate会返回一个代理,当您尝试访问其任何属性时,该代理将抛出ObjectNotFoundExceptions I would like to test that my application handles those bad objects correctly. 我想测试我的应用程序正确处理这些坏对象。 Currently, my tests work by mocking up the repositories to return the values that I want them to return. 目前,我的测试通过模拟存储库来返回我希望它们返回的值。 How do I create a not found object proxy that I can return from my mocked up repository? 如何创建一个未找到的对象代理,我可以从我的模拟存储库返回?

mh, MH,

I would simply mock an instance of your entity and set it up to throw ObjectNotFoundExceptions whenever you access a property. 我只是模拟一个实体的实例,并将其设置为在访问属性时抛出ObjectNotFoundExceptions

And the mocked repository then simply returns that object for any query or get/load etc... 然后,模拟的存储库只是为任何查询返回该对象或获取/加载等...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM