Redesign for MongoDbFixture.cs
This commit is contained in:
parent
fd6da9c589
commit
7daa314ad1
3 changed files with 11 additions and 23 deletions
|
@ -1,30 +1,32 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.Json;
|
using System.Text.Json;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using AutoFixture;
|
using AutoFixture;
|
||||||
using AutoFixture.Xunit2;
|
using AutoFixture.Xunit2;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Microsoft.Extensions.Options;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures;
|
using Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures;
|
||||||
using Retroactiune.Models;
|
using Retroactiune.Models;
|
||||||
|
using Retroactiune.Settings;
|
||||||
using Xunit;
|
using Xunit;
|
||||||
|
|
||||||
namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
|
namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Controllers
|
||||||
{
|
{
|
||||||
public class TestFeedbackReceiver : IClassFixture<WebApiTestingFactory>, IClassFixture<MongoDbFixture>
|
public class TestFeedbackReceiver : IClassFixture<WebApiTestingFactory>
|
||||||
{
|
{
|
||||||
private readonly MongoDbFixture _mongoDb;
|
private readonly MongoDbFixture _mongoDb;
|
||||||
private readonly HttpClient _client;
|
private readonly HttpClient _client;
|
||||||
|
|
||||||
public TestFeedbackReceiver(WebApiTestingFactory factory, MongoDbFixture mongoDbFixture)
|
public TestFeedbackReceiver(WebApiTestingFactory factory)
|
||||||
{
|
{
|
||||||
_client = factory.CreateClient();
|
_client = factory.CreateClient();
|
||||||
_mongoDb = mongoDbFixture;
|
var dbSettings = factory.Services.GetService<IOptions<RetroactiuneDbSettings>>();
|
||||||
|
_mongoDb = new MongoDbFixture(dbSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Options;
|
||||||
using MongoDB.Driver;
|
using MongoDB.Driver;
|
||||||
using Retroactiune.Models;
|
using Retroactiune.Models;
|
||||||
using Retroactiune.Settings;
|
using Retroactiune.Settings;
|
||||||
|
@ -16,21 +16,9 @@ namespace Retroactiune.IntegrationTests.Retroactiune.WebAPI.Fixtures
|
||||||
public IMongoCollection<FeedbackReceiver> FeedbackReceiverCollection =>
|
public IMongoCollection<FeedbackReceiver> FeedbackReceiverCollection =>
|
||||||
Database.GetCollection<FeedbackReceiver>(_settings.FeedbackReceiverCollectionName);
|
Database.GetCollection<FeedbackReceiver>(_settings.FeedbackReceiverCollectionName);
|
||||||
|
|
||||||
public MongoDbFixture()
|
public MongoDbFixture(IOptions<RetroactiuneDbSettings> options)
|
||||||
{
|
{
|
||||||
var config = new ConfigurationBuilder()
|
_settings = options.Value;
|
||||||
.AddJsonFile("appsettings.json")
|
|
||||||
.AddJsonFile("appsettings.Testing.json").Build();
|
|
||||||
|
|
||||||
var section = config.GetSection(nameof(RetroactiuneDbSettings));
|
|
||||||
|
|
||||||
_settings = new RetroactiuneDbSettings();
|
|
||||||
_settings.ConnectionString = section.GetValue<string>("ConnectionString");
|
|
||||||
_settings.TokensCollectionName = section.GetValue<string>("TokensCollectionName");
|
|
||||||
_settings.FeedbackCollectionName = section.GetValue<string>("FeedbackCollectionName");
|
|
||||||
_settings.FeedbackReceiverCollectionName = section.GetValue<string>("FeedbackReceiverCollectionName");
|
|
||||||
_settings.DatabaseName = section.GetValue<string>("DatabaseName");
|
|
||||||
|
|
||||||
var client = new MongoClient(_settings.ConnectionString);
|
var client = new MongoClient(_settings.ConnectionString);
|
||||||
Database = client.GetDatabase(_settings.DatabaseName);
|
Database = client.GetDatabase(_settings.DatabaseName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Microsoft.Extensions.Logging.Console;
|
|
||||||
|
|
||||||
namespace Retroactiune
|
namespace Retroactiune
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue