Skip to content

[BUG][aspnetcore] Doesn't work well with WebApplicationFactory #7093

@Sshnyari

Description

@Sshnyari

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • What's the version of OpenAPI Generator used?
  • Have you search for related issues/PRs?
  • What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Starting from asp.net core 3.0, when making integration tests with WebApplicationFactory, it searches for either

  • a method called CreateWebHostBuilder with a return an IWebHostBuilder
  • or one called CreateHostBuilder returning an IHostBuilder.

It crashes if it doesn't find any of those two.

In the mustache template for Program.cs, we have a mix of both (IHostBuilder CreateWebHostBuilder).

I suggest changing it to IHostBuilder CreateHostBuilder().

openapi-generator version

v4.3.1

OpenAPI declaration file content or url

the petstore.yaml file would do

Command line used for generation

the default one

Steps to reproduce
  1. generate the code
  2. add a integration tests project that uses WebApplicationFactory
  3. start the test
    it crashes with the message : System.InvalidOperationException : No method 'public static IHostBuilder CreateHostBuilder(string[] args)' or 'public static IWebHostBuilder CreateWebHostBuilder(string[] args)' found on 'API.Program'. Alternatively, WebApplicationFactory`1 can be extended and 'CreateHostBuilder' or 'CreateWebHostBuilder' can be overridden to provide your own instance.
Related issues/PRs

none

Suggest a fix

I suggest changing it to IHostBuilder CreateHostBuilder().

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions