Path: redb/redb.Tests.Integration/Tests/SqlitePro/SqliteProNativeExtensionTests.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/SqliteProNativeExtensionTests.cs
----
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using redb.Core;
using redb.Core.Models.Entities;
using redb.Core.Pro.Extensions;
using redb.SQLite.Data;
using redb.SQLite.Pro.Extensions;
using redb.Tests.Integration.Models;
namespace redb.Tests.Integration.Tests.SqlitePro;
///
/// The JSON of an object (LoadJsonAsync, and the load of a linked object whose scheme has no class in the
/// process) is read by the function get_object_json of the native extension, on Pro too. The open registration
/// finds the extension shipped with the package; the Pro registration did not, so a consumer who sets no path got
/// "no such function: get_object_json". Every other test sets the path itself; this one starts without it.
///
public class SqliteProNativeExtensionTests
{
private const string Cs = "Data Source=redb_tests_native_extension_pro.db";
[Fact]
public async Task ProRegistrationWithoutAPath_LoadsTheExtension_AndReadsObjectJson()
{
// Test collections run one after another (xunit.runner.json), so the process-wide path can be taken away here
// and put back after.
var previous = SqliteDataSource.NativeExtensionPath;
SqliteDataSource.NativeExtensionPath = null;
try
{
Fixtures.SqliteTestSupport.DeleteDbFiles(Cs);
var services = new ServiceCollection();
services.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning));
services.AddRedbPro(options => options.UseSqlite(Cs));
await using var provider = services.BuildServiceProvider();
var redb = provider.GetRequiredService();
await redb.InitializeAsync(ensureCreated: true);
await redb.SyncSchemeAsync();
var id = await redb.SaveAsync(new RedbObject { name = "json", Props = new SimpleProps { Title = "t" } });
var json = await redb.LoadJsonAsync(id);
json.Should().NotBeNullOrEmpty().And.Contain("\"t\"");
}
finally
{
SqliteDataSource.NativeExtensionPath = previous;
}
}
}