2009-07-17 22 views
0

.NET Framework 2.0用にRhino Mock 3.5を使用しています。このコードを実行すると、ランタイムエラーが発生します。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を使用していますし、私はフレームワーク2.0 dllのための特定のRhino Mock 3.5を参照しました。

答えて

4

HttpContextBaseは、.NET Framework 2.0に存在しません、ありがとうございました。 という名前の.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をターゲットにしなければならないと思います。 もう一度おねがいします –

関連する問題