2009-07-17 69 views
0

我正在使用Rhino Mock 3.5 for .Net Framework 2.0,当我运行此代码时出现运行时错误。RhinoMock 3.5在运行时运行时错误.net

这是代码

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是框架3.0的一部分,但我使用Framework 2.0和我引用了特定的Rhino Mocks 3.5 for Framework 2.0 dll。

谢谢

回答

4

HttpContextBase不Net框架2.0存在。它被添加到名为System.Web.Abstractions的.dll中,并且只有在.Net Framework 3.5,以及 Service Pack 1 for .Net Framework 3.5的情况下才可用。

如果你想嘲笑这一点,你将不得不以.net 3.5为目标。如果您正在使用独立程序集进行测试,那么没有理由不能将您的测试程序集定位到3.5并让您的生产应用程序单独运行。

+1

感谢您的回复。实际上,你可以添加一个对System.Web.Abstractions的引用,并在.Net 2.0中使用它;我一直在成功地使用它。 现在,我正在写这些测试,我得到这个错误,所以我想我将不得不针对.net 3.5进行测试,因为我有一个单独的程序集。 再次感谢 – 2009-07-20 16:38:00