帮助我避免这种nullreferenceException(使用rhino mocks)
-
16-09-2020 - |
题
我目前正在试图让我的一个单位测试工作,但是在路上有一件事。我有一个名为consureChouncheduleLookup的类,它具有附加的ID字段,它是只读的。当我尝试拨打呼叫使用此ID字段的方法时,它会在该特定的代码上抛出一个可爱的NULLREFILEDECTEP。这意味着id未分配给它,或者未实例化对象。
当我确实放入了基本的实例化时,它仍然会让我扔掉一个例外。任何如何绕过这个想法?
这是一个代码样本(对于它的价值)
AccountingScheduleLookup = new AccountingSchedule { Description = "Will this work?" }
var calendarPeriods = dal.GetObjects<AccountingScheduleDetail>(
Where.Property("AccountingScheduleID").Is(AccountingScheduleLookup.AccountingScheduleID));
. 解决方案
rhino模型的典型用法涉及建立期望,当访问该属性时,它会返回某个值。
以下是最新版本的rhino模型的快速参考:
http:// www.ayende.com / wiki / getfile.aspx?file= rhino + mocks + 3.3 +快速+参考.pdf
以下是可能与您有关的部分:
属性getter
Expect.Call(foo.Name).Return("Bob");
. 不隶属于 StackOverflow