0

I am a Java programmer learning C# on the job and I have inherited a command line application in .NET which sets up Kestrel to provide endpoints to a frontend.

       public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        private static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

I would like to be able to programmatically verify in our build pipeline that the application exposes an exact list of endpoints. For now the relative path of the URL's will be enough.

What would be the best way to approach this? Look into the HostBuilder created, or by asking the runtime when fully started?

Thorbjørn Ravn Andersen
  • 73,784
  • 33
  • 194
  • 347
  • are you talking like integration tests? Like starting a test server and hitting each endpoint to see if it exists? Or just enumerating over anything marked as `[ApiController]`. Then you could pull the `[Route]` from each method of said object – Andy May 22 '21 at 19:01
  • @Andy No. Endpoints are different and will require individual integration tests. I want to be absolutely certain that a given build exposes exactly those endpoint URL's we expect it to by comparing a manually maintained list to the one I ask about how I can retrieve. – Thorbjørn Ravn Andersen May 22 '21 at 19:03
  • How about [this](https://stackoverflow.com/questions/41908957/get-all-registered-routes-in-asp-net-core)? – Andy May 22 '21 at 19:05
  • 1
    @andy It might - I'll have a look. Thanks so far. – Thorbjørn Ravn Andersen May 22 '21 at 19:08

0 Answers0