mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-28 00:20:24 +08:00
test: Update test-container to v3.0.0 for support event-store
This commit is contained in:
parent
e25c5f5dff
commit
db0da365b0
@ -101,7 +101,11 @@
|
|||||||
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="6.2.2" />
|
<PackageReference Include="Duende.IdentityServer.EntityFramework" Version="6.2.2" />
|
||||||
<PackageReference Include="Duende.IdentityServer.EntityFramework.Storage" Version="6.2.2" />
|
<PackageReference Include="Duende.IdentityServer.EntityFramework.Storage" Version="6.2.2" />
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
|
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
|
||||||
<PackageReference Include="Testcontainers" Version="2.3.0" />
|
<PackageReference Include="Testcontainers" Version="3.0.0" />
|
||||||
|
<PackageReference Include="Testcontainers.EventStoreDb" Version="3.0.0" />
|
||||||
|
<PackageReference Include="Testcontainers.MongoDb" Version="3.0.0" />
|
||||||
|
<PackageReference Include="Testcontainers.PostgreSql" Version="3.0.0" />
|
||||||
|
<PackageReference Include="Testcontainers.RabbitMq" Version="3.0.0" />
|
||||||
<PackageReference Include="Unchase.Swashbuckle.AspNetCore.Extensions" Version="2.7.1" />
|
<PackageReference Include="Unchase.Swashbuckle.AspNetCore.Extensions" Version="2.7.1" />
|
||||||
<PackageReference Include="WebMotions.Fake.Authentication.JwtBearer" Version="7.0.0" />
|
<PackageReference Include="WebMotions.Fake.Authentication.JwtBearer" Version="7.0.0" />
|
||||||
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.1" />
|
<PackageReference Include="Yarp.ReverseProxy" Version="1.1.1" />
|
||||||
|
|||||||
@ -15,7 +15,7 @@ public static class Extensions
|
|||||||
public static IServiceCollection AddCustomCap<TDbContext>(this IServiceCollection services)
|
public static IServiceCollection AddCustomCap<TDbContext>(this IServiceCollection services)
|
||||||
where TDbContext : DbContext
|
where TDbContext : DbContext
|
||||||
{
|
{
|
||||||
var rabbitMqOptions = services.GetOptions<RabbitMQOptions>("RabbitMq");
|
var rabbitMqOptions = services.GetOptions<RabbitMQOptions>(nameof(RabbitMQOptions));
|
||||||
|
|
||||||
services.AddCap(x =>
|
services.AddCap(x =>
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,6 +5,11 @@ using Microsoft.Extensions.DependencyInjection;
|
|||||||
|
|
||||||
namespace BuildingBlocks.PersistMessageProcessor;
|
namespace BuildingBlocks.PersistMessageProcessor;
|
||||||
|
|
||||||
|
using EFCore;
|
||||||
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddPersistMessageProcessor(this IServiceCollection services)
|
public static IServiceCollection AddPersistMessageProcessor(this IServiceCollection services)
|
||||||
@ -33,4 +38,39 @@ public static class Extensions
|
|||||||
|
|
||||||
return services;
|
return services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static IApplicationBuilder UseMigration<TContext>(this IApplicationBuilder app, IWebHostEnvironment env)
|
||||||
|
where TContext : DbContext, IPersistMessageDbContext
|
||||||
|
{
|
||||||
|
MigrateDatabaseAsync<TContext>(app.ApplicationServices).GetAwaiter().GetResult();
|
||||||
|
|
||||||
|
if (!env.IsEnvironment("test"))
|
||||||
|
{
|
||||||
|
SeedDataAsync(app.ApplicationServices).GetAwaiter().GetResult();
|
||||||
|
}
|
||||||
|
|
||||||
|
return app;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task MigrateDatabaseAsync<TContext>(IServiceProvider serviceProvider)
|
||||||
|
where TContext : DbContext, IPersistMessageDbContext
|
||||||
|
{
|
||||||
|
using var scope = serviceProvider.CreateScope();
|
||||||
|
|
||||||
|
var persistMessageContext = scope.ServiceProvider.GetRequiredService<PersistMessageDbContext>();
|
||||||
|
await persistMessageContext.Database.MigrateAsync();
|
||||||
|
|
||||||
|
var context = scope.ServiceProvider.GetRequiredService<TContext>();
|
||||||
|
await context.Database.MigrateAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static async Task SeedDataAsync(IServiceProvider serviceProvider)
|
||||||
|
{
|
||||||
|
using var scope = serviceProvider.CreateScope();
|
||||||
|
var seeders = scope.ServiceProvider.GetServices<IDataSeeder>();
|
||||||
|
foreach (var seeder in seeders)
|
||||||
|
{
|
||||||
|
await seeder.SeedAllAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,8 +30,12 @@ using WebMotions.Fake.Authentication.JwtBearer;
|
|||||||
|
|
||||||
namespace BuildingBlocks.TestBase;
|
namespace BuildingBlocks.TestBase;
|
||||||
|
|
||||||
|
using System.Globalization;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
using Exception = System.Exception;
|
using Testcontainers.EventStoreDb;
|
||||||
|
using Testcontainers.MongoDb;
|
||||||
|
using Testcontainers.PostgreSql;
|
||||||
|
using Testcontainers.RabbitMq;
|
||||||
|
|
||||||
public class TestFixture<TEntryPoint> : IAsyncLifetime
|
public class TestFixture<TEntryPoint> : IAsyncLifetime
|
||||||
where TEntryPoint : class
|
where TEntryPoint : class
|
||||||
@ -40,10 +44,11 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
|||||||
private int Timeout => 120; // Second
|
private int Timeout => 120; // Second
|
||||||
private ITestHarness TestHarness => ServiceProvider?.GetTestHarness();
|
private ITestHarness TestHarness => ServiceProvider?.GetTestHarness();
|
||||||
private Action<IServiceCollection> TestRegistrationServices { get; set; }
|
private Action<IServiceCollection> TestRegistrationServices { get; set; }
|
||||||
private PostgreSqlTestcontainer PostgresTestcontainer;
|
private PostgreSqlContainer PostgresTestcontainer;
|
||||||
private PostgreSqlTestcontainer PostgresPersistTestContainer;
|
private PostgreSqlContainer PostgresPersistTestContainer;
|
||||||
public RabbitMqTestcontainer RabbitMqTestContainer;
|
public RabbitMqContainer RabbitMqTestContainer;
|
||||||
public MongoDbTestcontainer MongoDbTestContainer;
|
public MongoDbContainer MongoDbTestContainer;
|
||||||
|
public EventStoreDbContainer EventStoreDbTestContainer;
|
||||||
|
|
||||||
public HttpClient HttpClient
|
public HttpClient HttpClient
|
||||||
{
|
{
|
||||||
@ -151,7 +156,6 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
|||||||
return ExecuteScopeAsync(sp =>
|
return ExecuteScopeAsync(sp =>
|
||||||
{
|
{
|
||||||
var mediator = sp.GetRequiredService<IMediator>();
|
var mediator = sp.GetRequiredService<IMediator>();
|
||||||
|
|
||||||
return mediator.Send(request);
|
return mediator.Send(request);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -238,15 +242,17 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
|||||||
|
|
||||||
private async Task StartTestContainerAsync()
|
private async Task StartTestContainerAsync()
|
||||||
{
|
{
|
||||||
PostgresTestcontainer = TestContainers.PostgresTestContainer;
|
PostgresTestcontainer = TestContainers.PostgresTestContainer();
|
||||||
PostgresPersistTestContainer = TestContainers.PostgresPersistTestContainer;
|
PostgresPersistTestContainer = TestContainers.PostgresPersistTestContainer();
|
||||||
RabbitMqTestContainer = TestContainers.RabbitMqTestContainer;
|
RabbitMqTestContainer = TestContainers.RabbitMqTestContainer();
|
||||||
MongoDbTestContainer = TestContainers.MongoTestContainer;
|
MongoDbTestContainer = TestContainers.MongoTestContainer();
|
||||||
|
EventStoreDbTestContainer = TestContainers.EventStoreTestContainer();
|
||||||
|
|
||||||
await MongoDbTestContainer.StartAsync();
|
await MongoDbTestContainer.StartAsync();
|
||||||
await PostgresTestcontainer.StartAsync();
|
await PostgresTestcontainer.StartAsync();
|
||||||
await PostgresPersistTestContainer.StartAsync();
|
await PostgresPersistTestContainer.StartAsync();
|
||||||
await RabbitMqTestContainer.StartAsync();
|
await RabbitMqTestContainer.StartAsync();
|
||||||
|
await EventStoreDbTestContainer.StartAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task StopTestContainerAsync()
|
private async Task StopTestContainerAsync()
|
||||||
@ -255,20 +261,24 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
|
|||||||
await PostgresPersistTestContainer.StopAsync();
|
await PostgresPersistTestContainer.StopAsync();
|
||||||
await RabbitMqTestContainer.StopAsync();
|
await RabbitMqTestContainer.StopAsync();
|
||||||
await MongoDbTestContainer.StopAsync();
|
await MongoDbTestContainer.StopAsync();
|
||||||
|
await EventStoreDbTestContainer.StopAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCustomAppSettings(IConfigurationBuilder configuration)
|
private void AddCustomAppSettings(IConfigurationBuilder configuration)
|
||||||
{
|
{
|
||||||
configuration.AddInMemoryCollection(new KeyValuePair<string, string>[]
|
configuration.AddInMemoryCollection(new KeyValuePair<string, string>[]
|
||||||
{
|
{
|
||||||
new("PostgresOptions:ConnectionString", PostgresTestcontainer.ConnectionString),
|
new("PostgresOptions:ConnectionString", PostgresTestcontainer.GetConnectionString()),
|
||||||
new("PersistMessageOptions:ConnectionString", PostgresPersistTestContainer.ConnectionString),
|
new("PersistMessageOptions:ConnectionString", PostgresPersistTestContainer.GetConnectionString()),
|
||||||
new("RabbitMqOptions:HostName", RabbitMqTestContainer.Hostname),
|
new("RabbitMqOptions:HostName", RabbitMqTestContainer.Hostname),
|
||||||
new("RabbitMqOptions:UserName", RabbitMqTestContainer.Username),
|
new("RabbitMqOptions:UserName", TestContainers.RabbitMqContainerConfiguration.UserName),
|
||||||
new("RabbitMqOptions:Password", RabbitMqTestContainer.Password),
|
new("RabbitMqOptions:Password", TestContainers.RabbitMqContainerConfiguration.Password), new(
|
||||||
new("RabbitMqOptions:Port", RabbitMqTestContainer.Port.ToString()),
|
"RabbitMqOptions:Port",
|
||||||
new("MongoOptions:ConnectionString", MongoDbTestContainer.ConnectionString),
|
RabbitMqTestContainer.GetMappedPublicPort(TestContainers.RabbitMqContainerConfiguration.Port)
|
||||||
new("MongoOptions:DatabaseName", MongoDbTestContainer.Database)
|
.ToString(NumberFormatInfo.InvariantInfo)),
|
||||||
|
new("MongoOptions:ConnectionString", MongoDbTestContainer.GetConnectionString()),
|
||||||
|
new("MongoOptions:DatabaseName", TestContainers.MongoContainerConfiguration.Name),
|
||||||
|
new("EventStore:ConnectionString", EventStoreDbTestContainer.GetConnectionString())
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,6 +460,7 @@ public class TestFixtureCore<TEntryPoint> : IAsyncLifetime
|
|||||||
private NpgsqlConnection DefaultDbConnection { get; set; }
|
private NpgsqlConnection DefaultDbConnection { get; set; }
|
||||||
private NpgsqlConnection PersistDbConnection { get; set; }
|
private NpgsqlConnection PersistDbConnection { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public TestFixtureCore(TestFixture<TEntryPoint> integrationTestFixture, ITestOutputHelper outputHelper)
|
public TestFixtureCore(TestFixture<TEntryPoint> integrationTestFixture, ITestOutputHelper outputHelper)
|
||||||
{
|
{
|
||||||
Fixture = integrationTestFixture;
|
Fixture = integrationTestFixture;
|
||||||
@ -474,8 +485,8 @@ public class TestFixtureCore<TEntryPoint> : IAsyncLifetime
|
|||||||
|
|
||||||
private async Task InitPostgresAsync()
|
private async Task InitPostgresAsync()
|
||||||
{
|
{
|
||||||
var postgresOptions = Fixture.ServiceProvider.GetRequiredService<PostgresOptions>();
|
var postgresOptions = Fixture.ServiceProvider.GetService<PostgresOptions>();
|
||||||
var persistOptions = Fixture.ServiceProvider.GetRequiredService<PersistMessageOptions>();
|
var persistOptions = Fixture.ServiceProvider.GetService<PersistMessageOptions>();
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(persistOptions?.ConnectionString))
|
if (!string.IsNullOrEmpty(persistOptions?.ConnectionString))
|
||||||
{
|
{
|
||||||
@ -514,24 +525,26 @@ public class TestFixtureCore<TEntryPoint> : IAsyncLifetime
|
|||||||
private async Task ResetMongoAsync(CancellationToken cancellationToken = default)
|
private async Task ResetMongoAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
//https://stackoverflow.com/questions/3366397/delete-everything-in-a-mongodb-database
|
//https://stackoverflow.com/questions/3366397/delete-everything-in-a-mongodb-database
|
||||||
var dbClient = new MongoClient(Fixture.MongoDbTestContainer?.ConnectionString);
|
var dbClient = new MongoClient(Fixture.MongoDbTestContainer?.GetConnectionString());
|
||||||
var collections = await dbClient.GetDatabase(Fixture.MongoDbTestContainer?.Database)
|
var collections = await dbClient.GetDatabase(TestContainers.MongoContainerConfiguration.Name)
|
||||||
.ListCollectionsAsync(cancellationToken: cancellationToken);
|
.ListCollectionsAsync(cancellationToken: cancellationToken);
|
||||||
|
|
||||||
foreach (var collection in collections.ToList())
|
foreach (var collection in collections.ToList())
|
||||||
{
|
{
|
||||||
await dbClient.GetDatabase(Fixture.MongoDbTestContainer?.Database)
|
await dbClient.GetDatabase(TestContainers.MongoContainerConfiguration.Name)
|
||||||
.DropCollectionAsync(collection["name"].AsString, cancellationToken);
|
.DropCollectionAsync(collection["name"].AsString, cancellationToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ResetRabbitMqAsync(CancellationToken cancellationToken = default)
|
private async Task ResetRabbitMqAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
var port = Fixture.RabbitMqTestContainer?.GetMappedPublicPort(15672) ?? 15672;
|
var port = Fixture.RabbitMqTestContainer?.GetMappedPublicPort(TestContainers.RabbitMqContainerConfiguration
|
||||||
|
.ApiPort)
|
||||||
|
?? TestContainers.RabbitMqContainerConfiguration.ApiPort;
|
||||||
|
|
||||||
var managementClient = new ManagementClient(Fixture.RabbitMqTestContainer?.Hostname,
|
var managementClient = new ManagementClient(Fixture.RabbitMqTestContainer?.Hostname,
|
||||||
Fixture.RabbitMqTestContainer?.Username,
|
TestContainers.RabbitMqContainerConfiguration?.UserName,
|
||||||
Fixture.RabbitMqTestContainer?.Password, port);
|
TestContainers.RabbitMqContainerConfiguration?.Password, port);
|
||||||
|
|
||||||
var bd = await managementClient.GetBindingsAsync(cancellationToken);
|
var bd = await managementClient.GetBindingsAsync(cancellationToken);
|
||||||
var bindings = bd.Where(x => !string.IsNullOrEmpty(x.Source) && !string.IsNullOrEmpty(x.Destination));
|
var bindings = bd.Where(x => !string.IsNullOrEmpty(x.Source) && !string.IsNullOrEmpty(x.Destination));
|
||||||
|
|||||||
@ -1,62 +1,149 @@
|
|||||||
using System;
|
namespace BuildingBlocks.TestBase;
|
||||||
using DotNet.Testcontainers.Builders;
|
using Testcontainers.EventStoreDb;
|
||||||
using DotNet.Testcontainers.Configurations;
|
using Testcontainers.MongoDb;
|
||||||
using DotNet.Testcontainers.Containers;
|
using Testcontainers.PostgreSql;
|
||||||
|
using Testcontainers.RabbitMq;
|
||||||
namespace BuildingBlocks.TestBase;
|
using Web;
|
||||||
|
|
||||||
public static class TestContainers
|
public static class TestContainers
|
||||||
{
|
{
|
||||||
public static PostgreSqlTestcontainer PostgresTestContainer => new TestcontainersBuilder<PostgreSqlTestcontainer>()
|
public static RabbitMqContainerOptions RabbitMqContainerConfiguration { get;}
|
||||||
.WithDatabase(
|
public static PostgresContainerOptions PostgresContainerConfiguration { get;}
|
||||||
new PostgreSqlTestcontainerConfiguration
|
public static PostgresPersistContainerOptions PostgresPersistContainerConfiguration { get;}
|
||||||
|
public static MongoContainerOptions MongoContainerConfiguration { get;}
|
||||||
|
public static EventStoreContainerOptions EventStoreContainerConfiguration { get;}
|
||||||
|
|
||||||
|
static TestContainers()
|
||||||
{
|
{
|
||||||
Database = Guid.NewGuid().ToString("D"),
|
var configuration = ConfigurationHelper.GetConfiguration();
|
||||||
Password = Guid.NewGuid().ToString("D"),
|
|
||||||
Username = Guid.NewGuid().ToString("D")
|
RabbitMqContainerConfiguration = configuration.GetOptions<RabbitMqContainerOptions>(nameof(RabbitMqContainerOptions));
|
||||||
})
|
PostgresContainerConfiguration = configuration.GetOptions<PostgresContainerOptions>(nameof(PostgresContainerOptions));
|
||||||
.WithImage("postgres:latest")
|
PostgresPersistContainerConfiguration = configuration.GetOptions<PostgresPersistContainerOptions>(nameof(PostgresPersistContainerOptions));
|
||||||
.WithPortBinding(5432, true)
|
MongoContainerConfiguration = configuration.GetOptions<MongoContainerOptions>(nameof(MongoContainerOptions));
|
||||||
.WithCleanUp(true)
|
EventStoreContainerConfiguration = configuration.GetOptions<EventStoreContainerOptions>(nameof(EventStoreContainerOptions));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PostgreSqlContainer PostgresTestContainer()
|
||||||
|
{
|
||||||
|
var baseBuilder = new PostgreSqlBuilder()
|
||||||
|
.WithUsername(PostgresContainerConfiguration.UserName)
|
||||||
|
.WithPassword(PostgresContainerConfiguration.Password)
|
||||||
|
.WithLabel("Key", "Value");
|
||||||
|
|
||||||
|
var builder = baseBuilder
|
||||||
|
.WithImage(PostgresContainerConfiguration.ImageName)
|
||||||
|
.WithName(PostgresContainerConfiguration.Name)
|
||||||
|
.WithPortBinding(PostgresContainerConfiguration.Port, true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
public static PostgreSqlTestcontainer PostgresPersistTestContainer => new TestcontainersBuilder<PostgreSqlTestcontainer>()
|
return builder;
|
||||||
.WithDatabase(
|
}
|
||||||
new PostgreSqlTestcontainerConfiguration
|
|
||||||
|
public static PostgreSqlContainer PostgresPersistTestContainer()
|
||||||
{
|
{
|
||||||
Database = Guid.NewGuid().ToString("D"),
|
var baseBuilder = new PostgreSqlBuilder()
|
||||||
Password = Guid.NewGuid().ToString("D"),
|
.WithUsername(PostgresPersistContainerConfiguration.UserName)
|
||||||
Username = Guid.NewGuid().ToString("D")
|
.WithPassword(PostgresPersistContainerConfiguration.Password)
|
||||||
})
|
.WithLabel("Key", "Value");
|
||||||
.WithImage("postgres:latest")
|
|
||||||
.WithPortBinding(5432, true)
|
var builder = baseBuilder
|
||||||
.WithCleanUp(true)
|
.WithImage(PostgresPersistContainerConfiguration.ImageName)
|
||||||
|
.WithName(PostgresPersistContainerConfiguration.Name)
|
||||||
|
.WithPortBinding(PostgresPersistContainerConfiguration.Port, true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
public static MongoDbTestcontainer MongoTestContainer => new TestcontainersBuilder<MongoDbTestcontainer>()
|
public static MongoDbContainer MongoTestContainer()
|
||||||
.WithDatabase(new MongoDbTestcontainerConfiguration()
|
|
||||||
{
|
{
|
||||||
Database = Guid.NewGuid().ToString("D"),
|
var baseBuilder = new MongoDbBuilder()
|
||||||
Username = Guid.NewGuid().ToString("D"),
|
.WithUsername(MongoContainerConfiguration.UserName)
|
||||||
Password = Guid.NewGuid().ToString("D"),
|
.WithPassword(MongoContainerConfiguration.Password)
|
||||||
})
|
.WithLabel("Key", "Value");
|
||||||
.WithImage("mongo:5")
|
|
||||||
.WithCleanUp(true)
|
var builder = baseBuilder
|
||||||
|
.WithImage(MongoContainerConfiguration.ImageName)
|
||||||
|
.WithName(MongoContainerConfiguration.Name)
|
||||||
|
.WithPortBinding(MongoContainerConfiguration.Port, true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
public static RabbitMqTestcontainer RabbitMqTestContainer => new TestcontainersBuilder<RabbitMqTestcontainer>()
|
public static RabbitMqContainer RabbitMqTestContainer()
|
||||||
.WithMessageBroker(new RabbitMqTestcontainerConfiguration()
|
|
||||||
{
|
{
|
||||||
Password = "guest",
|
var baseBuilder = new RabbitMqBuilder()
|
||||||
Username = "guest"
|
.WithUsername(RabbitMqContainerConfiguration.UserName)
|
||||||
})
|
.WithPassword(RabbitMqContainerConfiguration.Password)
|
||||||
.WithImage("rabbitmq:3-management")
|
.WithLabel("Key", "Value");
|
||||||
.WithPortBinding(15672, true)
|
|
||||||
.WithPortBinding(5672, true)
|
var builder = baseBuilder
|
||||||
.WithCleanUp(true)
|
.WithImage(RabbitMqContainerConfiguration.ImageName)
|
||||||
|
.WithName(RabbitMqContainerConfiguration.Name)
|
||||||
|
.WithPortBinding(RabbitMqContainerConfiguration.ApiPort, true)
|
||||||
|
.WithPortBinding(RabbitMqContainerConfiguration.Port, true)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static EventStoreDbContainer EventStoreTestContainer()
|
||||||
|
{
|
||||||
|
var baseBuilder = new EventStoreDbBuilder()
|
||||||
|
.WithLabel("Key", "Value");
|
||||||
|
|
||||||
|
var builder = baseBuilder
|
||||||
|
.WithImage(EventStoreContainerConfiguration.ImageName)
|
||||||
|
.WithName(EventStoreContainerConfiguration.Name)
|
||||||
|
.WithPortBinding(EventStoreContainerConfiguration.Port, true)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class RabbitMqContainerOptions
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "rabbitmq_" + Guid.NewGuid();
|
||||||
|
public int Port { get; set; } = 5672;
|
||||||
|
public int ApiPort { get; set; } = 15672;
|
||||||
|
public string ImageName { get; set; } = "rabbitmq:3-management";
|
||||||
|
public string UserName { get; set; } = "guest";
|
||||||
|
public string Password { get; set; } = "guest";
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class PostgresContainerOptions
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "postgreSql_" + Guid.NewGuid().ToString("D");
|
||||||
|
public int Port { get; set; } = 5432;
|
||||||
|
public string ImageName { get; set; } = "postgres:latest";
|
||||||
|
public string UserName { get; set; } = Guid.NewGuid().ToString("D");
|
||||||
|
public string Password { get; set; } = Guid.NewGuid().ToString("D");
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class PostgresPersistContainerOptions
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "postgreSql_" + Guid.NewGuid().ToString("D");
|
||||||
|
public int Port { get; set; } = 5432;
|
||||||
|
public string ImageName { get; set; } = "postgres:latest";
|
||||||
|
public string UserName { get; set; } = Guid.NewGuid().ToString("D");
|
||||||
|
public string Password { get; set; } = Guid.NewGuid().ToString("D");
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class MongoContainerOptions
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "mongo_" + Guid.NewGuid().ToString("D");
|
||||||
|
public int Port { get; set; } = 27017;
|
||||||
|
public string ImageName { get; set; } = "mongo:5";
|
||||||
|
public string UserName { get; set; } = Guid.NewGuid().ToString("D");
|
||||||
|
public string Password { get; set; } = Guid.NewGuid().ToString("D");
|
||||||
|
}
|
||||||
|
|
||||||
|
public sealed class EventStoreContainerOptions
|
||||||
|
{
|
||||||
|
public string Name { get; set; } = "event_store_" + Guid.NewGuid().ToString("D");
|
||||||
|
public int Port { get; set; } = 2113;
|
||||||
|
public string ImageName { get; set; } = "eventstore/eventstore:21.2.0-buster-slim";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
using System.Threading.RateLimiting;
|
using System.Threading.RateLimiting;
|
||||||
using Booking.Data;
|
using Booking.Data;
|
||||||
using BuildingBlocks.Core;
|
using BuildingBlocks.Core;
|
||||||
using BuildingBlocks.EFCore;
|
|
||||||
using BuildingBlocks.EventStoreDB;
|
using BuildingBlocks.EventStoreDB;
|
||||||
using BuildingBlocks.HealthCheck;
|
using BuildingBlocks.HealthCheck;
|
||||||
using BuildingBlocks.IdsGenerator;
|
using BuildingBlocks.IdsGenerator;
|
||||||
@ -27,6 +26,8 @@ using Serilog;
|
|||||||
|
|
||||||
namespace Booking.Extensions.Infrastructure;
|
namespace Booking.Extensions.Infrastructure;
|
||||||
|
|
||||||
|
using BuildingBlocks.PersistMessageProcessor.Data;
|
||||||
|
|
||||||
public static class InfrastructureExtensions
|
public static class InfrastructureExtensions
|
||||||
{
|
{
|
||||||
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
public static WebApplicationBuilder AddInfrastructure(this WebApplicationBuilder builder)
|
||||||
@ -99,6 +100,7 @@ public static class InfrastructureExtensions
|
|||||||
});
|
});
|
||||||
app.UseCorrelationId();
|
app.UseCorrelationId();
|
||||||
app.UseHttpMetrics();
|
app.UseHttpMetrics();
|
||||||
|
app.UseMigration<PersistMessageDbContext>(env);
|
||||||
app.UseCustomHealthCheck();
|
app.UseCustomHealthCheck();
|
||||||
app.MapMetrics();
|
app.MapMetrics();
|
||||||
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
|
||||||
|
|||||||
@ -1,11 +1,8 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Booking.Api;
|
using Booking.Api;
|
||||||
using Booking.Data;
|
using Booking.Data;
|
||||||
using BuildingBlocks.Contracts.EventBus.Messages;
|
using BuildingBlocks.Contracts.EventBus.Messages;
|
||||||
using BuildingBlocks.EFCore;
|
|
||||||
using BuildingBlocks.PersistMessageProcessor.Data;
|
|
||||||
using BuildingBlocks.TestBase;
|
using BuildingBlocks.TestBase;
|
||||||
using Flight;
|
using Flight;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
@ -21,72 +18,69 @@ using GetByIdRequest = Flight.GetByIdRequest;
|
|||||||
|
|
||||||
namespace Integration.Test.Booking.Features
|
namespace Integration.Test.Booking.Features
|
||||||
{
|
{
|
||||||
// todo: uncomment after event-store test-container is published.
|
public class CreateBookingTests : BookingIntegrationTestBase
|
||||||
// public class CreateBookingTests : BookingIntegrationTestBase
|
{
|
||||||
// {
|
public CreateBookingTests(TestReadFixture<Program, BookingReadDbContext> integrationTestFixture) : base(
|
||||||
// public CreateBookingTests(TestReadFixture<Program, BookingReadDbContext> integrationTestFixture) : base(
|
integrationTestFixture)
|
||||||
// integrationTestFixture)
|
{
|
||||||
// {
|
}
|
||||||
// }
|
|
||||||
//
|
protected override void RegisterTestsServices(IServiceCollection services)
|
||||||
// protected override void RegisterTestsServices(IServiceCollection services)
|
{
|
||||||
// {
|
MockFlightGrpcServices(services);
|
||||||
// MockFlightGrpcServices(services);
|
MockPassengerGrpcServices(services);
|
||||||
// MockPassengerGrpcServices(services);
|
}
|
||||||
// }
|
|
||||||
//
|
[Fact]
|
||||||
// // todo: add support test for event-store
|
public async Task should_create_booking_to_event_store_currectly()
|
||||||
// [Fact]
|
{
|
||||||
// public async Task should_create_booking_to_event_store_currectly()
|
// Arrange
|
||||||
// {
|
var command = new FakeCreateBookingCommand().Generate();
|
||||||
// // Arrange
|
|
||||||
// var command = new FakeCreateBookingCommand().Generate();
|
// Act
|
||||||
//
|
var response = await Fixture.SendAsync(command);
|
||||||
// // Act
|
|
||||||
//
|
// Assert
|
||||||
// var response = await Fixture.SendAsync(command);
|
response.Should().BeGreaterOrEqualTo(0);
|
||||||
//
|
|
||||||
// // Assert
|
(await Fixture.WaitForPublishing<BookingCreated>()).Should().Be(true);
|
||||||
// response.Should().BeGreaterOrEqualTo(0);
|
}
|
||||||
//
|
|
||||||
// (await Fixture.WaitForPublishing<BookingCreated>()).Should().Be(true);
|
|
||||||
// }
|
private void MockPassengerGrpcServices(IServiceCollection services)
|
||||||
//
|
{
|
||||||
//
|
services.Replace(ServiceDescriptor.Singleton(x =>
|
||||||
// private void MockPassengerGrpcServices(IServiceCollection services)
|
{
|
||||||
// {
|
var mockPassenger = Substitute.For<PassengerGrpcService.PassengerGrpcServiceClient>();
|
||||||
// services.Replace(ServiceDescriptor.Singleton(x =>
|
|
||||||
// {
|
mockPassenger.GetByIdAsync(Arg.Any<Passenger.GetByIdRequest>())
|
||||||
// var mockPassenger = Substitute.For<PassengerGrpcService.PassengerGrpcServiceClient>();
|
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(new FakePassengerResponse().Generate()),
|
||||||
//
|
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||||
// mockPassenger.GetByIdAsync(Arg.Any<Passenger.GetByIdRequest>())
|
|
||||||
// .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(new FakePassengerResponse().Generate()),
|
return mockPassenger;
|
||||||
// Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
}));
|
||||||
//
|
}
|
||||||
// return mockPassenger;
|
|
||||||
// }));
|
private void MockFlightGrpcServices(IServiceCollection services)
|
||||||
// }
|
{
|
||||||
//
|
services.Replace(ServiceDescriptor.Singleton(x =>
|
||||||
// private void MockFlightGrpcServices(IServiceCollection services)
|
{
|
||||||
// {
|
var mockFlight = Substitute.For<FlightGrpcService.FlightGrpcServiceClient>();
|
||||||
// services.Replace(ServiceDescriptor.Singleton(x =>
|
|
||||||
// {
|
mockFlight.GetByIdAsync(Arg.Any<GetByIdRequest>())
|
||||||
// var mockFlight = Substitute.For<FlightGrpcService.FlightGrpcServiceClient>();
|
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(new FakeFlightResponse().Generate()),
|
||||||
//
|
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||||
// mockFlight.GetByIdAsync(Arg.Any<GetByIdRequest>())
|
|
||||||
// .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(new FakeFlightResponse().Generate()),
|
mockFlight.GetAvailableSeatsAsync(Arg.Any<GetAvailableSeatsRequest>())
|
||||||
// Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeSeatsResponse.Generate()),
|
||||||
//
|
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||||
// mockFlight.GetAvailableSeatsAsync(Arg.Any<GetAvailableSeatsRequest>())
|
|
||||||
// .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeSeatsResponse.Generate()),
|
mockFlight.ReserveSeatAsync(Arg.Any<ReserveSeatRequest>())
|
||||||
// Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
.Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeSeatsResponse.Generate()?.Items?.First()),
|
||||||
//
|
Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
||||||
// mockFlight.ReserveSeatAsync(Arg.Any<ReserveSeatRequest>())
|
|
||||||
// .Returns(TestCalls.AsyncUnaryCall(Task.FromResult(FakeSeatsResponse.Generate()?.Items?.First()),
|
return mockFlight;
|
||||||
// Task.FromResult(new Metadata()), () => Status.DefaultSuccess, () => new Metadata(), () => { }));
|
}));
|
||||||
//
|
}
|
||||||
// return mockFlight;
|
}
|
||||||
// }));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user