Path: redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProModuleUnloadTests.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProModuleUnloadTests.cs
----
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Loader;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using redb.Core;
using redb.Core.Interception;
using redb.Core.Models.Configuration;
using redb.Core.Models.Contracts;
using redb.Core.Models.Entities;
using redb.Core.Pro.Extensions;
using redb.SQLite.Data;
using redb.SQLite.Pro.Extensions;
using redb.Tests.Integration.Fixtures;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.SqlitePro;
///
/// A module of Tsak, end to end: its Props type and its save interceptor come from a collectible AssemblyLoadContext,
/// it syncs its scheme, saves, loads through the props cache, subscribes to the interceptor registry, deletes and
/// unsubscribes; then the context unloads while the host's redb service lives on. Nothing of redb may keep the
/// context alive.
///
[Collection("SqlitePro")]
public class SqliteProModuleUnloadTests
{
public SqliteProModuleUnloadTests(SqliteProFixture _) { }
// A database of its own, created by the test: the "Sqlite" connection string it used is the file of the Free
// collection, which had a schema only when that collection, or a previous run, made it.
private const string Cs = "Data Source=redb_tests_module_unload.db";
private static ServiceProvider BuildHost()
{
var cs = Cs;
SqliteDataSource.NativeExtensionPath ??= SqliteTestSupport.ResolveNativeExtension();
var services = new ServiceCollection();
services.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning));
services.AddRedbPro(options =>
{
options.UseSqlite(cs);
options.Configure(c =>
{
c.PropsSaveStrategy = PropsSaveStrategy.ChangeTracking;
c.EnablePropsCache = true;
c.CacheDomain = "module-unload";
});
});
return services.BuildServiceProvider();
}
private static MethodInfo ServiceMethod(string name, int genericArity, params Type[] parameters)
=> new[] { typeof(IRedbService) }.Concat(typeof(IRedbService).GetInterfaces())
.SelectMany(i => i.GetMethods())
.First(m => m.Name == name
&& (m.IsGenericMethodDefinition ? m.GetGenericArguments().Length : 0) == genericArity
&& m.GetParameters().Select(p => p.ParameterType.IsGenericParameter ? typeof(object) : p.ParameterType)
.SequenceEqual(parameters));
private static async Task