diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs index 5a693fb..f014cc9 100644 --- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs +++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Controllers/TestFeedbackReceiver.cs @@ -1,30 +1,32 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Text; using System.Text.Json; -using System.Threading; using System.Threading.Tasks; using AutoFixture; using AutoFixture.Xunit2; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Options; using MongoDB.Driver; using Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures; using Retroactiune.Models; +using Retroactiune.Settings; using Xunit; namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers { - public class TestFeedbackReceiver : IClassFixture, IClassFixture + public class TestFeedbackReceiver : IClassFixture { private readonly MongoDbFixture _mongoDb; private readonly HttpClient _client; - public TestFeedbackReceiver(WebApiTestingFactory factory, MongoDbFixture mongoDbFixture) + public TestFeedbackReceiver(WebApiTestingFactory factory) { _client = factory.CreateClient(); - _mongoDb = mongoDbFixture; + var dbSettings = factory.Services.GetService>(); + _mongoDb = new MongoDbFixture(dbSettings); } diff --git a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs index 0579884..d5a9ee5 100644 --- a/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs +++ b/Retroactiune.IntegrationTests/Retroactiune.WebAPI/Fixtures/MongoDbFixture.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Options; using MongoDB.Driver; using Retroactiune.Models; using Retroactiune.Settings; @@ -16,21 +16,9 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures public IMongoCollection FeedbackReceiverCollection => Database.GetCollection(_settings.FeedbackReceiverCollectionName); - public MongoDbFixture() + public MongoDbFixture(IOptions options) { - var config = new ConfigurationBuilder() - .AddJsonFile("appsettings.json") - .AddJsonFile("appsettings.Testing.json").Build(); - - var section = config.GetSection(nameof(RetroactiuneDbSettings)); - - _settings = new RetroactiuneDbSettings(); - _settings.ConnectionString = section.GetValue("ConnectionString"); - _settings.TokensCollectionName = section.GetValue("TokensCollectionName"); - _settings.FeedbackCollectionName = section.GetValue("FeedbackCollectionName"); - _settings.FeedbackReceiverCollectionName = section.GetValue("FeedbackReceiverCollectionName"); - _settings.DatabaseName = section.GetValue("DatabaseName"); - + _settings = options.Value; var client = new MongoClient(_settings.ConnectionString); Database = client.GetDatabase(_settings.DatabaseName); } diff --git a/Retroactiune.WebAPI/Program.cs b/Retroactiune.WebAPI/Program.cs index 106ceab..d378f68 100644 --- a/Retroactiune.WebAPI/Program.cs +++ b/Retroactiune.WebAPI/Program.cs @@ -1,7 +1,5 @@ using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Logging.Console; namespace Retroactiune {