How to mock an IFormFile for a unit/integration test in ASP.NET Core 1 MVC 6?

后端 未结 3 804
有刺的猬
有刺的猬 2020-12-16 11:05

I want to write tests for uploading of files in ASP.NET Core 1 but can\'t seem to find a nice way to mock/instanciate an object derived from IFormFile. Any suggestions on ho

3条回答
  •  攒了一身酷
    2020-12-16 11:27

    Easier would be to create an actual in-memory instance

     IFormFile file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 0, "Data", "dummy.txt");
    

提交回复
热议问题