我想用集成测试来测试一个函数,它将文件附加到RavenDB数据库中的文档。为此,我需要一个
IFormFile
.
显然,我不能从接口实例化,所以我尝试实例化
FormFile
继承自
形锉
接口。
using (var stream = File.OpenRead("placeholder.pdf"))
{
var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
{
ContentType = "application.pdf"
};
}
但这会引发以下错误:
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.AspNetCore.Http.Internal.FormFile.set_ContentType(String value)
当我移除
ContentType = "application.pdf"
从代码中它允许我实例化一个新的实例,但是没有
ContentType
.
如何实例化的实例
表单文件
与
内容类型
如果没有
Moq
框架?