-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ES.FX): add Microsoft.EntityFrameworkCore.SqlServer project and …
…update dependencies - Added new ES.FX.Microsoft.EntityFrameworkCore.SqlServer project to the solution. - Updated OpenTelemetry.Instrumentation.AspNetCore, Http, and Runtime packages from version 1.8.1 to 1.9.0 in ES.FX.Ignite.Hosting. - Replaced hardcoded "live" string with constant in IgniteHostingExtensions.cs and added HealthChecksTags class in ES.FX.Ignite.Spark. - Created TestContainerDesignTimeFactory class for DbContext design time factory using MsSql Testcontainers in ES.FX.Microsoft.EntityFrameworkCore.SqlServer. - Refactored SimpleDbContextDesignTimeFactory and TestDbContextDesignTimeFactory classes to inherit from TestContainerDesignTimeFactory. - Updated Testcontainers.MsSql package from version 3.8.0 to 3.9.0 in ES.FX.Shared.SqlServer.Tests. BREAKING CHANGE: This commit introduces significant changes that may affect existing functionality, including the addition of a new project and updates to several dependencies across multiple projects.
- Loading branch information
1 parent
8f38d33
commit 33b05d7
Showing
13 changed files
with
107 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 7 additions & 23 deletions
30
...ound.Shared.Data.Simple.EntityFrameworkCore.SqlServer/SimpleDbContextDesignTimeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,15 @@ | ||
using JetBrains.Annotations; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using ES.FX.Microsoft.EntityFrameworkCore.SqlServer.DesignTime; | ||
using JetBrains.Annotations; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
|
||
namespace Playground.Shared.Data.Simple.EntityFrameworkCore.SqlServer; | ||
|
||
[PublicAPI] | ||
public class SimpleDbContextDesignTimeFactory : IDesignTimeDbContextFactory<SimpleDbContext> | ||
public class SimpleDbContextDesignTimeFactory : TestContainerDesignTimeFactory<SimpleDbContext> | ||
{ | ||
public SimpleDbContext CreateDbContext(string[] args) | ||
protected override void ConfigureSqlServerOptions(SqlServerDbContextOptionsBuilder builder) | ||
{ | ||
var optionsBuilder = new DbContextOptionsBuilder<SimpleDbContext>(); | ||
var sqlBuilder = new SqlConnectionStringBuilder | ||
{ | ||
DataSource = "(local)", | ||
UserID = "sa", | ||
Password = "SuperPass#", | ||
InitialCatalog = $"{nameof(SimpleDbContext)}_Design", | ||
TrustServerCertificate = true | ||
}; | ||
optionsBuilder.UseSqlServer(sqlBuilder.ConnectionString, | ||
sqlServerDbContextOptionsBuilder => | ||
{ | ||
sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(SimpleDbContextDesignTimeFactory).Assembly | ||
.FullName); | ||
}); | ||
|
||
return new SimpleDbContext(optionsBuilder.Options); | ||
base.ConfigureSqlServerOptions(builder); | ||
builder.MigrationsAssembly(GetType().Assembly.FullName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace ES.FX.Ignite.Spark.HealthChecks; | ||
|
||
public static class HealthChecksTags | ||
{ | ||
/// <summary> | ||
/// Tag used for liveness health checks | ||
/// </summary> | ||
public const string Live = "live"; | ||
} |
51 changes: 51 additions & 0 deletions
51
...S.FX.Microsoft.EntityFrameworkCore.SqlServer/DesignTime/TestContainerDesignTimeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.EntityFrameworkCore.Internal; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Testcontainers.MsSql; | ||
|
||
namespace ES.FX.Microsoft.EntityFrameworkCore.SqlServer.DesignTime; | ||
|
||
/// <summary> | ||
/// DbContext design time factory using MsSql Testcontainers | ||
/// </summary> | ||
/// <typeparam name="TDbContext"> The <see cref="TDbContext" /> to create</typeparam> | ||
public class TestContainerDesignTimeFactory<TDbContext> : IDesignTimeDbContextFactory<TDbContext> | ||
where TDbContext : DbContext | ||
{ | ||
private MsSqlContainer? _container; | ||
|
||
public TDbContext CreateDbContext(string[] args) | ||
{ | ||
var builder = new MsSqlBuilder().WithName($"{GetType().Name}"); | ||
ConfigureMsSqlContainerBuilder(builder); | ||
_container = builder.Build(); | ||
|
||
_container.StartAsync().Wait(); | ||
var optionsBuilder = new DbContextOptionsBuilder<TDbContext>(); | ||
optionsBuilder.UseSqlServer(_container.GetConnectionString(), ConfigureSqlServerOptions); | ||
|
||
|
||
#pragma warning disable EF1001 | ||
var context = new DbContextFactorySource<TDbContext>().Factory(new ServiceCollection().BuildServiceProvider(), | ||
optionsBuilder.Options); | ||
#pragma warning restore EF1001 | ||
|
||
return context; | ||
} | ||
|
||
/// <summary> | ||
/// Configures the SqlServerDbContextOptionsBuilder before the DbContext is created | ||
/// </summary> | ||
protected virtual void ConfigureSqlServerOptions(SqlServerDbContextOptionsBuilder builder) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Configures the MsSqlBuilder before the container is created | ||
/// </summary> | ||
protected virtual void ConfigureMsSqlContainerBuilder(MsSqlBuilder builder) | ||
{ | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...rosoft.EntityFrameworkCore.SqlServer/ES.FX.Microsoft.EntityFrameworkCore.SqlServer.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" /> | ||
<PackageReference Include="Testcontainers.MsSql" Version="3.9.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\ES.FX.Microsoft.EntityFrameworkCore\ES.FX.Microsoft.EntityFrameworkCore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
28 changes: 6 additions & 22 deletions
28
...e.Microsoft.EntityFrameworkCore.SqlServer.Tests/Context/TestDbContextDesignTimeFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,16 @@ | ||
using ES.FX.Ignite.Microsoft.EntityFrameworkCore.Tests.Context; | ||
using ES.FX.Microsoft.EntityFrameworkCore.SqlServer.DesignTime; | ||
using JetBrains.Annotations; | ||
using Microsoft.Data.SqlClient; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Design; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
|
||
namespace ES.FX.Ignite.Microsoft.EntityFrameworkCore.SqlServer.Tests.Context; | ||
|
||
[PublicAPI] | ||
public class TestDbContextDesignTimeFactory : IDesignTimeDbContextFactory<TestDbContext> | ||
public class TestDbContextDesignTimeFactory : TestContainerDesignTimeFactory<TestDbContext> | ||
{ | ||
public TestDbContext CreateDbContext(string[] args) | ||
protected override void ConfigureSqlServerOptions(SqlServerDbContextOptionsBuilder builder) | ||
{ | ||
var optionsBuilder = new DbContextOptionsBuilder<TestDbContext>(); | ||
var sqlBuilder = new SqlConnectionStringBuilder | ||
{ | ||
DataSource = "(local)", | ||
UserID = "sa", | ||
Password = "SuperPass#", | ||
InitialCatalog = $"{nameof(TestDbContext)}_Design", | ||
TrustServerCertificate = true | ||
}; | ||
optionsBuilder.UseSqlServer(sqlBuilder.ConnectionString, | ||
sqlServerDbContextOptionsBuilder => | ||
{ | ||
sqlServerDbContextOptionsBuilder.MigrationsAssembly(typeof(TestDbContextDesignTimeFactory).Assembly | ||
.FullName); | ||
}); | ||
|
||
return new TestDbContext(optionsBuilder.Options); | ||
base.ConfigureSqlServerOptions(builder); | ||
builder.MigrationsAssembly(GetType().Assembly.FullName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 0 additions & 9 deletions
9
tests/ES.FX.Ignite.Microsoft.EntityFrameworkCore.Tests/UnitTest1.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters