Reputation: 638
I'm having issues trying to write a functional test for a ASP.NET Core gRPC web service, after investigating a number of articles on the issue, but with all of them referring to use of the Startup class that fell out of fashion with the introduction of .NET 6 and beyond.
Even the Microsoft article from 2024 relates back to sample code from the AspNetCore.Docs repository that still relies on the service implementing the Startup paradigm, which is incompatible with usage of WebApplication.CreateBuilder
method.
I have been following Milan Jovanović's video on writing functional tests in ASP.NET Core which is very informative and was hoping to follow the idea of using the WebApplicationFactory<Program>
class as the basis of the testing, but this is based on HTTP web services, and not sure how to shift this for use with a gRPC service.
If anyone has any advice on this, it would be very helpful, since I can't seem to find an example or explanation that will function in the .NET 8 world.
Upvotes: 1
Views: 30
Reputation: 21546
You are right, the official document does not provide the .NET 8 sample code.
About the "incompatible with usage of WebApplication.CreateBuilder method", you could leverage the Configuration and Services properties on the WebApplicationBuilder to modify configuration and DI directly, without the need for a startup class. Refer to the following tutorials:
Code samples migrated to the new minimal hosting model in ASP.NET Core 6.0
Migrate from ASP.NET Core 5.0 to 6.0
Besides, ASP.NET Core is an open-source project, you can also open a documentation issue and suggest the Docs team or the Article author to provide the .NET 8 version sample code.
Upvotes: 1