How to instantiate an instance of FormFile in C# without Moq?

后端 未结 1 660
盖世英雄少女心
盖世英雄少女心 2020-12-31 03:40

I want to test a function that attaches files to documents in a RavenDB database with an integration test. For this, I need an instance of IFormFile.

Ob

相关标签:
1条回答
  • 2020-12-31 04:08

    Thanks to Hans his comment, the actual answer is:

    using (var stream = File.OpenRead("placeholder.pdf"))
    {
        var file = new FormFile(stream, 0, stream.Length, null, Path.GetFileName(stream.Name))
        {
            Headers = new HeaderDictionary(),
            ContentType = "application/pdf"
        };
    }
    
    0 讨论(0)
提交回复
热议问题