[英]WebRootPath and TestServer
我有一個具有以下結構的XUnit測試項目:
我的集成測試中的_environment.WebRootPath
始終為null,並且在測試項目中有一些依賴該值的代碼。 我知道我可以在TestStartup中手動設置該值。 我想知道是否有比硬編碼路徑( C:\\...\\MyApp.Rest\\wwwroot
)更好的方法來設置值?
public TestStartup(IHostingEnvironment environment, IServiceProvider serviceProvider) {
_environment = environment;
_environment.WebRootPath = "ugly_hardcoded_path_to_wwwroot"
var builder = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile($"appsettings.{_environment.EnvironmentName}.json")
.AddEnvironmentVariables();
Configuration = builder.Build();
}
我在集成測試中遇到了相同的問題。 我在Microsoft.AspNetCore.TestHost
使用TestServer
類
這是我配置WebrootPath的方法:
_server = new TestServer(new WebHostBuilder()
.UseWebRoot(@"The path i want to use")
.UseStartup<Startup>());
_client = _server.CreateClient();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.