Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rhino Mock vs debug mode?

my problem is following:

I have ms unit test which uses stubbed http context for mvc routing tests. But one part of code (which uses rhino mock) is problematic:

var httpContextMock = MockRepository.GenerateStub<HttpContextBase>();
httpContextMock.Stub(c => c.Request.AppRelativeCurrentExecutionFilePath)
   .Return(url);

In debug mode, second line throws an exception:

enter image description here

Why such an error occurs ? While tests are fired without debugger, everything works fine.

Regards

like image 715
jwaliszko Avatar asked Nov 13 '22 17:11

jwaliszko


1 Answers

This is really weird. What's strange to me is that your code works in non-debug mode. The Request property is not stubbed, so you can't really know what it would return. You may try the following:

var httpContextMock = MockRepository.GenerateStub<HttpContextBase>();
var httpRequestMock = MockRepository.GenerateStub<HttpContextBase>();
httpContextMock.Stub(c => c.Request).Return(httpRequestMock); 
httpRequestMock.Stub(c => c.AppRelativeCurrentExecutionFilePath).Return(url);
like image 157
Amittai Shapira Avatar answered Dec 17 '22 07:12

Amittai Shapira