c# - Finding my ConnectionString in .NET Core integration tests -


i'm building automated integration tests .net core project. somehow need access connection string integration tests database. new .net core no longer has configurationmanager, instead configurations injected, there no way (at least not know of) inject connection string test class.

is there way in .net core can @ configuration file without injecting test class? or, alternatively, there way test class can have dependencies injected them?

.net core 2.0

create new configuration , specify correct path appsettings.json.

this part of testbase.cs inherit in tests.

public abstract class testbase {     protected readonly datetime utcnow;     protected readonly objectmother objectmother;     protected readonly httpclient restclient;      protected testbase()     {         iconfigurationroot configuration = new configurationbuilder()             .setbasepath(appcontext.basedirectory)             .addjsonfile("appsettings.json")             .build();          var connectionstringsappsettings = new connectionstringsappsettings();         configuration.getsection("connectionstrings").bind(connectionstringsappsettings);          //you can access appsettings connectionstringsappsettings.mykey          utcnow = datetime.utcnow;         objectmother = new objectmother(utcnow, connectionstringsappsettings);         webhostbuilder webhostbuilder = new webhostbuilder();         webhostbuilder.configureservices(s => s.addsingleton<istartupconfigurationservice, teststartupconfigurationservice>());         webhostbuilder.usestartup<startup>();         testserver testserver = new testserver(webhostbuilder);         restclient = testserver.createclient();     } } 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo