开发者

Help me avoid this NullReferenceException (using Rhino Mocks)

开发者 https://www.devze.com 2023-01-08 03:26 出处:网络
I\'m currently trying to get one of my unit tests to work, but there is one thing in the way. I have a class called AccountingScheduleLookup that has an ID field attached to it that\'s read-only. When

I'm currently trying to get one of my unit tests to work, but there is one thing in the way. I have a class called AccountingScheduleLookup that has an ID field attached to it that's read-only. When I try to mock a call to a method that uses this ID field it throws me a lovely NullReferenceException on that particular line of code. This means that either the ID was not assigned to it, or the object was not instantiated.

When I did put in a basic instantiation, though, it still threw me the exception. Any ideas for how to get开发者_开发知识库 around this?

Here's a code sample (for what it's worth)

AccountingScheduleLookup = new AccountingSchedule { Description = "Will this work?" }
var calendarPeriods = dal.GetObjects<AccountingScheduleDetail>(
     Where.Property("AccountingScheduleID").Is(AccountingScheduleLookup.AccountingScheduleID));


Typical usage of rhino mocks would involve setting up an expectation that when that property is accessed it return a certain value.

Here is a quick reference for the latest version of rhino mocks:

http://www.ayende.com/wiki/GetFile.aspx?File=Rhino+Mocks+3.3+Quick+Reference.pdf

Here is the section that will likely pertain to you:

Property Getters

Expect.Call(foo.Name).Return("Bob");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号