I am trying to do the following in an XUnit project to get the connectionstring to the database my tests should be using:
public class TestFixture : IDisposable
{
public IConfigurationRoot Configuration { get; set; }
public MyFixture()
{
var builder = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
Configuration = builder.Build();
}
public void Dispose()
{
}
}
It is very strange because it works perfectly in the WebAPI and MVC templates when used in Startup.cs. Additionally, this code was previously working in RC1 with dnx, but now that I updated everything to RC2 and Core CLI it no longer is able to find the appsettings.json
file which is in the root of the xunit class library.
Here is what my test class looks like so you can see how I am calling for the configuration:
public class MyTests : IClassFixture<MyFixture>
{
private readonly MyFixture _fixture;
public MyTests(MyFixture fixture)
{
this._fixture = fixture;
}
[Fact]
public void TestCase1()
{
ICarRepository carRepository = new CarRepository(_fixture.Configuration);
}
}