0

I have this setup in my unit test

HttpApplication application = MockRepository.GenerateStub<HttpApplication>();
application.Stub(a => a.CompleteRequest());

And when I run the tests it throws a NullReferenceException on the second line. This is confusing to me because up above it is mocked.

  • 1
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – gunr2171 Oct 15 '20 at 21:38
  • I'm unsure why my stubbing it would cause it to be null rather than what NRE is per say. – reagan yuan Oct 15 '20 at 21:43
  • What _specifically_ is the null reference? – gunr2171 Oct 15 '20 at 21:44
  • The "a.CompleteRequest()" specifically causes the null reference – reagan yuan Oct 15 '20 at 21:45
  • So that means that either `a` is null, or something _inside_ the `CompleteRequest()` method causes an NRE. Can you put down a breakpoint and walk through it? – gunr2171 Oct 15 '20 at 21:46
  • CompleteRequest() calls _stepManager.CompleteRequest(), which I assume is null because HttpApplication needs some background steps to initialize it. Debugging doesn't allow me to debug inside the a.CompleteRequest(). But, I thought application.Stub(a ->..) would not actually call the method. – reagan yuan Oct 15 '20 at 21:48

0 Answers0