gpt4 book ai didi

c# - 如何构造HttpPostedFileBase?

转载 作者:太空狗 更新时间:2023-10-29 22:34:51 26 4
gpt4 key购买 nike

我必须为此方法编写一个单元测试,但我无法构建 HttpPostedFileBase... 当我从浏览器运行该方法时,它运行良好,但我确实需要为此进行自动单元测试。所以我的问题是:如何构造 HttpPosterFileBase 以便将文件传递给 HttpPostedFileBase。

谢谢。

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

最佳答案

做这样的事情怎么样:

public class MockHttpPostedFileBase : HttpPostedFileBase
{
public MockHttpPostedFileBase()
{

}
}

然后你可以创建一个新的:

MockHttpPostedFileBase mockFile = new MockHttpPostedFileBase();

关于c# - 如何构造HttpPostedFileBase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3428276/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com