Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
5 of 6 tasks
Sshnyari opened this issue Jul 31, 2020 · 1 comment
Closed
5 of 6 tasks

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

Sshnyari opened this issue Jul 31, 2020 · 1 comment

Comments

@Sshnyari
Copy link
Contributor

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().

@auto-labeler
Copy link

auto-labeler bot commented Jul 31, 2020

👍 Thanks for opening this issue!
🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants