使用配置文件进行集成测试

时间:2021-02-07 01:48:46

标签: asp.net-core

我有一个使用 nUnit 的集成测试,并有一个类似的设置

[SetUp]
public void Setup()
{
    var webHostBuilder = new WebHostBuilder().UseStartup<Startup>();
    TestServer = new TestServer(webHostBuilder);
}

'Startup' 是我希望测试的 Web 应用程序的 Startup 类。像其他 ASP.NET 应用程序一样,这个启动看起来像:

        /// 
        /// Startup constructor with DI, auto generated
        /// 
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }


        public IConfiguration Configuration { get; }


        ///
        /// This method gets called by the runtime. Use this method to add services to the container.
        /// auto generated
        /// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        //// 
        public void ConfigureServices(IServiceCollection services)
        {
// I would like Configuration to access the same configuration values that are read into the web
// application but somehow Configuration points elsewhere.
        }

我希望配置访问读入网络的相同配置值 应用程序,但不知何故 配置指向别处。谁能给我一个提示,让我知道我该怎么做 有配置指向在正常期间读入的相同配置(appSettings.json) 网络应用程序的执行? 谢谢

0 个答案:

没有答案