我创建了一个asp.net点网核心rtm(1.0.0-preview2-003121).
它使用ConfigurationBuilder从appsettings.json生成配置:
public Startup(IHostingEnvironment env) { var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json",optional: false,reloadOnChange: true); Configuration = builder.Build(); }
我也试过’.SetBasePath(Directory.GetCurrentDirectory())`
现在我的单元测试(在另一个项目中)我正在构建一个内存主机:
我试过了:
_server = new TestServer(new WebHostBuilder().UseStartup<Startup>()); _client = _server.CreateClient();
我试过了:
_server = new TestServer( new WebHostBuilder() .UseContentRoot(Directory.GetCurrentDirectory()) .UseStartup<Startup>()); _client = _server.CreateClient();
我的Travis.yml文件很标准:
install: # Install .net using linux CLI commands - sudo sh -c 'echo "deb [arch=amd64] https://apt-mo.trafficmanager.net/repos/dotnet/ trusty main" > /etc/apt/sources.list.d/dotnetdev.list' - sudo apt-key adv --keyserver apt-mo.trafficmanager.net --recv-keys 417A0893 - sudo apt-get update - sudo apt-get -qq install dotnet-dev-1.0.0-preview2-003121 - sudo apt-get install dotnet-hostfxr-1.0.2 script: - dotnet restore - dotnet build src/Speakr.WebApp.Site - dotnet build tests/Speakr.WebApp.Site.Tests - dotnet test tests/Speakr.WebApp.Site.Tests -f netcoreapp1.0
在本地,所有工作和建设.在Windows和Ubuntu上.
在travis CI tho,我收到以下错误:
错误:Speakr.WebApp.Site.Tests.InMemoryTests.HomeControllerIndexShouldNotBeNull
有没有人见过这个?
我已经尝试将project.json添加到测试项目中,在主项目中包含CopyToOutput并在测试项目中包含CopytoOutput.
纳达! 原文链接:https://www.f2er.com/aspnet/245539.html