public async Task EdmundsApiAccess() { var options = CreateOptions("EdmundsApiAccess"); // Note: configuration requires that the appsettings.json file and // UserSecretsId (in project.json) are included in the UnitTest project var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json") .AddUserSecrets() .AddEnvironmentVariables() .Build(); var edmundsSettings = new EdmundsSettings() { EdmundsApiKey = configuration["EdmundsApiKey"] }; var optionsMock = new Mock <IOptions <EdmundsSettings> >(); optionsMock.Setup(m => m.Value).Returns(edmundsSettings); using (var context = new ApplicationDbContext(options)) { var carsController = new CarsController( new CarsService( context, new EdmundsService(optionsMock.Object))); Assert.That( (await carsController.ListMakes()).Count() > 0, "No makes retrieved from Edmunds."); } }
public EdmundsService(IOptions <EdmundsSettings> settings) { this.settings = settings.Value; client.BaseAddress = new Uri("https://api.edmunds.com/api/vehicle/v2/"); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }