如何构建HttpPostedFileBase? [英] How to construct HttpPostedFileBase?

查看:273
本文介绍了如何构建HttpPostedFileBase?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须写这个方法的单元测试,但我不能构建HttpPostedFileBase ......当我从浏览器中运行的方法,效果很好,但我真的需要,一个autoamted单元测试。所以我的问题是:我怎么构建HttpPosterFileBase为了传递一个文件HttpPostedFileBase。

感谢。

 公众的ActionResult UploadFile(IEnumerable的< HttpPostedFileBase>文件)
    {
        的foreach(在文件var文件)
        {
           // ...
        }
    }


解决方案

如何做这样的事情:

 公共类MockHttpPostedFileBase:HttpPostedFileBase
{
    公共MockHttpPostedFileBase()
    {    }
}

,那么你可以创建一个新的:

  MockHttpPostedFileBase mockFile =新MockHttpPostedFileBase();

I have to write a Unit test for this method but I am unable to construct HttpPostedFileBase... When I run the method from the browser, it works well but I really need an autoamted unit test for that. So my question is: how do I construct HttpPosterFileBase in order to pass a file to HttpPostedFileBase.

Thanks.

    public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> files)
    {
        foreach (var file in files)
        {
           // ...
        }
    }

解决方案

How about doing something like this:

public class MockHttpPostedFileBase : HttpPostedFileBase
{
    public MockHttpPostedFileBase()
    {

    }
}

then you can create a new one:

MockHttpPostedFileBase mockFile = new MockHttpPostedFileBase();

这篇关于如何构建HttpPostedFileBase?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆