© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
3 replies
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);
        }
    }
    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>
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
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ Azure KeyVault duplicated API calls
C#CC# / help
3y ago
❔ Writting tests for api calls
C#CC# / help
3y ago
❔ Unauthorized while reading secrets from Azure Keyvault
C#CC# / help
3y ago
✅ Overriding IConfigurationManager.GetSection for integration tests in .NET 8 Minimal API
C#CC# / help
14mo ago