views:

65

answers:

1

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));
A: 

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");
CountBobula
The latest version of Rhino Mocks is actually 3.6. 3.3 came out around October 2007, while 3.6 came out around September 2009.
Mark Rushakoff