While writing some tests for the following method I had a strange problem. When the test ran it threw a NullReferenceExceptions for my stubbed User object.
The method under test is simple enough
as is the test case
The mocking Framework is Rhino Mocks and this was the solution to the problem.
With Rhino a call to a stub (or mock) is expected only once while my method is checking the user object a number of times. Eventually the test will just check that the cookie has been set so I can change the User stub to: