< Summary

Information
Class: Elsa.Persistence.EFCore.Extensions.SqliteProvidersExtensions
Assembly: Elsa.Persistence.EFCore.Sqlite
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Sqlite/SqliteProvidersExtensions.cs
Line coverage
88%
Covered lines: 8
Uncovered lines: 1
Coverable lines: 9
Total lines: 76
Line coverage: 88.8%
Branch coverage
100%
Covered branches: 2
Total branches: 2
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
get_Assembly()100%11100%
AddSqliteEntityModelCreatingHandlers(...)100%11100%
UseSqlite(...)100%11100%
UseSqlite(...)100%210%
UseSqlite(...)100%22100%
UseSqlite(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Persistence.EFCore.Sqlite/SqliteProvidersExtensions.cs

#LineLine coverage
 1using System.Reflection;
 2using Elsa.Persistence.EFCore.Sqlite;
 3using Elsa.Extensions;
 4using Microsoft.EntityFrameworkCore.Infrastructure;
 5using Microsoft.Extensions.DependencyInjection;
 6
 7// ReSharper disable once CheckNamespace
 8namespace Elsa.Persistence.EFCore.Extensions;
 9
 10/// <summary>
 11/// Provides extensions to configure EF Core to use Sqlite.
 12/// </summary>
 13public static class SqliteProvidersExtensions
 14{
 615    private static Assembly Assembly => typeof(SqliteProvidersExtensions).Assembly;
 16
 17    public static IServiceCollection AddSqliteEntityModelCreatingHandlers(this IServiceCollection services) =>
 618        services.TryAddScopedImplementation<IEntityModelCreatingHandler, SetupForSqlite>();
 19
 20    /// <summary>
 21    /// Configures the feature to use Sqlite.
 22    /// </summary>
 23    public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
 24        string? connectionString = null,
 25        ElsaDbContextOptions? options = null,
 26        Action<SqliteDbContextOptionsBuilder>? configure = null)
 27        where TDbContext : ElsaDbContextBase
 28        where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
 29    {
 630        return feature.UseSqlite(Assembly, connectionString, options, configure);
 31    }
 32
 33    /// <summary>
 34    /// Configures the feature to use Sqlite.
 35    /// </summary>
 36    public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
 37        Func<IServiceProvider, string> connectionStringFunc,
 38        ElsaDbContextOptions? options = null,
 39        Action<SqliteDbContextOptionsBuilder>? configure = null)
 40        where TDbContext : ElsaDbContextBase
 41        where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
 42    {
 043        return feature.UseSqlite(Assembly, connectionStringFunc, options, configure);
 44    }
 45
 46    /// <summary>
 47    /// Configures the feature to use Sqlite.
 48    /// </summary>
 49    public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
 50        Assembly migrationsAssembly,
 51        string? connectionString = null,
 52        ElsaDbContextOptions? options = null,
 53        Action<SqliteDbContextOptionsBuilder>? configure = null)
 54        where TDbContext : ElsaDbContextBase
 55        where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
 56    {
 657        connectionString ??= "Data Source=elsa.sqlite.db;Cache=Shared;";
 658        return feature.UseSqlite(migrationsAssembly, _ => connectionString, options, configure);
 59    }
 60
 61    /// <summary>
 62    /// Configures the feature to use Sqlite.
 63    /// </summary>
 64    public static TFeature UseSqlite<TFeature, TDbContext>(this PersistenceFeatureBase<TFeature, TDbContext> feature,
 65        Assembly migrationsAssembly,
 66        Func<IServiceProvider, string> connectionStringFunc,
 67        ElsaDbContextOptions? options = null,
 68        Action<SqliteDbContextOptionsBuilder>? configure = null)
 69        where TDbContext : ElsaDbContextBase
 70        where TFeature : PersistenceFeatureBase<TFeature, TDbContext>
 71    {
 672        feature.Module.Services.AddSqliteEntityModelCreatingHandlers();
 673        feature.DbContextOptionsBuilder = (sp, db) => db.UseElsaSqlite(migrationsAssembly, connectionStringFunc(sp), opt
 674        return (TFeature)feature;
 75    }
 76}