Path: redb/redb.Tests.Integration/Tests/Unit/ProFriendAccessTests.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/Unit/ProFriendAccessTests.cs
----
using System.Reflection;
using System.Runtime.CompilerServices;
namespace redb.Tests.Integration.Tests.Unit;
///
/// redb.Postgres and redb.MSSql give their Pro provider access to the batch methods of their connections, which are
/// internal. The grant names the public key of the Pro assemblies (RedbProPublicKey of the root Directory.Build.props).
/// Built without that property, the grant came out as "PublicKey=" and granted nothing: the build stayed green and a
/// list query of Pro threw MethodAccessException at run time. Each grant must carry the key the Pro provider is signed
/// with.
///
public class ProFriendAccessTests
{
[Theory]
[InlineData(typeof(redb.Postgres.RedbService), typeof(redb.Postgres.Pro.Query.PvtSqlGenerator))]
[InlineData(typeof(redb.MSSql.RedbService), typeof(redb.MSSql.Pro.Query.PvtSqlGenerator))]
public void FreeProvider_GrantsItsProProvider_ByTheProPublicKey(Type freeType, Type proType)
{
var pro = proType.Assembly.GetName();
var proKey = Convert.ToHexString(pro.GetPublicKey() ?? []);
proKey.Should().NotBeEmpty($"{pro.Name} is strong-named");
var grants = freeType.Assembly.GetCustomAttributes()
.Select(a => a.AssemblyName)
.Where(n => n.StartsWith(pro.Name + ",", StringComparison.Ordinal) || n == pro.Name)
.ToList();
grants.Should().ContainSingle($"{freeType.Assembly.GetName().Name} grants {pro.Name} friend access");
var key = grants[0].Split("PublicKey=", 2) is [_, var k] ? k.Trim() : "";
key.Should().NotBeEmpty("a grant without a key reaches no signed assembly");
key.Should().BeEquivalentTo(proKey, "the grant names the key the Pro provider is signed with");
}
}