refactor(TestBase): add ConfigureServices-callback method to be able to add custom services to testes
This commit is contained in:
parent
cb0c361cdb
commit
7fbf0ebbfc
@ -2,11 +2,7 @@
|
||||
using DigitalData.Core.Abstraction.Application.Repository;
|
||||
using EnvelopeGenerator.Application.Common.Dto.EnvelopeReceiver;
|
||||
using EnvelopeGenerator.Application.Common.Notifications.DocSigned;
|
||||
using EnvelopeGenerator.Application.Common.Notifications.DocSigned.Handlers;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.Dynamic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EnvelopeGenerator.Tests.Application;
|
||||
|
||||
@ -14,9 +10,13 @@ public class DocSignedNotificationTests : TestBase
|
||||
{
|
||||
protected IMapper _mapper;
|
||||
|
||||
public override Task Setup()
|
||||
protected override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
return base.Setup();
|
||||
}
|
||||
|
||||
public override async Task Setup()
|
||||
{
|
||||
await base.Setup();
|
||||
_mapper = Host.Services.GetRequiredService<IMapper>();
|
||||
}
|
||||
|
||||
|
||||
@ -24,7 +24,7 @@ public class Fake
|
||||
{
|
||||
public static readonly Faker Provider = new("de");
|
||||
|
||||
public static Host CreateHost() => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
|
||||
public static Host CreateHost(Action<IServiceCollection>? configureServices = null) => Microsoft.Extensions.Hosting.Host.CreateDefaultBuilder()
|
||||
.ConfigureAppConfiguration((context, config) =>
|
||||
{
|
||||
// add appsettings.json
|
||||
@ -33,6 +33,9 @@ public class Fake
|
||||
})
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
// add custom services
|
||||
configureServices?.Invoke(services);
|
||||
|
||||
IConfiguration configuration = context.Configuration;
|
||||
|
||||
// add Application and Infrastructure services
|
||||
|
||||
@ -4,12 +4,17 @@ using EnvelopeGenerator.Application.Histories.Commands;
|
||||
using EnvelopeGenerator.Application.Histories.Queries;
|
||||
using EnvelopeGenerator.Domain.Constants;
|
||||
using EnvelopeGenerator.Domain.Entities;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace EnvelopeGenerator.Tests.Application;
|
||||
|
||||
[TestFixture]
|
||||
public class HistoryTests : TestBase
|
||||
{
|
||||
protected override void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
}
|
||||
|
||||
[SetUp]
|
||||
public override Task Setup()
|
||||
{
|
||||
|
||||
@ -8,7 +8,7 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace EnvelopeGenerator.Tests.Application;
|
||||
|
||||
public class TestBase : Faker
|
||||
public abstract class TestBase : Faker
|
||||
{
|
||||
protected Fake.Host Host;
|
||||
|
||||
@ -24,10 +24,12 @@ public class TestBase : Faker
|
||||
|
||||
protected IRepository Repository => Host.Services.GetRequiredService<IRepository>();
|
||||
|
||||
protected abstract void ConfigureServices(IServiceCollection services);
|
||||
|
||||
[SetUp]
|
||||
public virtual async Task Setup()
|
||||
{
|
||||
Host = Fake.CreateHost();
|
||||
Host = Fake.CreateHost(ConfigureServices);
|
||||
await Host.AddSamples();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user