some change in inMemoryTestHarness masstransit

This commit is contained in:
meysamhadeli 2022-05-10 03:20:24 +04:30
parent 63d48215ea
commit 3a2f555561
37 changed files with 300 additions and 3291 deletions

View File

@ -7,7 +7,6 @@ using Microsoft.AspNetCore.Authentication;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
var appOptions = builder.Services.GetOptions<AppOptions>("AppOptions");
Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));

View File

@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Enrichers.Span;
using Serilog.Events;
@ -10,18 +12,20 @@ public static class Extensions
{
public static WebApplicationBuilder AddCustomSerilog(this WebApplicationBuilder builder)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.Console()
.WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}", LogEventLevel.Error)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Error)
.Enrich.WithSpan()
.Enrich.FromLogContext()
.ReadFrom.Configuration(ctx.Configuration));
Log.Logger = new LoggerConfiguration()
.WriteTo.Console()
.CreateBootstrapLogger();
return builder;
builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.Console()
.WriteTo.SpectreConsole("{Timestamp:HH:mm:ss} [{Level:u4}] {Message:lj}{NewLine}{Exception}",
LogEventLevel.Error)
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Error)
.Enrich.WithSpan()
.Enrich.FromLogContext()
.ReadFrom.Configuration(ctx.Configuration));
return builder;
}
}

View File

@ -3,7 +3,9 @@ using BuildingBlocks.Domain.Event;
using BuildingBlocks.Utils;
using Humanizer;
using MassTransit;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace BuildingBlocks.MassTransit;
@ -15,56 +17,59 @@ public static class Extensions
bool.TryParse(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), out var inContainer) &&
inContainer;
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services, Assembly assembly)
public static IServiceCollection AddCustomMassTransit(this IServiceCollection services, Assembly assembly, IWebHostEnvironment env)
{
services.AddMassTransit(configure =>
if (!env.IsEnvironment("test"))
{
configure.AddConsumers(assembly);
configure.UsingRabbitMq((context, configurator) =>
services.AddMassTransit(configure =>
{
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
var host = IsRunningInContainer ? "rabbitmq" : rabbitMqOptions.HostName;
configure.AddConsumers(assembly);
configurator.Host(host, h =>
configure.UsingRabbitMq((context, configurator) =>
{
h.Username(rabbitMqOptions.UserName);
h.Password(rabbitMqOptions.Password);
});
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>("RabbitMq");
var host = IsRunningInContainer ? "rabbitmq" : rabbitMqOptions.HostName;
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
.Where(x => x.IsAssignableTo(typeof(IIntegrationEvent))
&& !x.IsInterface
&& !x.IsAbstract
&& !x.IsGenericType);
configurator.Host(host, h =>
{
h.Username(rabbitMqOptions.UserName);
h.Password(rabbitMqOptions.Password);
});
foreach (var type in types)
{
var consumers = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
.Where(x => x.IsAssignableTo(typeof(IConsumer<>).MakeGenericType(type))).ToList();
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
.Where(x => x.IsAssignableTo(typeof(IIntegrationEvent))
&& !x.IsInterface
&& !x.IsAbstract
&& !x.IsGenericType);
if (consumers.Any())
configurator.ReceiveEndpoint(
string.IsNullOrEmpty(rabbitMqOptions.ExchangeName)
? type.Name.Underscore()
: $"{rabbitMqOptions.ExchangeName}_{type.Name.Underscore()}", e =>
{
foreach (var consumer in consumers)
foreach (var type in types)
{
var consumers = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes())
.Where(x => x.IsAssignableTo(typeof(IConsumer<>).MakeGenericType(type))).ToList();
if (consumers.Any())
configurator.ReceiveEndpoint(
string.IsNullOrEmpty(rabbitMqOptions.ExchangeName)
? type.Name.Underscore()
: $"{rabbitMqOptions.ExchangeName}_{type.Name.Underscore()}", e =>
{
configurator.ConfigureEndpoints(context, x => x.Exclude(consumer));
var methodInfo = typeof(DependencyInjectionReceiveEndpointExtensions)
.GetMethods()
.Where(x => x.GetParameters()
.Any(p => p.ParameterType == typeof(IServiceProvider)))
.FirstOrDefault(x => x.Name == "Consumer" && x.IsGenericMethod);
foreach (var consumer in consumers)
{
configurator.ConfigureEndpoints(context, x => x.Exclude(consumer));
var methodInfo = typeof(DependencyInjectionReceiveEndpointExtensions)
.GetMethods()
.Where(x => x.GetParameters()
.Any(p => p.ParameterType == typeof(IServiceProvider)))
.FirstOrDefault(x => x.Name == "Consumer" && x.IsGenericMethod);
var generic = methodInfo?.MakeGenericMethod(consumer);
generic?.Invoke(e, new object[] {e, context, null});
}
});
}
var generic = methodInfo?.MakeGenericMethod(consumer);
generic?.Invoke(e, new object[] {e, context, null});
}
});
}
});
});
});
}
return services;
}

View File

@ -23,6 +23,7 @@ using Serilog;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
var env = builder.Environment;
var appOptions = builder.Services.GetOptions<AppOptions>("AppOptions");
builder.Services.Configure<GrpcOptions>(options => configuration.GetSection("Grpc").Bind(options));
@ -46,7 +47,7 @@ builder.Services.AddHttpContextAccessor();
builder.Services.AddTransient<IEventMapper, EventMapper>();
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
builder.Services.AddCustomMassTransit(typeof(BookingRoot).Assembly);
builder.Services.AddCustomMassTransit(typeof(BookingRoot).Assembly, env);
builder.Services.AddCustomOpenTelemetry();
builder.Services.AddTransient<AuthHeaderHandler>();
SnowFlakIdGenerator.Configure(3);

View File

@ -7,7 +7,7 @@
}
},
"ConnectionStrings": {
"BookingConnection": "Server=db;Database=BookingDB;User ID=sa;Password=@Aa123456"
"DefaultConnection": "Server=db;Database=BookingDB;User ID=sa;Password=@Aa123456"
},
"RabbitMq": {
"HostName": "rabbitmq",

View File

@ -8,6 +8,7 @@ using BuildingBlocks.Jwt;
using BuildingBlocks.Logging;
using BuildingBlocks.Mapster;
using BuildingBlocks.MassTransit;
using BuildingBlocks.Mongo;
using BuildingBlocks.OpenTelemetry;
using BuildingBlocks.Swagger;
using BuildingBlocks.Utils;
@ -23,84 +24,77 @@ using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Prometheus;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
RegisterServices(builder);
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
var env = builder.Environment;
var appOptions = builder.Services.GetOptions<AppOptions>("AppOptions");
Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
builder.Services.AddCustomDbContext<FlightDbContext>(configuration, typeof(FlightRoot).Assembly);
builder.Services.AddMongoDbContext<FlightReadDbContext>(configuration);
builder.Services.AddScoped<IDataSeeder, FlightDataSeeder>();
builder.AddCustomSerilog();
builder.Services.AddJwt();
builder.Services.AddControllers();
builder.Services.AddCustomSwagger(builder.Configuration, typeof(FlightRoot).Assembly);
builder.Services.AddCustomVersioning();
builder.Services.AddCustomMediatR();
builder.Services.AddValidatorsFromAssembly(typeof(FlightRoot).Assembly);
builder.Services.AddCustomProblemDetails();
builder.Services.AddCustomMapster(typeof(FlightRoot).Assembly);
builder.Services.AddHttpContextAccessor();
builder.Services.AddTransient<IEventMapper, EventMapper>();
builder.Services.AddCustomMassTransit(typeof(FlightRoot).Assembly, env);
builder.Services.AddCustomOpenTelemetry();
builder.Services.AddRouting(options => options.LowercaseUrls = true);
builder.Services.AddGrpc(options =>
{
options.Interceptors.Add<GrpcExceptionInterceptor>();
});
builder.Services.AddMagicOnion();
SnowFlakIdGenerator.Configure(1);
builder.Services.AddCachingRequest(new List<Assembly>
{
typeof(FlightRoot).Assembly
});
builder.Services.AddEasyCaching(options => { options.UseInMemory(configuration, "mem"); });
var app = builder.Build();
ConfigureApplication(app);
if (app.Environment.IsDevelopment())
{
var provider = app.Services.GetService<IApiVersionDescriptionProvider>();
app.UseCustomSwagger(provider);
}
app.UseSerilogRequestLogging();
app.UseCorrelationId();
app.UseRouting();
app.UseHttpMetrics();
app.UseMigrations();
app.UseProblemDetails();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapMetrics();
endpoints.MapMagicOnionService();
});
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
app.Run();
static void RegisterServices(WebApplicationBuilder builder)
{
var configuration = builder.Configuration;
var services = builder.Services;
var appOptions = services.GetOptions<AppOptions>("AppOptions");
Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
builder.AddCustomSerilog();
services.AddCustomDbContext<FlightDbContext>(configuration, typeof(FlightRoot).Assembly);
services.AddScoped<IDataSeeder, FlightDataSeeder>();
services.AddJwt();
services.AddControllers();
services.AddCustomSwagger(builder.Configuration, typeof(FlightRoot).Assembly);
services.AddCustomVersioning();
services.AddCustomMediatR();
services.AddValidatorsFromAssembly(typeof(FlightRoot).Assembly);
services.AddCustomProblemDetails();
services.AddCustomMapster(typeof(FlightRoot).Assembly);
services.AddHttpContextAccessor();
services.AddTransient<IEventMapper, EventMapper>();
services.AddCustomMassTransit(typeof(FlightRoot).Assembly);
services.AddCustomOpenTelemetry();
services.AddRouting(options => options.LowercaseUrls = true);
services.AddGrpc(options =>
{
options.Interceptors.Add<GrpcExceptionInterceptor>();
});
services.AddMagicOnion();
SnowFlakIdGenerator.Configure(1);
services.AddCachingRequest(new List<Assembly> {typeof(FlightRoot).Assembly});
services.AddEasyCaching(options => { options.UseInMemory(configuration, "mem"); });
}
static void ConfigureApplication(WebApplication app)
{
var appOptions = app.GetOptions<AppOptions>("AppOptions");
if (app.Environment.IsDevelopment())
{
var provider = app.Services.GetService<IApiVersionDescriptionProvider>();
app.UseCustomSwagger(provider);
}
app.UseSerilogRequestLogging();
app.UseCorrelationId();
app.UseRouting();
app.UseHttpMetrics();
app.UseMigrations();
app.UseProblemDetails();
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapMetrics();
endpoints.MapMagicOnionService();
});
app.MapGet("/", x => x.Response.WriteAsync(appOptions.Name));
}
public partial class Program { }
public partial class Program {}

View File

@ -7,7 +7,7 @@
}
},
"ConnectionStrings": {
"FlightConnection": "Server=db;Database=FlightDB;User ID=sa;Password=@Aa123456"
"DefaultConnection": "Server=db;Database=FlightDB;User ID=sa;Password=@Aa123456"
},
"Jwt": {
"Authority": "https://localhost:5005",

View File

@ -1,6 +1,6 @@
{
"ConnectionStrings": {
"FlightConnection": "Server=db;Database=FlightDB;User ID=sa;Password=@Aa123456"
"DefaultConnection": "Server=.\\sqlexpress;Database=FlightDBTest;Trusted_Connection=True;MultipleActiveResultSets=true"
},
"RabbitMq": {
"HostName": "rabbitmq",

View File

@ -1,221 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220303140107_Init")]
partial class Init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CorrelationId")
.HasColumnType("nvarchar(max)");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircraft.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airport.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.HasOne("Flight.Aircraft.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airport.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.HasOne("Flight.Flight.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,233 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220303172333_ModifiedBy-to-entities")]
partial class ModifiedBytoentities
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CorrelationId")
.HasColumnType("nvarchar(max)");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircraft.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airport.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.HasOne("Flight.Aircraft.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airport.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.HasOne("Flight.Flight.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,63 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class ModifiedBytoentities : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "ModifiedBy",
schema: "dbo",
table: "Seat",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "ModifiedBy",
schema: "dbo",
table: "Flight",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "ModifiedBy",
schema: "dbo",
table: "Airport",
type: "int",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "ModifiedBy",
schema: "dbo",
table: "Aircraft",
type: "int",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Seat");
migrationBuilder.DropColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Flight");
migrationBuilder.DropColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Airport");
migrationBuilder.DropColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Aircraft");
}
}
}

View File

@ -1,233 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220303182534_Change-corrolationId-type-outbox")]
partial class ChangecorrolationIdtypeoutbox
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircraft.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airport.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.HasOne("Flight.Aircraft.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airport.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.HasOne("Flight.Flight.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,34 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class ChangecorrolationIdtypeoutbox : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<Guid>(
name: "CorrelationId",
table: "OutboxMessages",
type: "uniqueidentifier",
nullable: true,
oldClrType: typeof(string),
oldType: "nvarchar(max)",
oldNullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "CorrelationId",
table: "OutboxMessages",
type: "nvarchar(max)",
nullable: true,
oldClrType: typeof(Guid),
oldType: "uniqueidentifier",
oldNullable: true);
}
}
}

View File

@ -1,245 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220415203349_Add-Versening")]
partial class AddVersening
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircraft.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airport.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("ModifiedBy")
.HasColumnType("int");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flight.Models.Flight", b =>
{
b.HasOne("Flight.Aircraft.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airport.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Flight.Models.Seat", b =>
{
b.HasOne("Flight.Flight.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,67 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class AddVersening : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "Version",
schema: "dbo",
table: "Seat",
type: "bigint",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<long>(
name: "Version",
schema: "dbo",
table: "Flight",
type: "bigint",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<long>(
name: "Version",
schema: "dbo",
table: "Airport",
type: "bigint",
nullable: false,
defaultValue: 0L);
migrationBuilder.AddColumn<long>(
name: "Version",
schema: "dbo",
table: "Aircraft",
type: "bigint",
nullable: false,
defaultValue: 0L);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Version",
schema: "dbo",
table: "Seat");
migrationBuilder.DropColumn(
name: "Version",
schema: "dbo",
table: "Flight");
migrationBuilder.DropColumn(
name: "Version",
schema: "dbo",
table: "Airport");
migrationBuilder.DropColumn(
name: "Version",
schema: "dbo",
table: "Aircraft");
}
}
}

View File

@ -1,269 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220416172637_Add-Audit")]
partial class AddAudit
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<int?>("CreatedBy")
.HasColumnType("int");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("LastModifiedBy")
.HasColumnType("int");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airports.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<int?>("CreatedBy")
.HasColumnType("int");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("LastModifiedBy")
.HasColumnType("int");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<int?>("CreatedBy")
.HasColumnType("int");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("LastModifiedBy")
.HasColumnType("int");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<int?>("CreatedBy")
.HasColumnType("int");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<int?>("LastModifiedBy")
.HasColumnType("int");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.HasOne("Flight.Aircrafts.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airports.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.HasOne("Flight.Flights.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,240 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class AddAudit : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Seat",
newName: "LastModifiedBy");
migrationBuilder.RenameColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Flight",
newName: "LastModifiedBy");
migrationBuilder.RenameColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Airport",
newName: "LastModifiedBy");
migrationBuilder.RenameColumn(
name: "ModifiedBy",
schema: "dbo",
table: "Aircraft",
newName: "LastModifiedBy");
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Seat",
type: "datetime2",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime2");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
schema: "dbo",
table: "Seat",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Seat",
type: "int",
nullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Flight",
type: "datetime2",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime2");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
schema: "dbo",
table: "Flight",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Flight",
type: "int",
nullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Airport",
type: "datetime2",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime2");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
schema: "dbo",
table: "Airport",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Airport",
type: "int",
nullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Aircraft",
type: "datetime2",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime2");
migrationBuilder.AddColumn<DateTime>(
name: "CreatedAt",
schema: "dbo",
table: "Aircraft",
type: "datetime2",
nullable: true);
migrationBuilder.AddColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Aircraft",
type: "int",
nullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "CreatedAt",
schema: "dbo",
table: "Seat");
migrationBuilder.DropColumn(
name: "CreatedBy",
schema: "dbo",
table: "Seat");
migrationBuilder.DropColumn(
name: "CreatedAt",
schema: "dbo",
table: "Flight");
migrationBuilder.DropColumn(
name: "CreatedBy",
schema: "dbo",
table: "Flight");
migrationBuilder.DropColumn(
name: "CreatedAt",
schema: "dbo",
table: "Airport");
migrationBuilder.DropColumn(
name: "CreatedBy",
schema: "dbo",
table: "Airport");
migrationBuilder.DropColumn(
name: "CreatedAt",
schema: "dbo",
table: "Aircraft");
migrationBuilder.DropColumn(
name: "CreatedBy",
schema: "dbo",
table: "Aircraft");
migrationBuilder.RenameColumn(
name: "LastModifiedBy",
schema: "dbo",
table: "Seat",
newName: "ModifiedBy");
migrationBuilder.RenameColumn(
name: "LastModifiedBy",
schema: "dbo",
table: "Flight",
newName: "ModifiedBy");
migrationBuilder.RenameColumn(
name: "LastModifiedBy",
schema: "dbo",
table: "Airport",
newName: "ModifiedBy");
migrationBuilder.RenameColumn(
name: "LastModifiedBy",
schema: "dbo",
table: "Aircraft",
newName: "ModifiedBy");
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Seat",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime2",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Flight",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime2",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Airport",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime2",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "LastModified",
schema: "dbo",
table: "Aircraft",
type: "datetime2",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime2",
oldNullable: true);
}
}
}

View File

@ -1,175 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class UpdateAudit : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<long>(
name: "LastModifiedBy",
schema: "dbo",
table: "Seat",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "CreatedBy",
schema: "dbo",
table: "Seat",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "LastModifiedBy",
schema: "dbo",
table: "Flight",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "CreatedBy",
schema: "dbo",
table: "Flight",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "LastModifiedBy",
schema: "dbo",
table: "Airport",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "CreatedBy",
schema: "dbo",
table: "Airport",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "LastModifiedBy",
schema: "dbo",
table: "Aircraft",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
migrationBuilder.AlterColumn<long>(
name: "CreatedBy",
schema: "dbo",
table: "Aircraft",
type: "bigint",
nullable: true,
oldClrType: typeof(int),
oldType: "int",
oldNullable: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<int>(
name: "LastModifiedBy",
schema: "dbo",
table: "Seat",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Seat",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "LastModifiedBy",
schema: "dbo",
table: "Flight",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Flight",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "LastModifiedBy",
schema: "dbo",
table: "Airport",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Airport",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "LastModifiedBy",
schema: "dbo",
table: "Aircraft",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "CreatedBy",
schema: "dbo",
table: "Aircraft",
type: "int",
nullable: true,
oldClrType: typeof(long),
oldType: "bigint",
oldNullable: true);
}
}
}

View File

@ -1,301 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220421195137_Add-Internal-Messages")]
partial class AddInternalMessages
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.InternalProcessor.InternalMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CommandType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("InternalMessages", (string)null);
});
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airports.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.HasOne("Flight.Aircrafts.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airports.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.HasOne("Flight.Flights.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,36 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class AddInternalMessages : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "InternalMessages",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
OccurredOn = table.Column<DateTime>(type: "datetime2", nullable: false),
CommandType = table.Column<string>(type: "nvarchar(max)", nullable: false),
Data = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProcessedOn = table.Column<DateTime>(type: "datetime2", nullable: true),
CorrelationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_InternalMessages", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "InternalMessages");
}
}
}

View File

@ -1,301 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220422121403_Update-EventId")]
partial class UpdateEventId
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.InternalProcessor.InternalMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CommandType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.HasKey("Id");
b.ToTable("InternalMessages", (string)null);
});
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("EventId");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airports.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.HasOne("Flight.Aircrafts.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airports.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.HasOne("Flight.Flights.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class UpdateEventId : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Id",
table: "OutboxMessages",
newName: "EventId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "EventId",
table: "OutboxMessages",
newName: "Id");
}
}
}

View File

@ -1,301 +0,0 @@
// <auto-generated />
using System;
using Flight.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220422122146_Update-Internal")]
partial class UpdateInternal
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "6.0.1")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.InternalProcessor.InternalMessage", b =>
{
b.Property<Guid>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CommandType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.HasKey("EventId");
b.ToTable("InternalMessages", (string)null);
});
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("EventId");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airports.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("AircraftId");
b.HasIndex("ArriveAirportId");
b.ToTable("Flight", "dbo");
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("FlightId");
b.ToTable("Seat", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.HasOne("Flight.Aircrafts.Models.Aircraft", null)
.WithMany()
.HasForeignKey("AircraftId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("Flight.Airports.Models.Airport", null)
.WithMany()
.HasForeignKey("ArriveAirportId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
{
b.HasOne("Flight.Flights.Models.Flight", null)
.WithMany()
.HasForeignKey("FlightId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,25 +0,0 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
public partial class UpdateInternal : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "Id",
table: "InternalMessages",
newName: "EventId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.RenameColumn(
name: "EventId",
table: "InternalMessages",
newName: "Id");
}
}
}

View File

@ -12,8 +12,8 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace Flight.Data.Migrations
{
[DbContext(typeof(FlightDbContext))]
[Migration("20220418195957_Update-Audit")]
partial class UpdateAudit
[Migration("20220509213249_Init")]
partial class Init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -24,44 +24,6 @@ namespace Flight.Data.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
{
b.Property<long>("Id")

View File

@ -21,7 +21,11 @@ namespace Flight.Data.Migrations
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Model = table.Column<string>(type: "nvarchar(max)", nullable: true),
ManufacturingYear = table.Column<int>(type: "int", nullable: false),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
Version = table.Column<long>(type: "bigint", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
@ -38,7 +42,11 @@ namespace Flight.Data.Migrations
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Address = table.Column<string>(type: "nvarchar(max)", nullable: true),
Code = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
Version = table.Column<long>(type: "bigint", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
@ -46,24 +54,6 @@ namespace Flight.Data.Migrations
table.PrimaryKey("PK_Airport", x => x.Id);
});
migrationBuilder.CreateTable(
name: "OutboxMessages",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: false),
OccurredOn = table.Column<DateTime>(type: "datetime2", nullable: false),
Type = table.Column<string>(type: "nvarchar(max)", nullable: false),
Data = table.Column<string>(type: "nvarchar(max)", nullable: false),
ProcessedOn = table.Column<DateTime>(type: "datetime2", nullable: true),
EventType = table.Column<string>(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false),
CorrelationId = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_OutboxMessages", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Flight",
schema: "dbo",
@ -80,7 +70,11 @@ namespace Flight.Data.Migrations
FlightDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
Version = table.Column<long>(type: "bigint", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
@ -112,7 +106,11 @@ namespace Flight.Data.Migrations
Type = table.Column<int>(type: "int", nullable: false),
Class = table.Column<int>(type: "int", nullable: false),
FlightId = table.Column<long>(type: "bigint", nullable: false),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
Version = table.Column<long>(type: "bigint", nullable: false),
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
},
constraints: table =>
@ -148,9 +146,6 @@ namespace Flight.Data.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OutboxMessages");
migrationBuilder.DropTable(
name: "Seat",
schema: "dbo");

View File

@ -22,76 +22,6 @@ namespace Flight.Data.Migrations
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
modelBuilder.Entity("BuildingBlocks.InternalProcessor.InternalMessage", b =>
{
b.Property<Guid>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("CommandType")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.HasKey("EventId");
b.ToTable("InternalMessages", (string)null);
});
modelBuilder.Entity("BuildingBlocks.Outbox.OutboxMessage", b =>
{
b.Property<Guid>("EventId")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<Guid?>("CorrelationId")
.HasColumnType("uniqueidentifier");
b.Property<string>("Data")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EventType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTime>("OccurredOn")
.HasColumnType("datetime2");
b.Property<DateTime?>("ProcessedOn")
.HasColumnType("datetime2");
b.Property<string>("Type")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("EventId");
b.ToTable("OutboxMessages", (string)null);
});
modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b =>
{
b.Property<long>("Id")

View File

@ -12,16 +12,16 @@
</ItemGroup>
<ItemGroup>
<Folder Include="Aircrafts\Exceptions"/>
<Folder Include="Airports\Exceptions"/>
<Folder Include="Data\Migrations"/>
<Folder Include="Enum"/>
<Folder Include="Flights\Features\UpdateFlight"/>
<Folder Include="Seats\Features\CreateSeat"/>
<Folder Include="Aircrafts\Exceptions" />
<Folder Include="Airports\Exceptions" />
<Folder Include="Data\Migrations" />
<Folder Include="Enum" />
<Folder Include="Flights\Features\UpdateFlight" />
<Folder Include="Seats\Features\CreateSeat" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\BuildingBlocks\BuildingBlocks.csproj"/>
<ProjectReference Include="..\..\..\..\BuildingBlocks\BuildingBlocks.csproj" />
</ItemGroup>
</Project>

View File

@ -1,5 +1,4 @@
using System;
using System.Threading.Tasks;
using System.Threading.Tasks;
using Xunit;
namespace Integration.Test;
@ -12,9 +11,9 @@ public class DeleteTests
public DeleteTests(TestFixture fixture) => _fixture = fixture;
[Fact]
public async Task Should_delete_flight()
public Task Should_delete_flight()
{
var b = 2;
return Task.CompletedTask;
}
}

View File

@ -1,70 +0,0 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Ductus.FluentDocker.Builders;
using Ductus.FluentDocker.Services;
using Ductus.FluentDocker.Services.Extensions;
namespace Integration.Test.DockerTestUtilities;
public static class DockerDatabaseUtilities
{
private const string ACCEPT_EULA = "Y";
private const string SA_PASSWORD = "@Aa123456";
private const string DB_CONTAINER_NAME = "sqldb";
private static readonly ImageTag ImageTagForOs = new("mcr.microsoft.com/mssql/server", "2017-latest");
public static async Task<int> EnsureDockerStartedAndGetPortPortAsync()
{
await DockerUtilities.CleanupRunningContainers(DB_CONTAINER_NAME);
await DockerUtilities.CleanupRunningVolumes(DB_CONTAINER_NAME);
var hosts = new Hosts().Discover();
var docker = hosts.FirstOrDefault(x => x.IsNative) ?? hosts.FirstOrDefault(x => x.Name == "default");
// create container, if one doesn't already exist
var existingContainer = docker?.GetContainers().FirstOrDefault(c => c.Name == DB_CONTAINER_NAME);
if (existingContainer == null)
{
var container = new Builder().UseContainer()
.WithName(DB_CONTAINER_NAME)
.UseImage($"{ImageTagForOs.Image}:{ImageTagForOs.Tag}")
.ExposePort(1433, 1433)
.WithEnvironment(
$"SA_PASSWORD={SA_PASSWORD}",
$"ACCEPT_EULA={ACCEPT_EULA}")
.WaitForPort("1433/tcp", 30000 /*30s*/)
.Build();
container.Start();
await DockerUtilities.WaitUntilDatabaseAvailableAsync(GetSqlConnectionString());
}
return existingContainer.ToHostExposedEndpoint("1433/tcp").Port;
}
// SQL Server 2019 does not work on macOS + M1 chip. So we use SQL Edge as a workaround until SQL Server 2022 is GA.
// See https://github.com/pdevito3/craftsman/issues/53 for details.
private static ImageTag GetImageTagForOs()
{
var sqlServerImageTag = new ImageTag("mcr.microsoft.com/mssql/server", "2019-latest");
var sqlEdgeImageTag = new ImageTag("mcr.microsoft.com/azure-sql-edge", "latest");
return IsRunningOnMacOsArm64() ? sqlEdgeImageTag : sqlServerImageTag;
}
private static bool IsRunningOnMacOsArm64()
{
var isMacOs = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
var cpuArch = RuntimeInformation.ProcessArchitecture;
return isMacOs && cpuArch == Architecture.Arm64;
}
public static string GetSqlConnectionString()
{
return DockerUtilities.GetSqlConnectionString();
}
private record ImageTag(string Image, string Tag);
}

View File

@ -1,135 +0,0 @@
// based on https://blog.dangl.me/archive/running-sql-server-integration-tests-in-net-core-projects-via-docker/
using System;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Threading.Tasks;
using Docker.DotNet;
using Docker.DotNet.Models;
using Microsoft.Data.SqlClient;
namespace Integration.Test.DockerTestUtilities;
public static class DockerUtilities
{
private static bool IsRunningOnWindows()
{
return Environment.OSVersion.Platform == PlatformID.Win32NT;
}
public static DockerClient GetDockerClient()
{
var dockerUri = IsRunningOnWindows()
? "npipe://./pipe/docker_engine"
: "unix:///var/run/docker.sock";
return new DockerClientConfiguration(new Uri(dockerUri))
.CreateClient();
}
public static async Task CleanupRunningContainers(string containerName, int hoursTillExpiration = -24)
{
var dockerClient = GetDockerClient();
var runningContainers = await dockerClient.Containers
.ListContainersAsync(new ContainersListParameters());
foreach (var runningContainer in
runningContainers.Where(cont => cont.Names.Any(n => n.Contains(containerName))))
{
// Stopping all test containers that are older than 24 hours
var expiration = hoursTillExpiration > 0
? hoursTillExpiration * -1
: hoursTillExpiration;
if (runningContainer.Created < DateTime.UtcNow.AddHours(expiration))
try
{
await EnsureDockerContainersStoppedAndRemovedAsync(runningContainer.ID);
}
catch
{
// Ignoring failures to stop running containers
}
}
}
public static async Task CleanupRunningVolumes(string volumeName, int hoursTillExpiration = -24)
{
var dockerClient = GetDockerClient();
var runningVolumes = await dockerClient.Volumes.ListAsync();
foreach (var runningVolume in runningVolumes.Volumes.Where(v => v.Name == volumeName))
{
// Stopping all test volumes that are older than 24 hours
var expiration = hoursTillExpiration > 0
? hoursTillExpiration * -1
: hoursTillExpiration;
if (DateTime.Parse(runningVolume.CreatedAt) < DateTime.UtcNow.AddHours(expiration))
try
{
await EnsureDockerVolumesRemovedAsync(runningVolume.Name);
}
catch
{
// Ignoring failures to stop running containers
}
}
}
public static async Task EnsureDockerContainersStoppedAndRemovedAsync(string dockerContainerId)
{
var dockerClient = GetDockerClient();
await dockerClient.Containers
.StopContainerAsync(dockerContainerId, new ContainerStopParameters());
await dockerClient.Containers
.RemoveContainerAsync(dockerContainerId, new ContainerRemoveParameters());
}
public static async Task EnsureDockerVolumesRemovedAsync(string volumeName)
{
var dockerClient = GetDockerClient();
await dockerClient.Volumes.RemoveAsync(volumeName);
}
public static async Task WaitUntilDatabaseAvailableAsync(string connectionString)
{
var start = DateTime.UtcNow;
const int maxWaitTimeSeconds = 60;
var connectionEstablished = false;
while (!connectionEstablished && start.AddSeconds(maxWaitTimeSeconds) > DateTime.UtcNow)
try
{
using var sqlConnection = new SqlConnection(connectionString);
await sqlConnection.OpenAsync();
connectionEstablished = true;
}
catch
{
// If opening the SQL connection fails, SQL Server is not ready yet
await Task.Delay(500);
}
if (!connectionEstablished)
throw new Exception(
$"Connection to the SQL docker database could not be established within {maxWaitTimeSeconds} seconds.");
}
public static int GetFreePort()
{
// From https://stackoverflow.com/a/150974/4190785
var tcpListener = new TcpListener(IPAddress.Loopback, 0);
tcpListener.Start();
var port = ((IPEndPoint) tcpListener.LocalEndpoint).Port;
tcpListener.Stop();
return port;
}
public static string GetSqlConnectionString()
{
return new SqlConnectionStringBuilder()
{
ConnectionString = "Server=db;Database=FlightDB;User ID=sa;Password=@Aa123456"
}.ToString();
}
}

View File

@ -6,29 +6,29 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4"/>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0"/>
<PackageReference Include="xunit" Version="2.4.1"/>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Nito.AsyncEx" Version="5.1.2"/>
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
<PackageReference Include="AutoBogus" Version="2.13.1"/>
<PackageReference Include="Bogus" Version="34.0.1"/>
<PackageReference Include="Docker.DotNet" Version="3.125.5"/>
<PackageReference Include="Ductus.FluentDocker" Version="2.10.41"/>
<PackageReference Include="FluentAssertions" Version="6.2.0"/>
<PackageReference Include="MediatR" Version="9.0.0"/>
<PackageReference Include="Moq" Version="4.16.1"/>
<PackageReference Include="Respawn" Version="4.0.0"/>
<PackageReference Include="AutoBogus" Version="2.13.1" />
<PackageReference Include="Bogus" Version="34.0.1" />
<PackageReference Include="Docker.DotNet" Version="3.125.5" />
<PackageReference Include="Ductus.FluentDocker" Version="2.10.41" />
<PackageReference Include="FluentAssertions" Version="6.2.0" />
<PackageReference Include="MediatR" Version="9.0.0" />
<PackageReference Include="Moq" Version="4.16.1" />
<PackageReference Include="Respawn" Version="4.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\src\Flight.Api\Flight.Api.csproj"/>
<ProjectReference Include="..\src\Flight.Api\Flight.Api.csproj" />
</ItemGroup>
</Project>

View File

@ -1,14 +1,25 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BuildingBlocks.Domain.Model;
using Flight.Data;
using MassTransit;
using MassTransit.Testing;
using MediatR;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Moq;
using Respawn;
using Xunit;
using Xunit.Abstractions;
namespace Integration.Test;
@ -18,51 +29,72 @@ public class SliceFixtureCollection : ICollectionFixture<TestFixture>
}
// ref: https://github.com/jbogard/ContosoUniversityDotNetCore-Pages/blob/master/ContosoUniversity.IntegrationTests/SliceFixture.cs
// ref: https://github.com/MassTransit/MassTransit/blob/00d6992286911a437b63b93c89a56e920b053c11/src/MassTransit.TestFramework/InMemoryTestFixture.cs
// ref: https://wrapt.dev/blog/building-an-event-driven-dotnet-application-integration-testing
public class TestFixture : IAsyncLifetime
{
private readonly Checkpoint _checkpoint;
private readonly IConfiguration _configuration;
private readonly WebApplicationFactory<Program> _factory;
private readonly IServiceScopeFactory _scopeFactory;
private static InMemoryTestHarness _harness;
public ITestOutputHelper Output { get; set; }
public TestFixture()
{
var factory = FlightTestApplicationFactory();
_factory = FlightTestApplicationFactory();
_configuration = factory.Services.GetRequiredService<IConfiguration>();
_scopeFactory = factory.Services.GetRequiredService<IServiceScopeFactory>();
_configuration = _factory.Services.GetRequiredService<IConfiguration>();
_scopeFactory = _factory.Services.GetRequiredService<IServiceScopeFactory>();
_checkpoint = new Checkpoint();
}
public WebApplicationFactory<Program> FlightTestApplicationFactory()
{
Environment.SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", "test");
return new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureTestServices((services) =>
{
services.RemoveAll(typeof(IHostedService));
});
builder.ConfigureServices(services =>
{
builder.ConfigureLogging(logging =>
{
logging.ClearProviders(); // Remove other loggers
});
var httpContextAccessorService = services.FirstOrDefault(d =>
d.ServiceType == typeof(IHttpContextAccessor));
services.Remove(httpContextAccessorService);
services.AddSingleton(_ => Mock.Of<IHttpContextAccessor>());
services.AddScoped<InMemoryTestHarness>();
var provider = services.BuildServiceProvider();
var serviceScopeFactory = provider.GetService<IServiceScopeFactory>();
// MassTransit Start Setup -- Do Not Delete Comment
_harness = serviceScopeFactory?.CreateScope().ServiceProvider.GetRequiredService<InMemoryTestHarness>();
_harness?.Start().GetAwaiter().GetResult();
});
});
}
public Task InitializeAsync()
{
return _checkpoint.Reset(_configuration.GetConnectionString("DefaultConnection"));
}
public Task DisposeAsync()
public async Task DisposeAsync()
{
_factory?.Dispose();
return Task.CompletedTask;
}
public WebApplicationFactory<Program> FlightTestApplicationFactory()
{
return new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration((_, configBuilder) =>
{
configBuilder.AddInMemoryCollection(new Dictionary<string, string>
{
{
"ConnectionStrings:DefaultConnection",
"Server=db;Database=FlightDB;User ID=sa;Password=@Aa123456"
}
});
});
});
await _harness.Stop();
await _factory.DisposeAsync();
}
public async Task ExecuteScopeAsync(Func<IServiceProvider, Task> action)
@ -227,4 +259,65 @@ public class TestFixture : IAsyncLifetime
return mediator.Send(request);
});
}
// MassTransit Methods -- Do Not Delete Comment
/// <summary>
/// Publishes a message to the bus, and waits for the specified response.
/// </summary>
/// <param name="message">The message that should be published.</param>
/// <typeparam name="TMessage">The message that should be published.</typeparam>
public static async Task PublishMessage<TMessage>(object message)
where TMessage : class
{
await _harness.Bus.Publish<TMessage>(message);
}
/// <summary>
/// Confirm if there was a fault when publishing for this harness.
/// </summary>
/// <typeparam name="TMessage">The message that should be published.</typeparam>
/// <returns>A boolean of true if there was a fault for a message of the given type when published.</returns>
public Task<bool> IsFaultyPublished<TMessage>()
where TMessage : class
{
return _harness.Published.Any<Fault<TMessage>>();
}
/// <summary>
/// Confirm that a message has been published for this harness.
/// </summary>
/// <typeparam name="TMessage">The message that should be published.</typeparam>
/// <returns>A boolean of true if a message of the given type has been published.</returns>
public Task<bool> IsPublished<TMessage>()
where TMessage : class
{
return _harness.Published.Any<TMessage>();
}
/// <summary>
/// Confirm that a message has been consumed for this harness.
/// </summary>
/// <typeparam name="TMessage">The message that should be consumed.</typeparam>
/// <returns>A boolean of true if a message of the given type has been consumed.</returns>
public Task<bool> IsConsumed<TMessage>()
where TMessage : class
{
return _harness.Consumed.Any<TMessage>();
}
/// <summary>
/// The desired consumer consumed the message.
/// </summary>
/// <typeparam name="TMessage">The message that should be consumed.</typeparam>
/// <typeparam name="TConsumedBy">The consumer of the message.</typeparam>
/// <returns>A boolean of true if a message of the given type has been consumed by the given consumer.</returns>
public Task<bool> IsConsumed<TMessage, TConsumedBy>()
where TMessage : class
where TConsumedBy : class, IConsumer
{
using var scope = _scopeFactory.CreateScope();
var consumerHarness = scope.ServiceProvider.GetRequiredService<IConsumerTestHarness<TConsumedBy>>();
return consumerHarness.Consumed.Any<TMessage>();
}
}

View File

@ -45,7 +45,7 @@ builder.Services.AddScoped<IDataSeeder, IdentityDataSeeder>();
builder.Services.AddTransient<IEventMapper, EventMapper>();
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
builder.Services.AddCustomMassTransit(typeof(IdentityRoot).Assembly);
builder.Services.AddCustomMassTransit(typeof(IdentityRoot).Assembly, env);
builder.Services.AddCustomOpenTelemetry();
builder.Services.AddIdentityServer(env);

View File

@ -1,7 +1,7 @@
{
"App": "Identity-Service",
"ConnectionStrings": {
"IdentityConnection": "Server=db;Database=IdentityDB;User ID=sa;Password=@Aa123456"
"DefaultConnection": "Server=db;Database=IdentityDB;User ID=sa;Password=@Aa123456"
},
"RabbitMq": {
"HostName": "rabbitmq",

View File

@ -22,6 +22,7 @@ using Serilog;
var builder = WebApplication.CreateBuilder(args);
var configuration = builder.Configuration;
var env = builder.Environment;
var appOptions = builder.Services.GetOptions<AppOptions>("AppOptions");
Console.WriteLine(FiggleFonts.Standard.Render(appOptions.Name));
@ -41,7 +42,7 @@ builder.Services.AddHttpContextAccessor();
builder.Services.AddTransient<IEventMapper, EventMapper>();
builder.Services.AddTransient<IBusPublisher, BusPublisher>();
builder.Services.AddCustomMassTransit(typeof(PassengerRoot).Assembly);
builder.Services.AddCustomMassTransit(typeof(PassengerRoot).Assembly, env);
builder.Services.AddCustomOpenTelemetry();
builder.Services.AddGrpc(options =>
{

View File

@ -1,7 +1,7 @@
{
"App": "Passenger-Service",
"ConnectionStrings": {
"PassengerConnection": "Server=db;Database=PassengerDB;User ID=sa;Password=@Aa123456"
"DefaultConnection": "Server=db;Database=PassengerDB;User ID=sa;Password=@Aa123456"
},
"Jwt": {
"Authority": "https://localhost:5005",