Introduced a `DbConnection` constructor in `JobRunnerDbContext` for Entity Framework 6 to enable in-memory testing with the Effort library. Added conditional compilation to support both .NET Framework 4.8 and .NET 8. Implemented `AddInfrastructureInMemory` in `DependencyExtension` to register services with in-memory databases: - For .NET 4.8, uses Effort's transient connection. - For .NET 8, uses EF Core's in-memory provider. Registered AutoMapper in both methods for object mapping. Added `EntityMappingProfile` to define AutoMapper configurations, enforcing explicit DTO-to-entity mappings. These changes improve testability and maintainability across .NET versions.
62 lines
1.7 KiB
C#
62 lines
1.7 KiB
C#
#if NET48
|
|
using System.Data.Entity;
|
|
using System.Data.Common;
|
|
#else
|
|
using Microsoft.EntityFrameworkCore;
|
|
#endif
|
|
using ECMJobRunner.Domain.Entities;
|
|
|
|
namespace ECMJobRunner.Infrastructure.Data
|
|
{
|
|
/// <summary>
|
|
/// Entity Framework DbContext for ECM Job Runner
|
|
/// </summary>
|
|
public class JobRunnerDbContext : DbContext
|
|
{
|
|
/// <summary>
|
|
/// Profile entities
|
|
/// </summary>
|
|
public DbSet<CfgProfile> CfgProfiles { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// ProfileSqlJob entities
|
|
/// </summary>
|
|
public DbSet<ProfileSqlJob> ProfileSqlJobs { get; set; } = null!;
|
|
|
|
/// <summary>
|
|
/// ProfileHistory entities
|
|
/// </summary>
|
|
public DbSet<ProfileHistory> ProfileHistories { get; set; } = null!;
|
|
|
|
#if NET48
|
|
/// <summary>
|
|
/// Default constructor for Entity Framework 6 (.NET Framework 4.8)
|
|
/// </summary>
|
|
public JobRunnerDbContext() : base("name=JobRunnerConnection")
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor with connection string for Entity Framework 6
|
|
/// </summary>
|
|
public JobRunnerDbContext(string connectionString) : base(connectionString)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Constructor with DbConnection for Entity Framework 6 (used for InMemory testing with Effort)
|
|
/// </summary>
|
|
public JobRunnerDbContext(DbConnection connection) : base(connection, contextOwnsConnection: true)
|
|
{
|
|
}
|
|
#else
|
|
/// <summary>
|
|
/// Constructor for Entity Framework Core (.NET 8)
|
|
/// </summary>
|
|
public JobRunnerDbContext(DbContextOptions<JobRunnerDbContext> options) : base(options)
|
|
{
|
|
}
|
|
#endif
|
|
}
|
|
}
|