< Summary

Information
Class: OzonRepositories.Context.ApplicationDbContextFactory
Assembly: OzonRepositories
File(s): /home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Context/ApplicationDbContextFactory.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 9
Coverable lines: 9
Total lines: 32
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CreateDbContext(...)0%620%

File(s)

/home/runner/work/Studio2Prod/Studio2Prod/OzonRepositories/Context/ApplicationDbContextFactory.cs

#LineLine coverage
 1using Microsoft.EntityFrameworkCore;
 2using Microsoft.EntityFrameworkCore.Design;
 3using OzonRepositories.Utils;
 4using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
 5
 6namespace OzonRepositories.Context;
 7
 8/// <summary>
 9/// Design-time factory used by EF Core tooling (dotnet ef migrations add/update).
 10/// Connection string here is for local dev only; production uses the DI-configured context.
 11/// </summary>
 12public class ApplicationDbContextFactory : IDesignTimeDbContextFactory<ApplicationDbContext>
 13{
 14    public ApplicationDbContext CreateDbContext(string[] args)
 15    {
 016        var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();
 17
 18        // Connection string for EF tooling only (migrations). Never used at runtime.
 19        // Set via environment variable before running "dotnet ef migrations add/update":
 20        //   export EF_DESIGN_CONNECTION="Server=...;Database=...;User=...;Password=...;"
 021        var connectionString =
 022            Environment.GetEnvironmentVariable("EF_DESIGN_CONNECTION")
 023            ?? throw new InvalidOperationException(
 024                "EF_DESIGN_CONNECTION environment variable is not set. " +
 025                "Set it to a valid MySQL connection string before running EF tooling.");
 26
 027        var serverVersion = St2MariaDb.ServerVersion;
 028        optionsBuilder.UseMySql(connectionString, serverVersion);
 29
 030        return new ApplicationDbContext(optionsBuilder.Options);
 31    }
 32}