dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.48k stars 10.03k forks source link

gRPC integration test `TStartup` = `Program.cs` throws `"A public method named 'ConfigureIntegrationTests' or 'Configure' could not be found in the 'Program' type."` #44906

Open khteh opened 2 years ago

khteh commented 2 years ago

Is there an existing issue for this?

Describe the bug

I follow this: https://learn.microsoft.com/en-us/aspnet/core/grpc/test-services?view=aspnetcore-6.0 and bump into:

"A public method named 'ConfigureIntegrationTests' or 'Configure' could not be found in the 'Program' type."
at Microsoft.AspNetCore.Hosting.StartupLoader.FindMethod(Type startupType, String methodName, String environmentName, Type returnType, Boolean required)
   at Microsoft.AspNetCore.Hosting.StartupLoader.FindConfigureDelegate(Type startupType, String environmentName)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services, Object instance)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__0(HostBuilderContext context, IServiceCollection services)
   at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
   at Microsoft.Extensions.Hosting.HostBuilder.Build()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostBuilderExtensions.<StartAsync>d__1.MoveNext()
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostBuilderExtensions.Start(IHostBuilder hostBuilder)
   at Web.Api.IntegrationTests.Services.GrpcTestFixture`1.EnsureServer() in C:\\Projects\\ASP.Net\\AspNetCoreWebApi\\test\\Web.Api.IntegrationTests\\Services\\GrpcTestFixture.cs:line 115

The server is configured to listen at https://localhost:5000. This happens when I use the default TestServer.CreateHandler().


Does .Net Core 6 GRPC support HTTP/3? I configure HttpHandler with the following class:

public class Http3Handler : DelegatingHandler
{
    public Http3Handler() { }
    public Http3Handler(HttpMessageHandler innerHandler) : base(innerHandler) { }
    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
    {
        request.Version = HttpVersion.Version30;
        request.VersionPolicy = HttpVersionPolicy.RequestVersionExact;
       return await base.SendAsync(request, cancellationToken); // throws exception here
    }
}

and assign it:

    HttpHandler = new Http3Handler(Fixture.Handler)

and bump into the same error and exception shown above.

Expected Behavior

No response

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

6.0.402

Anything else?

Windows 11, Visual Studio 2022 17.3.6

rafikiassumani-msft commented 1 year ago

@khteh the sample code only supports Startup.cs and not Program.cs. We may add support for Program.cs in the future.

ghost commented 1 year ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

khteh commented 1 year ago

Isn't the sample code built for .Net 6 and the date of the article is "06/04/2022"?

khteh commented 1 year ago

Hello!!! Wasn't startup.cs removed in .Net 6 with minimal hosting model? How long should we wait to do integration tests on gRPC services!?!

JamesNK commented 1 year ago

It isn't removed. Both options are supported. If you need it then you should choose it over WebApplicationBuilder.

davidfowl commented 1 year ago

Do we have a doc on how to test with the minimal hosting model?

kwaclaw commented 1 year ago

I am also interested to see how I can test when I don't have a startup class in the gRPC server, but a Program.cs with only top level statements. It seems it is possible for MVC using the WebApplicationFactory.

I tested this for my gRPC test project and found it worked for me:

khteh commented 1 year ago

Any update on this?

jakoss commented 8 months ago

Do we have a doc on how to test with the minimal hosting model?

I don't believe so, it would be very useful