Tôi có giao diện điều khiển & cho phép người dùng tải tệp lên máy chủ. Điều này được thực hiện trong chế độ xem bằng cách sử dụng input type='file'
và trong bộ điều khiển bằng cách nhận giá trị Request.Files
(HttpRequestBase
, trả lại HttpFileCollectionWrapper
).Rhino Mocks: Mocking HttpRequestBase.Files
Tôi đang gặp khó khăn khi chế nhạo nội dung này bằng cách sử dụng Rhino Mocks.
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);
Các nhà xây dựng cho HttpFileCollectionWrapper
đòi hỏi một HttpFileCollection
, tuy nhiên điều này có một constructor internal
.
Có ai có thể đề xuất cách nhận cách tiếp cận này hoặc biến thể của nó để hoạt động không?