Open nickraphael opened 1 year ago
I believe this works
var files = new List<IFormFile>();
mockHttpContext.RequestMock.FormMock.FilesMock.Mock.Setup(c => c.GetEnumerator()).Returns(files.GetEnumerator());
You could also mock the indexer if you needed to.
For me I setup the ReadFormAsync()
that was used in my controller to get the Forms and then the Files.
var file = new FormFile(new MemoryStream(Encoding.UTF8.GetBytes("This is a dummy file")), 0, 20, "Data", "dummy.txt");
httpContextMock.RequestMock.Mock.Setup(s => s.ReadFormAsync(It.IsAny<CancellationToken>())).ReturnsAsync(new FormCollection(new Dictionary<string, StringValues>(), new FormFileCollection { file }));
Currently there doesn't seem to be a way to mock a context that holds a file.