I have a .NET Core class library for blob storage, which I use in ASP.NET Core web applications, and I want to test the controller it exposes. For reasons beyond my control, I need to test the controller without using a HTTP client, testing server, or web application, which is why I am trying to mock a request. I need to mock a multipart/form-data HTTP request for a file upload in order to test the POST method of the controller.
I tried to figure out how to mock the request from this article: How to mock the Request on Controller in ASP.Net MVC? but to no avail.
[HttpPost]
[DisableFormValueModelBinding]
public async Task<AttachedFile> Post()
{
return await Request.WriteToFileStorage(service);
}
Every time I try to mock the Request object in some way, I get an exception in the test explorer with "Message: System.Exception : Expected a multipart request, but got" (for some reason the text is cut off after "but got").
Aucun commentaire:
Enregistrer un commentaire