Avanade / UnitTestEx

UnitTestEx provides .NET testing extensions to the most popular testing frameworks (MSTest, NUnit and Xunit) specifically to improve the testing experience with ASP.NET controller, and Azure Function, execution including underlying HttpClientFactory mocking.
MIT License
18 stars 4 forks source link

HTTP Functions that use Microsoft.Azure.Functions.Worker.Http #67

Closed m-flak closed 2 months ago

m-flak commented 3 months ago

I have an HTTP-triggered Azure function with the following signature, using the Microsoft.Azure.Functions.Worker.Http.* classes for the request and response data.

[Function(...)]
public async Task<HttpResponseData> Run([HttpTrigger(...)] HttpRequestData req, FunctionContext context)
{
/*...*/
}

I was unable to get UnitTestEx to work with this setup and had to do my unit testing with Moq and mock classes for those request/response classes.

My functions project uses the isolated worker model, and I followed the example setup the best I could. In the end, I was unable to use this library because it could not handle HttpRequestData/HttpResponseData.

I am still new to using Azure Functions, so if I can switch these over to what UnitTestEx supports, I'm unaware. 😃

chullybun commented 3 months ago

Hi,

This is a challenge with the isolated worker model where Microsoft introduced new types, versus the more widely used HttpRequest and HttpResponse. Thankfully, Microsoft has now (recently) added support for these types; see this article for guidance on usage.

Generally, my guidance is to use HttpRequest and HttpResponse as there are many other libraries, etc. out there that support, and means development is largely consistent with an ASP.NET Core implementation.

Cheers...

m-flak commented 2 months ago

Thankfully, Microsoft has now (recently) added support for these types; see this article for guidance on usage.

Thanks!! I skimmed that article but wasn't sure if it was worth it to migrate. I will now because this library really takes the pain out of testing Azure code.