我正在使用Rhino Mock 3.5 for .Net Framework 2.0,当我运行此代码时出现运行时错误。
这是代码
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);
这是错误:
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是Framework 3.0的一部分,但我使用的是Framework 2.0,我引用了特定的Rhino Mocks 3.5 for Framework 2.0 dll。
谢谢
答案 0 :(得分:4)
HttpContextBase
。它被添加到名为System.Web.Abstractions
的.dll中,仅当您为.Net Framework 3.5安装.Net Framework 3.5,以及 Service Pack 1时才可用。
如果你想嘲笑它,你必须以.net 3.5为目标。如果您使用单独的组件进行测试,则没有理由不能将测试组件定位到3.5并将生产应用程序单独留下。