C#C
C#3y ago
bdcp

❔ Writing tests for Minimal API that calls KeyVault and Azure

How can i write tests for a web app using minimal Apis.

    internal class UserWebApplication : WebApplicationFactory<Program>
    {
        protected override IHost CreateHost(IHostBuilder builder)
        {
              // How can i just override keyvault here?
             builder.ConfigureHostConfiguration(config =>
            {
                config.AddInMemoryCollection(new Dictionary<string, string>
                {
                    ["KeyVault:Uri"] = "??",
                });
            });


            return base.CreateHost(builder);
        }
    }


The Docs say i have to use WebApplicationFactory<Program> but i can't create it bescause it tries to call KeyVault and Azure client'd also need to be set etc.
Is it possible to just add a mock keyvault into it?
image.png
Was this page helpful?