2010-02-22 35 views
5

Kullanıcının bir dosyayı sunucuya yüklemesine izin veren bir görünüm & denetleyicim var. Bu, bir input type='file' kullanarak denetleyicide ve Request.Files (, HttpFileCollectionWrapper döndürerek) değerini alarak denetleyicide yapılır.Rhino Mocks: Mocking HttpRequestBase.Files

Bunu Rhino Mocks kullanarak alay etmekte zorlanıyorum.

HttpContextBase mockHttpContext = MockRepository.GenerateMock<HttpContextBase>(); 
HttpRequestBase mockRequest = MockRepository.GenerateMock<HttpRequestBase>(); 
mockHttpContext.Stub(x => x.Request).Return(mockRequest); 

mockRequest.Stub(x => x.HttpMethod).Return("GET"); 

// Next line fails - throws MissingMethodException 
// (Can't find a constructor with matching arguments) 
HttpFileCollectionWrapper files = 
    MockRepository.GenerateMock<HttpFileCollectionWrapper>(); 

files.Stub(x => x.Count).Return(1); 

mockRequest.Stub(x => x.Files).Return(files); 

HttpFileCollectionWrapper için kurucu, ancak bu bir internal kurucu sahip bir HttpFileCollection gerektirir.

Bu yaklaşımın nasıl çalıştığını veya bir varyantının çalışmasını önerebilecek biri var mı?

cevap

6

Mock HttpFileCollectionBase yerine HttpFileCollectionWrapper:

var filesMock = MockRepository.GenerateMock<HttpFileCollectionBase>(); 
filesMock.Stub(x => x.Count).Return(1); 
mockRequest.Stub(x => x.Files).Return(filesMock); 
İlgili konular