views:

137

answers:

1

I'm using Rhino Mock 3.5 for .Net Framework 2.0 and when I run this code I get a run time error.

This is the code

IFile fileInterface = MockRepository.GenerateStub<IFile>();<br>
IUrlMapper urlMapper = MockRepository.GenerateStub<IUrlMapper>();

// this is the line causing the run-time error<br>
HttpContextBase mockHttpContext = MockRepository.GenerateMock<HttpContextBase>();

HttpRequestBase mockRequest = MockRepository.GenerateMock<HttpRequestBase>();

RhinoMocksExtensions.Stub<HttpContextBase,HttpRequestBase>(mockHttpContext, delegate(HttpContextBase ctx)
{
                                                               return ctx.Request;
                                                           }
).Return(mockRequest);


RhinoMocksExtensions.Stub(fileInterface, delegate(IFile f)
                 {
                     f.Exists(Arg<string>.Is.Anything);
                 }
).Return(true);


AspxReplacementResolver resolverToTest = new AspxReplacementResolver(mockHttpContext, fileInterface, urlMapper);

This is the Error:

TestCase 'TestMockingRhinoMock35.TestTestFixtures.Test1'
failed: System.TypeLoadException : Could not load type 'System.Web.RequestNotification' from assembly 'System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'......

System.Web.RequestNotification is part of Framework 3.0 but I'm using Framework 2.0 and I referenced the specific Rhino Mocks 3.5 for Framework 2.0 dll.

Thank you

+4  A: 

HttpContextBase doesn't exist in .Net framework 2.0. It was added in a .dll called System.Web.Abstractions, and is only available if you've installed the .Net Framework 3.5, as well as Service Pack 1 for .Net Framework 3.5.

You'll have to target .net 3.5 if you want to mock this out. If you're using a seperate assembly for testing, there's no reason you couldn't target your test assembly to 3.5 and leave your production application alone.

womp
Thank you for your response. Actually you can add a reference to System.Web.Abstractions and use it within .Net 2.0; I've been using it successfully.Now that I'm writing these tests I am getting this error, so I guess I'll have to target .net 3.5 for testing since I have a separate assembly.Thanks again
Rafael N