WebHostBuilder () does not start. C # Integration Test

0

I am trying to create a series of tests against an Asp.net core service. The service starts perfect as well as the tests running against it. The problem is when I try to start the tests using webHostBuilder. At the time of making the request I get the error:

  

System.AggregateException: One or more errors occurred. (String   reference not set to an instance of a String.       Parameter name: s)

From the startUp class of the service

StartUp - >

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using TrackerBackend.Core.Middleware;

namespace serviceName
{
    public class Startup
    {
    public Startup(IConfiguration configuration, IHostingEnvironment env)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddApplicationInsightsTelemetry();
        services.AddMvc();
        Ioc.AddRegistration(services, Configuration);
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
          if (env.IsDevelopment())
          {
              app.UseDeveloperExceptionPage();
          }

          app.UseAuthentication();
          app.UseMvc();
      }
   }
}

That's how I'm creating the client - >

public Client()
{
    _server = new TestServer(new WebHostBuilder().UseStartup<Startup>());
    _client = _server.CreateClient();
    _client.BaseAddress = new Uri("http://localhost:58255");
}

I hope you can help me. Thanks

    
asked by Ale Prado 09.04.2018 в 13:34
source

1 answer

0

Resuleto

The webhostBuilder does not default to the "appsettings.json"

_server = new TestServer(new WebHostBuilder()
            .UseEnvironment("Development")
            .UseContentRoot("path/rootProject")
            .UseConfiguration(new ConfigurationBuilder().AddJsonFile("path/appsettings.json").Build())
            .UseStartup<Startup>());
    
answered by 09.04.2018 в 15:12