using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; using Umbraco.Cms.Tests.Common.Testing; using Umbraco.Cms.Tests.Integration.Testing; namespace Umbraco.Cms.Tests.Integration.Umbraco.Persistence.EFCore.DbContext; [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console)] internal sealed class CustomDbContextUmbracoProviderTests : UmbracoIntegrationTest { [Test] public void Can_Register_Custom_DbContext_And_Resolve() { var dbContext = Services.GetRequiredService(); Assert.IsNotNull(dbContext); Assert.IsNotEmpty(dbContext.Database.GetConnectionString()); } protected override void CustomTestSetup(IUmbracoBuilder builder) { builder.Services.AddUmbracoDbContext((serviceProvider, options, connectionString, providerName) => { options.UseUmbracoDatabaseProvider(serviceProvider); }); } internal class CustomDbContext : Microsoft.EntityFrameworkCore.DbContext { public CustomDbContext(DbContextOptions options) : base(options) { } } } [TestFixture] [UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console)] public class CustomDbContextCustomSqliteProviderTests : UmbracoIntegrationTest { [Test] public void Can_Register_Custom_DbContext_And_Resolve() { var dbContext = Services.GetRequiredService(); Assert.IsNotNull(dbContext); Assert.IsNotEmpty(dbContext.Database.GetConnectionString()); } protected override void CustomTestSetup(IUmbracoBuilder builder) { builder.Services.AddUmbracoDbContext((serviceProvider, options, connectionString, providerName) => { options.UseSqlite("Data Source=:memory:;Version=3;New=True;"); }); } internal class CustomDbContext : Microsoft.EntityFrameworkCore.DbContext { public CustomDbContext(DbContextOptions options) : base(options) { } } }