我通过HTTP Post上传文件,并从Request.Files属性中获取文件。好的 - 现在我想测试我的服务。
我的服务代码:
public void Post(MyFileRequest request)
{
var files = base.Request.Files;
foreach (var file in files)
{
url = this.uploader.UploadFile(Session, file);
}
}
对于模拟请求我正在使用MockRequestContext,如下所示:
private MyService CreateMyService(Session session)
{
var myService = new MyService(this.uploaderMock.Object)
{
RequestContext = GetRequestContextMock(session)
};
return myService;
}
private IRequestContext GetRequestContextMock(Session session)
{
var mockedRequestContext = new MockRequestContext();
mockedRequestContext.Get<IHttpRequest>().Items.Add(ServiceExtensions.RequestItemsSessionKey, session);
return mockedRequestContext;
}
是否有可能在IHttpRequest中模拟Files属性?