Is there a way to create a test server for minimal APIs without WebApplicationFactory<TEntryPoint>? #51782
Unanswered
paulomorgado
asked this question in
Q&A
Replies: 2 comments 3 replies
-
You need to do something like this to expose the Program.csvar messages = new List<MyMessage>();
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
app.MapGet("/", (MyMessage m) => messages.Add(m));
app.Run();
public partial class Program
{
// Expose the Program class for use with WebApplicationFactory<T>
} Your Testsvar factory = new WebApplicationFactory<Program>(); |
Beta Was this translation helpful? Give feedback.
3 replies
-
Just checked. If it's a unit tests project, that doesn't work. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'd like to have something like this on my tests:
Now I would like to have a
TestServer
instance for that and use:But this seems to be possible only using
WebApplicationFactory<TEntryPoint>
. And that requires an entrypoint.Beta Was this translation helpful? Give feedback.
All reactions